/**
   * cleanup any undismissed ota dialogs so the InCallScreen UI can be shown
   *
   * @return void
   */
  private void otaCleanup() {

    PhoneApp app = PhoneApp.getInstance();
    boolean isOtaCallActive = false;

    if (TelephonyCapabilities.supportsOtasp(app.phone)) {
      boolean activateState =
          (app.cdmaOtaScreenState.otaScreenState
              == OtaUtils.CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION);
      boolean dialogState =
          (app.cdmaOtaScreenState.otaScreenState
              == OtaUtils.CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG);

      if (activateState || dialogState) {
        // The OTASP sequence is active, but either (1) the call
        // hasn't started yet, or (2) the call has ended and we're
        // showing the success/failure screen. In either of these
        // cases it's OK to make a new outgoing call, but we need
        // to take down any OTASP-related UI first.
        if (dialogState) app.dismissOtaDialogs();
        app.clearOtaState();
        app.clearInCallScreenMode();
      }
    }
  }
  /**
   * Check if ota call is active
   *
   * @return True if ota call is still active False if ota call is not active
   */
  private boolean isOtaActive() {

    PhoneApp app = PhoneApp.getInstance();
    boolean isOtaCallActive = false;

    if (TelephonyCapabilities.supportsOtasp(app.phone)) {

      // TODO: Need cleaner way to check if OTA is active.
      // Also, this check seems to be broken in one obscure case: if
      // you interrupt an OTASP call by pressing Back then Skip,
      // otaScreenState somehow gets left in either PROGRESS or
      // LISTENING.
      if ((app.cdmaOtaScreenState.otaScreenState
              == OtaUtils.CdmaOtaScreenState.OtaScreenState.OTA_STATUS_PROGRESS)
          || (app.cdmaOtaScreenState.otaScreenState
              == OtaUtils.CdmaOtaScreenState.OtaScreenState.OTA_STATUS_LISTENING)) {
        isOtaCallActive = true;
        // The actual OTASP call is active. Don't allow new
        // outgoing calls at all from this state.
        Log.w(TAG, "OTASP call is active");
      }
    }
    return isOtaCallActive;
  }
    public void doReceive(Context context, Intent intent) {
      if (DBG) Log.v(TAG, "doReceive: " + intent);

      boolean alreadyCalled;
      String number;
      String originalUri;

      alreadyCalled = intent.getBooleanExtra(OutgoingCallBroadcaster.EXTRA_ALREADY_CALLED, false);
      if (alreadyCalled) {
        if (DBG) Log.v(TAG, "CALL already placed -- returning.");
        return;
      }

      // Once the NEW_OUTGOING_CALL broadcast is finished, the resultData
      // is used as the actual number to call. (If null, no call will be
      // placed.)

      number = getResultData();
      if (VDBG) Log.v(TAG, "- got number from resultData: '" + number + "'");

      final PhoneApp app = PhoneApp.getInstance();

      if (isOtaActive()) {
        // OTASP call is active. Don't allow new outgoing calls at all
        Log.w(TAG, "OTASP call is active: disallowing a new outgoing call.");
        return;
      }

      if (number == null) {
        if (DBG) Log.v(TAG, "CALL cancelled (null number), returning...");
        return;
      } else if (TelephonyCapabilities.supportsOtasp(app.phone)
          && (app.phone.getState() != Phone.State.IDLE)
          && (app.phone.isOtaSpNumber(number))) {
        if (DBG) Log.v(TAG, "Call is active, a 2nd OTA call cancelled -- returning.");
        return;
      } else if (PhoneNumberUtils.isPotentialLocalEmergencyNumber(number, context)) {
        // Just like 3rd-party apps aren't allowed to place emergency
        // calls via the ACTION_CALL intent, we also don't allow 3rd
        // party apps to use the NEW_OUTGOING_CALL broadcast to rewrite
        // an outgoing call into an emergency number.
        Log.w(TAG, "Cannot modify outgoing call to emergency number " + number + ".");
        return;
      }

      originalUri = intent.getStringExtra(OutgoingCallBroadcaster.EXTRA_ORIGINAL_URI);
      if (originalUri == null) {
        Log.e(TAG, "Intent is missing EXTRA_ORIGINAL_URI -- returning.");
        return;
      }

      Uri uri = Uri.parse(originalUri);

      // We already called convertKeypadLettersToDigits() and
      // stripSeparators() way back in onCreate(), before we sent out the
      // NEW_OUTGOING_CALL broadcast.  But we need to do it again here
      // too, since the number might have been modified/rewritten during
      // the broadcast (and may now contain letters or separators again.)
      number = PhoneNumberUtils.convertKeypadLettersToDigits(number);
      number = PhoneNumberUtils.stripSeparators(number);

      if (DBG) Log.v(TAG, "doReceive: proceeding with call...");
      if (VDBG) Log.v(TAG, "- uri: " + uri);
      if (VDBG) Log.v(TAG, "- actual number to dial: '" + number + "'");

      startSipCallOptionHandler(context, intent, uri, number);
    }