Program: 184711
Project: 184711
Buggy source:
/** 
 * Handles the wired headset button while in-call. This is called from the PhoneApp, not from the InCallScreen, since the HEADSETHOOK button means "mute or unmute the current call" *any* time a call is active, even if the user isn't actually on the in-call screen.
 * @return true if we consumed the event.
 */
static boolean handleHeadsetHook(Phone phone){
  if (DBG)   log("String_Node_Str");
  if (phone.getState() == Phone.State.IDLE) {
    return false;
  }
  final boolean hasRingingCall=!phone.getRingingCall().isIdle();
  final boolean hasActiveCall=!phone.getForegroundCall().isIdle();
  final boolean hasHoldingCall=!phone.getBackgroundCall().isIdle();
  if (hasRingingCall) {
    int phoneType=phone.getPhoneType();
    if (phoneType == Phone.PHONE_TYPE_CDMA) {
      answerCall(phone);
    }
 else     if (phoneType == Phone.PHONE_TYPE_GSM) {
      if (hasActiveCall && hasHoldingCall) {
        if (DBG)         log("String_Node_Str");
        answerAndEndActive(phone);
      }
 else {
        if (DBG)         log("String_Node_Str");
        answerCall(phone);
      }
    }
 else {
      throw new IllegalStateException("String_Node_Str" + phoneType);
    }
  }
 else {
    Connection c=phone.getForegroundCall().getLatestConnection();
    if (c != null && !PhoneNumberUtils.isEmergencyNumber(c.getAddress())) {
      if (getMute(phone)) {
        if (DBG)         log("String_Node_Str");
        setMute(phone,false);
      }
 else {
        if (DBG)         log("String_Node_Str");
        setMute(phone,true);
      }
    }
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Handles the wired headset button while in-call. This is called from the PhoneApp, not from the InCallScreen, since the HEADSETHOOK button means "mute or unmute the current call" *any* time a call is active, even if the user isn't actually on the in-call screen.
 * @return true if we consumed the event.
 */
static boolean handleHeadsetHook(Phone phone,KeyEvent event){
  if (DBG)   log("String_Node_Str" + event.getAction() + "String_Node_Str"+ event.getRepeatCount());
  if (phone.getState() == Phone.State.IDLE) {
    return false;
  }
  final boolean hasRingingCall=!phone.getRingingCall().isIdle();
  final boolean hasActiveCall=!phone.getForegroundCall().isIdle();
  final boolean hasHoldingCall=!phone.getBackgroundCall().isIdle();
  if (hasRingingCall && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP) {
    int phoneType=phone.getPhoneType();
    if (phoneType == Phone.PHONE_TYPE_CDMA) {
      answerCall(phone);
    }
 else     if (phoneType == Phone.PHONE_TYPE_GSM) {
      if (hasActiveCall && hasHoldingCall) {
        if (DBG)         log("String_Node_Str");
        answerAndEndActive(phone);
      }
 else {
        if (DBG)         log("String_Node_Str");
        answerCall(phone);
      }
    }
 else {
      throw new IllegalStateException("String_Node_Str" + phoneType);
    }
  }
 else {
    if (event.isLongPress()) {
      if (DBG)       log("String_Node_Str");
      hangup(phone);
    }
 else     if (event.getAction() == KeyEvent.ACTION_UP && event.getRepeatCount() == 0) {
      Connection c=phone.getForegroundCall().getLatestConnection();
      if (c != null && !PhoneNumberUtils.isEmergencyNumber(c.getAddress())) {
        if (getMute(phone)) {
          if (DBG)           log("String_Node_Str");
          setMute(phone,false);
        }
 else {
          if (DBG)           log("String_Node_Str");
          setMute(phone,true);
        }
      }
    }
  }
  return true;
}