Program: 23985
Project: 23985
Buggy source:
@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  if (action.equals(BluetoothA2dp.SINK_STATE_CHANGED_ACTION)) {
    int state=intent.getIntExtra(BluetoothA2dp.SINK_STATE,BluetoothA2dp.STATE_DISCONNECTED);
    String address=intent.getStringExtra(BluetoothIntent.ADDRESS);
    if (state == BluetoothA2dp.STATE_DISCONNECTED) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,AudioSystem.DEVICE_STATE_UNAVAILABLE,address);
    }
 else     if (state == BluetoothA2dp.STATE_CONNECTED) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,AudioSystem.DEVICE_STATE_AVAILABLE,address);
    }
  }
 else   if (action.equals(BluetoothIntent.HEADSET_AUDIO_STATE_CHANGED_ACTION)) {
    int state=intent.getIntExtra(BluetoothIntent.HEADSET_AUDIO_STATE,BluetoothHeadset.STATE_ERROR);
    String address=intent.getStringExtra(BluetoothIntent.ADDRESS);
    if (state == BluetoothHeadset.AUDIO_STATE_DISCONNECTED) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO,AudioSystem.DEVICE_STATE_UNAVAILABLE,address);
    }
 else     if (state == BluetoothHeadset.AUDIO_STATE_CONNECTED) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO,AudioSystem.DEVICE_STATE_AVAILABLE,address);
    }
  }
 else   if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
    int state=intent.getIntExtra("String_Node_Str",0);
    if ((state & BIT_HEADSET) == 0 && (mHeadsetState & BIT_HEADSET) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
    }
 else     if ((state & BIT_HEADSET) != 0 && (mHeadsetState & BIT_HEADSET) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
    }
    if ((state & BIT_HEADSET_NO_MIC) == 0 && (mHeadsetState & BIT_HEADSET_NO_MIC) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
    }
 else     if ((state & BIT_HEADSET_NO_MIC) != 0 && (mHeadsetState & BIT_HEADSET_NO_MIC) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
    }
    if ((state & BIT_TTY) == 0 && (mHeadsetState & BIT_TTY) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_TTY,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
    }
 else     if ((state & BIT_TTY) != 0 && (mHeadsetState & BIT_TTY) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_TTY,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
    }
    if ((state & BIT_FM_HEADSET) == 0 && (mHeadsetState & BIT_FM_HEADSET) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_HEADPHONE,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
    }
 else     if ((state & BIT_FM_HEADSET) != 0 && (mHeadsetState & BIT_FM_HEADSET) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_HEADPHONE,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
    }
    if ((state & BIT_FM_SPEAKER) == 0 && (mHeadsetState & BIT_FM_SPEAKER) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_SPEAKER,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
    }
 else     if ((state & BIT_FM_SPEAKER) != 0 && (mHeadsetState & BIT_FM_SPEAKER) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_SPEAKER,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
    }
    mHeadsetState=state;
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  if (action.equals(BluetoothA2dp.SINK_STATE_CHANGED_ACTION)) {
    int state=intent.getIntExtra(BluetoothA2dp.SINK_STATE,BluetoothA2dp.STATE_DISCONNECTED);
    String address=intent.getStringExtra(BluetoothIntent.ADDRESS);
    if (state == BluetoothA2dp.STATE_DISCONNECTED) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,AudioSystem.DEVICE_STATE_UNAVAILABLE,address);
      mConnectedDevices.remove(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP);
    }
 else     if (state == BluetoothA2dp.STATE_CONNECTED) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,AudioSystem.DEVICE_STATE_AVAILABLE,address);
      mConnectedDevices.put(new Integer(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP),address);
    }
  }
 else   if (action.equals(BluetoothIntent.HEADSET_AUDIO_STATE_CHANGED_ACTION)) {
    int state=intent.getIntExtra(BluetoothIntent.HEADSET_AUDIO_STATE,BluetoothHeadset.STATE_ERROR);
    String address=intent.getStringExtra(BluetoothIntent.ADDRESS);
    if (state == BluetoothHeadset.AUDIO_STATE_DISCONNECTED) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO,AudioSystem.DEVICE_STATE_UNAVAILABLE,address);
      mConnectedDevices.remove(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO);
    }
 else     if (state == BluetoothHeadset.AUDIO_STATE_CONNECTED) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO,AudioSystem.DEVICE_STATE_AVAILABLE,address);
      mConnectedDevices.put(new Integer(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO),address);
    }
  }
 else   if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
    int state=intent.getIntExtra("String_Node_Str",0);
    if ((state & BIT_HEADSET) == 0 && (mHeadsetState & BIT_HEADSET) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
      mConnectedDevices.remove(AudioSystem.DEVICE_OUT_WIRED_HEADSET);
    }
 else     if ((state & BIT_HEADSET) != 0 && (mHeadsetState & BIT_HEADSET) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
      mConnectedDevices.put(new Integer(AudioSystem.DEVICE_OUT_WIRED_HEADSET),"String_Node_Str");
    }
    if ((state & BIT_HEADSET_NO_MIC) == 0 && (mHeadsetState & BIT_HEADSET_NO_MIC) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
      mConnectedDevices.remove(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE);
    }
 else     if ((state & BIT_HEADSET_NO_MIC) != 0 && (mHeadsetState & BIT_HEADSET_NO_MIC) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
      mConnectedDevices.put(new Integer(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE),"String_Node_Str");
    }
    if ((state & BIT_TTY) == 0 && (mHeadsetState & BIT_TTY) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_TTY,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
      mConnectedDevices.remove(AudioSystem.DEVICE_OUT_TTY);
    }
 else     if ((state & BIT_TTY) != 0 && (mHeadsetState & BIT_TTY) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_TTY,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
      mConnectedDevices.put(new Integer(AudioSystem.DEVICE_OUT_TTY),"String_Node_Str");
    }
    if ((state & BIT_FM_HEADSET) == 0 && (mHeadsetState & BIT_FM_HEADSET) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_HEADPHONE,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
      mConnectedDevices.remove(AudioSystem.DEVICE_OUT_FM_HEADPHONE);
    }
 else     if ((state & BIT_FM_HEADSET) != 0 && (mHeadsetState & BIT_FM_HEADSET) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_HEADPHONE,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
      mConnectedDevices.put(new Integer(AudioSystem.DEVICE_OUT_FM_HEADPHONE),"String_Node_Str");
    }
    if ((state & BIT_FM_SPEAKER) == 0 && (mHeadsetState & BIT_FM_SPEAKER) != 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_SPEAKER,AudioSystem.DEVICE_STATE_UNAVAILABLE,"String_Node_Str");
      mConnectedDevices.remove(AudioSystem.DEVICE_OUT_FM_SPEAKER);
    }
 else     if ((state & BIT_FM_SPEAKER) != 0 && (mHeadsetState & BIT_FM_SPEAKER) == 0) {
      AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_SPEAKER,AudioSystem.DEVICE_STATE_AVAILABLE,"String_Node_Str");
      mConnectedDevices.put(new Integer(AudioSystem.DEVICE_OUT_FM_SPEAKER),"String_Node_Str");
    }
    mHeadsetState=state;
  }
}