Program: 184849
Project: 184849
Buggy source:
/** 
 * Updates the enabledness and visibility of all items in the InCallMenuView based on the current state of the Phone. This is called every time we need to display the menu, right before it becomes visible.
 * @return true if we successfully updated the items and it's OKto go ahead and show the menu, or false if we shouldn't show the menu at all.
 */
boolean updateItems(Phone phone){
  if (DBG)   log("String_Node_Str");
  if (phone.getState() == Phone.State.IDLE) {
    if (DBG)     log("String_Node_Str");
    return false;
  }
  final boolean hasRingingCall=!phone.getRingingCall().isIdle();
  final boolean hasActiveCall=!phone.getForegroundCall().isIdle();
  final Call.State fgCallState=phone.getForegroundCall().getState();
  final boolean hasHoldingCall=!phone.getBackgroundCall().isIdle();
  if (hasActiveCall && (PhoneApp.getInstance().isOtaCallInActiveState())) {
    mAnswerAndHold.setVisible(false);
    mAnswerAndHold.setEnabled(false);
    mAnswerAndEnd.setVisible(false);
    mAnswerAndEnd.setEnabled(false);
    mManageConference.setVisible(false);
    mAddCall.setEnabled(false);
    mSwapCalls.setEnabled(false);
    mMergeCalls.setEnabled(false);
    mHold.setEnabled(false);
    mBluetooth.setEnabled(false);
    mMute.setEnabled(false);
    mAnswer.setVisible(false);
    mIgnore.setVisible(false);
    boolean inConferenceCall=PhoneUtils.isConferenceCall(phone.getForegroundCall());
    boolean showShowDialpad=!InCallScreen.ConfigurationHelper.isLandscape() && !inConferenceCall;
    boolean enableShowDialpad=showShowDialpad && mInCallScreen.okToShowDialpad();
    mShowDialpad.setVisible(showShowDialpad);
    mShowDialpad.setEnabled(enableShowDialpad);
    boolean isDtmfDialerOpened=mInCallScreen.isDialerOpened();
    mShowDialpad.setText(isDtmfDialerOpened ? R.string.menu_hideDialpad : R.string.menu_showDialpad);
    mEndCall.setVisible(true);
    mEndCall.setEnabled(true);
    mSpeaker.setVisible(true);
    if (PhoneApp.getInstance().isHeadsetPlugged()) {
      mSpeaker.setEnabled(false);
      mSpeaker.setIndicatorState(false);
    }
 else {
      mSpeaker.setEnabled(true);
      boolean speakerOn=PhoneUtils.isSpeakerOn(mInCallScreen.getApplicationContext());
      mSpeaker.setIndicatorState(speakerOn);
    }
    mInCallMenuView.updateVisibility();
    return true;
  }
  if (hasRingingCall) {
    if (hasActiveCall && !hasHoldingCall) {
      if (phone.getPhoneName().equals("String_Node_Str")) {
        mAnswer.setVisible(true);
        mAnswer.setEnabled(true);
        mIgnore.setVisible(true);
        mIgnore.setEnabled(true);
        mAnswerAndHold.setVisible(false);
        mAnswerAndEnd.setVisible(false);
      }
 else {
        mAnswerAndHold.setVisible(true);
        mAnswerAndHold.setEnabled(true);
        mAnswerAndEnd.setVisible(true);
        mAnswerAndEnd.setEnabled(true);
        mAnswer.setVisible(false);
        mIgnore.setVisible(false);
        mManageConference.setVisible(false);
      }
      mShowDialpad.setVisible(false);
      mEndCall.setVisible(false);
      mAddCall.setVisible(false);
      mSwapCalls.setVisible(false);
      mMergeCalls.setVisible(false);
      mBluetooth.setVisible(false);
      mSpeaker.setVisible(false);
      mMute.setVisible(false);
      mHold.setVisible(false);
      mInCallMenuView.updateVisibility();
      return true;
    }
 else {
      return false;
    }
  }
  InCallControlState inCallControlState=mInCallScreen.getUpdatedInCallControlState();
  mManageConference.setVisible(inCallControlState.manageConferenceVisible);
  mManageConference.setEnabled(inCallControlState.manageConferenceEnabled);
  boolean showShowDialpad=!InCallScreen.ConfigurationHelper.isLandscape() && !inCallControlState.manageConferenceVisible;
  boolean enableShowDialpad=showShowDialpad && mInCallScreen.okToShowDialpad();
  mShowDialpad.setVisible(showShowDialpad);
  mShowDialpad.setEnabled(enableShowDialpad);
  mShowDialpad.setText(mInCallScreen.isDialerOpened() ? R.string.menu_hideDialpad : R.string.menu_showDialpad);
  mEndCall.setVisible(true);
  mEndCall.setEnabled(true);
  mAddCall.setVisible(true);
  mAddCall.setEnabled(inCallControlState.canAddCall);
  mSwapCalls.setVisible(true);
  mSwapCalls.setEnabled(inCallControlState.canSwap);
  mMergeCalls.setVisible(true);
  mMergeCalls.setEnabled(inCallControlState.canMerge);
  mBluetooth.setVisible(true);
  mBluetooth.setEnabled(inCallControlState.bluetoothEnabled);
  mBluetooth.setIndicatorState(inCallControlState.bluetoothIndicatorOn);
  mSpeaker.setVisible(true);
  mSpeaker.setEnabled(inCallControlState.speakerEnabled);
  mSpeaker.setIndicatorState(inCallControlState.speakerOn);
  mMute.setVisible(true);
  mMute.setEnabled(inCallControlState.canMute);
  mMute.setIndicatorState(inCallControlState.muteIndicatorOn);
  mHold.setVisible(inCallControlState.supportsHold);
  mHold.setIndicatorState(inCallControlState.onHold);
  mHold.setEnabled(inCallControlState.canHold);
  mAnswer.setVisible(false);
  mAnswer.setEnabled(false);
  mIgnore.setVisible(false);
  mIgnore.setEnabled(false);
  mAnswerAndHold.setVisible(false);
  mAnswerAndHold.setEnabled(false);
  mAnswerAndEnd.setVisible(false);
  mAnswerAndEnd.setEnabled(false);
  mInCallMenuView.updateVisibility();
  return true;
}

Fixed version (ground truth):
/** 
 * Updates the enabledness and visibility of all items in the InCallMenuView based on the current state of the Phone. This is called every time we need to display the menu, right before it becomes visible.
 * @return true if we successfully updated the items and it's OKto go ahead and show the menu, or false if we shouldn't show the menu at all.
 */
boolean updateItems(Phone phone){
  if (DBG)   log("String_Node_Str");
  if (phone.getState() == Phone.State.IDLE) {
    if (DBG)     log("String_Node_Str");
    return false;
  }
  final boolean hasRingingCall=!phone.getRingingCall().isIdle();
  final boolean hasActiveCall=!phone.getForegroundCall().isIdle();
  final Call.State fgCallState=phone.getForegroundCall().getState();
  final boolean hasHoldingCall=!phone.getBackgroundCall().isIdle();
  if (hasActiveCall && (PhoneApp.getInstance().isOtaCallInActiveState())) {
    mAnswerAndHold.setVisible(false);
    mAnswerAndHold.setEnabled(false);
    mAnswerAndEnd.setVisible(false);
    mAnswerAndEnd.setEnabled(false);
    mManageConference.setVisible(false);
    mAddCall.setEnabled(false);
    mSwapCalls.setEnabled(false);
    mMergeCalls.setEnabled(false);
    mHold.setEnabled(false);
    mBluetooth.setEnabled(false);
    mMute.setEnabled(false);
    mAnswer.setVisible(false);
    mIgnore.setVisible(false);
    boolean inConferenceCall=PhoneUtils.isConferenceCall(phone.getForegroundCall());
    boolean showShowDialpad=!InCallScreen.ConfigurationHelper.isLandscape() && !inConferenceCall;
    boolean enableShowDialpad=showShowDialpad && mInCallScreen.okToShowDialpad();
    mShowDialpad.setVisible(showShowDialpad);
    mShowDialpad.setEnabled(enableShowDialpad);
    boolean isDtmfDialerOpened=mInCallScreen.isDialerOpened();
    mShowDialpad.setText(isDtmfDialerOpened ? R.string.menu_hideDialpad : R.string.menu_showDialpad);
    mEndCall.setVisible(true);
    mEndCall.setEnabled(true);
    mSpeaker.setVisible(true);
    mSpeaker.setEnabled(true);
    boolean speakerOn=PhoneUtils.isSpeakerOn(mInCallScreen.getApplicationContext());
    mSpeaker.setIndicatorState(speakerOn);
    mInCallMenuView.updateVisibility();
    return true;
  }
  if (hasRingingCall) {
    if (hasActiveCall && !hasHoldingCall) {
      if (phone.getPhoneName().equals("String_Node_Str")) {
        mAnswer.setVisible(true);
        mAnswer.setEnabled(true);
        mIgnore.setVisible(true);
        mIgnore.setEnabled(true);
        mAnswerAndHold.setVisible(false);
        mAnswerAndEnd.setVisible(false);
      }
 else {
        mAnswerAndHold.setVisible(true);
        mAnswerAndHold.setEnabled(true);
        mAnswerAndEnd.setVisible(true);
        mAnswerAndEnd.setEnabled(true);
        mAnswer.setVisible(false);
        mIgnore.setVisible(false);
        mManageConference.setVisible(false);
      }
      mShowDialpad.setVisible(false);
      mEndCall.setVisible(false);
      mAddCall.setVisible(false);
      mSwapCalls.setVisible(false);
      mMergeCalls.setVisible(false);
      mBluetooth.setVisible(false);
      mSpeaker.setVisible(false);
      mMute.setVisible(false);
      mHold.setVisible(false);
      mInCallMenuView.updateVisibility();
      return true;
    }
 else {
      return false;
    }
  }
  InCallControlState inCallControlState=mInCallScreen.getUpdatedInCallControlState();
  mManageConference.setVisible(inCallControlState.manageConferenceVisible);
  mManageConference.setEnabled(inCallControlState.manageConferenceEnabled);
  boolean showShowDialpad=!InCallScreen.ConfigurationHelper.isLandscape() && !inCallControlState.manageConferenceVisible;
  boolean enableShowDialpad=showShowDialpad && mInCallScreen.okToShowDialpad();
  mShowDialpad.setVisible(showShowDialpad);
  mShowDialpad.setEnabled(enableShowDialpad);
  mShowDialpad.setText(mInCallScreen.isDialerOpened() ? R.string.menu_hideDialpad : R.string.menu_showDialpad);
  mEndCall.setVisible(true);
  mEndCall.setEnabled(true);
  mAddCall.setVisible(true);
  mAddCall.setEnabled(inCallControlState.canAddCall);
  mSwapCalls.setVisible(true);
  mSwapCalls.setEnabled(inCallControlState.canSwap);
  mMergeCalls.setVisible(true);
  mMergeCalls.setEnabled(inCallControlState.canMerge);
  mBluetooth.setVisible(true);
  mBluetooth.setEnabled(inCallControlState.bluetoothEnabled);
  mBluetooth.setIndicatorState(inCallControlState.bluetoothIndicatorOn);
  mSpeaker.setVisible(true);
  mSpeaker.setEnabled(inCallControlState.speakerEnabled);
  mSpeaker.setIndicatorState(inCallControlState.speakerOn);
  mMute.setVisible(true);
  mMute.setEnabled(inCallControlState.canMute);
  mMute.setIndicatorState(inCallControlState.muteIndicatorOn);
  mHold.setVisible(inCallControlState.supportsHold);
  mHold.setIndicatorState(inCallControlState.onHold);
  mHold.setEnabled(inCallControlState.canHold);
  mAnswer.setVisible(false);
  mAnswer.setEnabled(false);
  mIgnore.setVisible(false);
  mIgnore.setEnabled(false);
  mAnswerAndHold.setVisible(false);
  mAnswerAndHold.setEnabled(false);
  mAnswerAndEnd.setVisible(false);
  mAnswerAndEnd.setEnabled(false);
  mInCallMenuView.updateVisibility();
  return true;
}