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);
    }
  }
  /** Called when the activity goes in/out of the foreground. */
  public void onUiShowing(boolean showing) {
    // We need to update the notification bar when we leave the UI because that
    // could trigger it to show again.
    if (mStatusBarNotifier != null) {
      mStatusBarNotifier.updateNotification(mInCallState, mCallList);
    }

    if (mProximitySensor != null) {
      mProximitySensor.onInCallShowing(showing);
    }

    if (showing) {
      mIsActivityPreviouslyStarted = true;
    }
  }
  /** Hangs up any active or outgoing calls. */
  public void hangUpOngoingCall(Context context) {
    // By the time we receive this intent, we could be shut down and call list
    // could be null.  Bail in those cases.
    if (mCallList == null) {
      if (mStatusBarNotifier == null) {
        // The In Call UI has crashed but the notification still stayed up. We should not
        // come to this stage.
        StatusBarNotifier.clearInCallNotification(context);
      }
      return;
    }

    Call call = mCallList.getOutgoingCall();
    if (call == null) {
      call = mCallList.getActiveOrBackgroundCall();
    }

    if (call != null) {
      CallCommandClient.getInstance().disconnectCall(call.getCallId());
    }
  }
 /** Starts the incoming call Ui immediately, bypassing the card UI */
 public void startIncomingCallUi(InCallState inCallState) {
   mStatusBarNotifier.updateNotificationAndLaunchIncomingCallUi(inCallState, mCallList);
 }