private void startUi(InCallState inCallState) {
    final Call incomingCall = mCallList.getIncomingCall();
    final boolean isCallWaiting =
        (incomingCall != null && incomingCall.getState() == Call.State.CALL_WAITING);

    // If the screen is off, we need to make sure it gets turned on for incoming calls.
    // This normally works just fine thanks to FLAG_TURN_SCREEN_ON but that only works
    // when the activity is first created. Therefore, to ensure the screen is turned on
    // for the call waiting case, we finish() the current activity and start a new one.
    // There should be no jank from this since the screen is already off and will remain so
    // until our new activity is up.
    if (mProximitySensor.isScreenReallyOff() && isCallWaiting) {
      if (isActivityStarted()) {
        mInCallActivity.finish();
      }
      mInCallActivity = null;
    }

    final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    // If the screen is on, we'll prefer to not interrupt the user too much and slide in a card
    if (pm.isScreenOn()) {
      Intent intent = new Intent(mContext, InCallCardActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      mContext.startActivity(intent);
    } else {
      mStatusBarNotifier.updateNotificationAndLaunchIncomingCallUi(inCallState, mCallList);
    }
  }
  /** Given the call list, return the state in which the in-call screen should be. */
  public static InCallState getPotentialStateFromCallList(CallList callList) {

    InCallState newState = InCallState.NO_CALLS;

    if (callList == null) {
      return newState;
    }
    if (callList.getIncomingCall() != null) {
      newState = InCallState.INCOMING;
    } else if (callList.getOutgoingCall() != null) {
      newState = InCallState.OUTGOING;
    } else if (callList.getActiveCall() != null
        || callList.getBackgroundCall() != null
        || callList.getDisconnectedCall() != null
        || callList.getDisconnectingCall() != null) {
      newState = InCallState.INCALL;
    }

    return newState;
  }
  /**
   * Handles the green CALL key while in-call.
   *
   * @return true if we consumed the event.
   */
  public boolean handleCallKey() {
    Log.v(this, "handleCallKey");

    // The green CALL button means either "Answer", "Unhold", or
    // "Swap calls", or can be a no-op, depending on the current state
    // of the Phone.

    /** INCOMING CALL */
    final CallList calls = CallList.getInstance();
    final Call incomingCall = calls.getIncomingCall();
    Log.v(this, "incomingCall: " + incomingCall);

    // (1) Attempt to answer a call
    if (incomingCall != null) {
      CallCommandClient.getInstance().answerCall(incomingCall.getCallId());
      if (mAccelerometerListener != null) {
        mAccelerometerListener.enableSensor(false);
      }
      return true;
    }

    /** ACTIVE CALL */
    final Call activeCall = calls.getActiveCall();
    if (activeCall != null) {
      // TODO: This logic is repeated from CallButtonPresenter.java. We should
      // consolidate this logic.
      final boolean isGeneric = activeCall.can(Capabilities.GENERIC_CONFERENCE);
      final boolean canMerge = activeCall.can(Capabilities.MERGE_CALLS);
      final boolean canSwap = activeCall.can(Capabilities.SWAP_CALLS);

      Log.v(
          this,
          "activeCall: "
              + activeCall
              + ", isGeneric: "
              + isGeneric
              + ", canMerge: "
              + canMerge
              + ", canSwap: "
              + canSwap);

      // (2) Attempt actions on Generic conference calls
      if (activeCall.isConferenceCall() && isGeneric) {
        if (canMerge) {
          CallCommandClient.getInstance().merge();
          return true;
        } else if (canSwap) {
          CallCommandClient.getInstance().swap();
          return true;
        }
      }

      // (3) Swap calls
      if (canSwap) {
        CallCommandClient.getInstance().swap();
        return true;
      }
    }

    /** BACKGROUND CALL */
    final Call heldCall = calls.getBackgroundCall();
    if (heldCall != null) {
      // We have a hold call so presumeable it will always support HOLD...but
      // there is no harm in double checking.
      final boolean canHold = heldCall.can(Capabilities.HOLD);

      Log.v(this, "heldCall: " + heldCall + ", canHold: " + canHold);

      // (4) unhold call
      if (heldCall.getState() == Call.State.ONHOLD && canHold) {
        CallCommandClient.getInstance().hold(heldCall.getCallId(), false);
        return true;
      }
    }

    // Always consume hard keys
    return true;
  }