Program: 199418
Project: 199418
Buggy source:
@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  int device;
  int state;
  if (action.equals(Intent.ACTION_DOCK_EVENT)) {
    int dockState=intent.getIntExtra(Intent.EXTRA_DOCK_STATE,Intent.EXTRA_DOCK_STATE_UNDOCKED);
    int config;
switch (dockState) {
case Intent.EXTRA_DOCK_STATE_DESK:
      config=AudioSystem.FORCE_BT_DESK_DOCK;
    break;
case Intent.EXTRA_DOCK_STATE_CAR:
  config=AudioSystem.FORCE_BT_CAR_DOCK;
break;
case Intent.EXTRA_DOCK_STATE_LE_DESK:
config=AudioSystem.FORCE_ANALOG_DOCK;
break;
case Intent.EXTRA_DOCK_STATE_HE_DESK:
config=AudioSystem.FORCE_DIGITAL_DOCK;
break;
case Intent.EXTRA_DOCK_STATE_UNDOCKED:
default :
config=AudioSystem.FORCE_NONE;
}
if (!((dockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || ((dockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) && (mDockState == Intent.EXTRA_DOCK_STATE_LE_DESK)))) {
AudioSystem.setForceUse(AudioSystem.FOR_DOCK,config);
}
mDockState=dockState;
}
 else if (action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) {
state=intent.getIntExtra(BluetoothProfile.EXTRA_STATE,BluetoothProfile.STATE_DISCONNECTED);
device=AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
String address=null;
BluetoothDevice btDevice=intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (btDevice == null) {
return;
}
address=btDevice.getAddress();
BluetoothClass btClass=btDevice.getBluetoothClass();
if (btClass != null) {
switch (btClass.getDeviceClass()) {
case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
device=AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET;
break;
case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO:
device=AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
break;
}
}
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
address="String_Node_Str";
}
boolean connected=(state == BluetoothProfile.STATE_CONNECTED);
if (handleDeviceConnection(connected,device,address)) {
synchronized (mScoClients) {
if (connected) {
mBluetoothHeadsetDevice=btDevice;
}
 else {
mBluetoothHeadsetDevice=null;
resetBluetoothSco();
}
}
}
}
 else if (action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) || action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) {
state=intent.getIntExtra("String_Node_Str",0);
int alsaCard=intent.getIntExtra("String_Node_Str",-1);
int alsaDevice=intent.getIntExtra("String_Node_Str",-1);
boolean hasPlayback=intent.getBooleanExtra("String_Node_Str",false);
boolean hasCapture=intent.getBooleanExtra("String_Node_Str",false);
boolean hasMIDI=intent.getBooleanExtra("String_Node_Str",false);
String params=(alsaCard == -1 && alsaDevice == -1 ? "String_Node_Str" : "String_Node_Str" + alsaCard + "String_Node_Str"+ alsaDevice);
device=action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) ? AudioSystem.DEVICE_OUT_USB_ACCESSORY : AudioSystem.DEVICE_OUT_USB_DEVICE;
setWiredDeviceConnectionState(device,state,params);
device=action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) ? AudioSystem.DEVICE_IN_USB_ACCESSORY : AudioSystem.DEVICE_IN_USB_DEVICE;
setWiredDeviceConnectionState(device,state,params);
}
 else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
boolean broadcast=false;
int scoAudioState=AudioManager.SCO_AUDIO_STATE_ERROR;
synchronized (mScoClients) {
int btState=intent.getIntExtra(BluetoothProfile.EXTRA_STATE,-1);
if (!mScoClients.isEmpty() && (mScoAudioState == SCO_STATE_ACTIVE_INTERNAL || mScoAudioState == SCO_STATE_ACTIVATE_REQ || mScoAudioState == SCO_STATE_DEACTIVATE_REQ)) {
broadcast=true;
}
switch (btState) {
case BluetoothHeadset.STATE_AUDIO_CONNECTED:
scoAudioState=AudioManager.SCO_AUDIO_STATE_CONNECTED;
if (mScoAudioState != SCO_STATE_ACTIVE_INTERNAL && mScoAudioState != SCO_STATE_DEACTIVATE_REQ && mScoAudioState != SCO_STATE_DEACTIVATE_EXT_REQ) {
mScoAudioState=SCO_STATE_ACTIVE_EXTERNAL;
}
break;
case BluetoothHeadset.STATE_AUDIO_DISCONNECTED:
scoAudioState=AudioManager.SCO_AUDIO_STATE_DISCONNECTED;
mScoAudioState=SCO_STATE_INACTIVE;
clearAllScoClients(0,false);
break;
case BluetoothHeadset.STATE_AUDIO_CONNECTING:
if (mScoAudioState != SCO_STATE_ACTIVE_INTERNAL && mScoAudioState != SCO_STATE_DEACTIVATE_REQ && mScoAudioState != SCO_STATE_DEACTIVATE_EXT_REQ) {
mScoAudioState=SCO_STATE_ACTIVE_EXTERNAL;
}
default :
broadcast=false;
break;
}
}
if (broadcast) {
broadcastScoConnectionState(scoAudioState);
Intent newIntent=new Intent(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
newIntent.putExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,scoAudioState);
sendStickyBroadcastToAll(newIntent);
}
}
 else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
mBootCompleted=true;
sendMsg(mAudioHandler,MSG_LOAD_SOUND_EFFECTS,SENDMSG_QUEUE,0,0,null,0);
mKeyguardManager=(KeyguardManager)mContext.getSystemService(Context.KEYGUARD_SERVICE);
mScoConnectionState=AudioManager.SCO_AUDIO_STATE_ERROR;
resetBluetoothSco();
getBluetoothHeadset();
Intent newIntent=new Intent(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
newIntent.putExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,AudioManager.SCO_AUDIO_STATE_DISCONNECTED);
sendStickyBroadcastToAll(newIntent);
BluetoothAdapter adapter=BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
adapter.getProfileProxy(mContext,mBluetoothProfileServiceListener,BluetoothProfile.A2DP);
}
sendMsg(mAudioHandler,MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED,SENDMSG_REPLACE,0,0,null,SAFE_VOLUME_CONFIGURE_TIMEOUT_MS);
}
 else if (action.equals(Intent.ACTION_SCREEN_ON)) {
AudioSystem.setParameters("String_Node_Str");
}
 else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
AudioSystem.setParameters("String_Node_Str");
}
 else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
handleConfigurationChanged(context);
}
 else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
sendMsg(mAudioHandler,MSG_BROADCAST_AUDIO_BECOMING_NOISY,SENDMSG_REPLACE,0,0,null,0);
mMediaFocusControl.discardAudioFocusOwner();
readAudioSettings(true);
sendMsg(mAudioHandler,MSG_SET_ALL_VOLUMES,SENDMSG_QUEUE,0,0,mStreamStates[AudioSystem.STREAM_MUSIC],0);
}
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  int device;
  int state;
  if (action.equals(Intent.ACTION_DOCK_EVENT)) {
    int dockState=intent.getIntExtra(Intent.EXTRA_DOCK_STATE,Intent.EXTRA_DOCK_STATE_UNDOCKED);
    int config;
switch (dockState) {
case Intent.EXTRA_DOCK_STATE_DESK:
      config=AudioSystem.FORCE_BT_DESK_DOCK;
    break;
case Intent.EXTRA_DOCK_STATE_CAR:
  config=AudioSystem.FORCE_BT_CAR_DOCK;
break;
case Intent.EXTRA_DOCK_STATE_LE_DESK:
config=AudioSystem.FORCE_ANALOG_DOCK;
break;
case Intent.EXTRA_DOCK_STATE_HE_DESK:
config=AudioSystem.FORCE_DIGITAL_DOCK;
break;
case Intent.EXTRA_DOCK_STATE_UNDOCKED:
default :
config=AudioSystem.FORCE_NONE;
}
if (!((dockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || ((dockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) && (mDockState == Intent.EXTRA_DOCK_STATE_LE_DESK)))) {
AudioSystem.setForceUse(AudioSystem.FOR_DOCK,config);
}
mDockState=dockState;
}
 else if (action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) {
state=intent.getIntExtra(BluetoothProfile.EXTRA_STATE,BluetoothProfile.STATE_DISCONNECTED);
device=AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
String address=null;
BluetoothDevice btDevice=intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (btDevice == null) {
return;
}
address=btDevice.getAddress();
BluetoothClass btClass=btDevice.getBluetoothClass();
if (btClass != null) {
switch (btClass.getDeviceClass()) {
case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
device=AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET;
break;
case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO:
device=AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
break;
}
}
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
address="String_Node_Str";
}
boolean connected=(state == BluetoothProfile.STATE_CONNECTED);
if (handleDeviceConnection(connected,device,address)) {
synchronized (mScoClients) {
if (connected) {
mBluetoothHeadsetDevice=btDevice;
}
 else {
mBluetoothHeadsetDevice=null;
resetBluetoothSco();
}
}
}
}
 else if (action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG)) {
state=intent.getIntExtra("String_Node_Str",0);
int alsaCard=intent.getIntExtra("String_Node_Str",-1);
int alsaDevice=intent.getIntExtra("String_Node_Str",-1);
String params=(alsaCard == -1 && alsaDevice == -1 ? "String_Node_Str" : "String_Node_Str" + alsaCard + "String_Node_Str"+ alsaDevice);
device=AudioSystem.DEVICE_OUT_USB_ACCESSORY;
setWiredDeviceConnectionState(device,state,params);
}
 else if (action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) {
state=intent.getIntExtra("String_Node_Str",0);
int alsaCard=intent.getIntExtra("String_Node_Str",-1);
int alsaDevice=intent.getIntExtra("String_Node_Str",-1);
boolean hasPlayback=intent.getBooleanExtra("String_Node_Str",false);
boolean hasCapture=intent.getBooleanExtra("String_Node_Str",false);
boolean hasMIDI=intent.getBooleanExtra("String_Node_Str",false);
String params=(alsaCard == -1 && alsaDevice == -1 ? "String_Node_Str" : "String_Node_Str" + alsaCard + "String_Node_Str"+ alsaDevice);
if (hasPlayback) {
device=AudioSystem.DEVICE_OUT_USB_DEVICE;
setWiredDeviceConnectionState(device,state,params);
}
if (hasCapture) {
device=AudioSystem.DEVICE_IN_USB_DEVICE;
setWiredDeviceConnectionState(device,state,params);
}
}
 else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
boolean broadcast=false;
int scoAudioState=AudioManager.SCO_AUDIO_STATE_ERROR;
synchronized (mScoClients) {
int btState=intent.getIntExtra(BluetoothProfile.EXTRA_STATE,-1);
if (!mScoClients.isEmpty() && (mScoAudioState == SCO_STATE_ACTIVE_INTERNAL || mScoAudioState == SCO_STATE_ACTIVATE_REQ || mScoAudioState == SCO_STATE_DEACTIVATE_REQ)) {
broadcast=true;
}
switch (btState) {
case BluetoothHeadset.STATE_AUDIO_CONNECTED:
scoAudioState=AudioManager.SCO_AUDIO_STATE_CONNECTED;
if (mScoAudioState != SCO_STATE_ACTIVE_INTERNAL && mScoAudioState != SCO_STATE_DEACTIVATE_REQ && mScoAudioState != SCO_STATE_DEACTIVATE_EXT_REQ) {
mScoAudioState=SCO_STATE_ACTIVE_EXTERNAL;
}
break;
case BluetoothHeadset.STATE_AUDIO_DISCONNECTED:
scoAudioState=AudioManager.SCO_AUDIO_STATE_DISCONNECTED;
mScoAudioState=SCO_STATE_INACTIVE;
clearAllScoClients(0,false);
break;
case BluetoothHeadset.STATE_AUDIO_CONNECTING:
if (mScoAudioState != SCO_STATE_ACTIVE_INTERNAL && mScoAudioState != SCO_STATE_DEACTIVATE_REQ && mScoAudioState != SCO_STATE_DEACTIVATE_EXT_REQ) {
mScoAudioState=SCO_STATE_ACTIVE_EXTERNAL;
}
default :
broadcast=false;
break;
}
}
if (broadcast) {
broadcastScoConnectionState(scoAudioState);
Intent newIntent=new Intent(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
newIntent.putExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,scoAudioState);
sendStickyBroadcastToAll(newIntent);
}
}
 else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
mBootCompleted=true;
sendMsg(mAudioHandler,MSG_LOAD_SOUND_EFFECTS,SENDMSG_QUEUE,0,0,null,0);
mKeyguardManager=(KeyguardManager)mContext.getSystemService(Context.KEYGUARD_SERVICE);
mScoConnectionState=AudioManager.SCO_AUDIO_STATE_ERROR;
resetBluetoothSco();
getBluetoothHeadset();
Intent newIntent=new Intent(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
newIntent.putExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,AudioManager.SCO_AUDIO_STATE_DISCONNECTED);
sendStickyBroadcastToAll(newIntent);
BluetoothAdapter adapter=BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
adapter.getProfileProxy(mContext,mBluetoothProfileServiceListener,BluetoothProfile.A2DP);
}
sendMsg(mAudioHandler,MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED,SENDMSG_REPLACE,0,0,null,SAFE_VOLUME_CONFIGURE_TIMEOUT_MS);
}
 else if (action.equals(Intent.ACTION_SCREEN_ON)) {
AudioSystem.setParameters("String_Node_Str");
}
 else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
AudioSystem.setParameters("String_Node_Str");
}
 else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
handleConfigurationChanged(context);
}
 else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
sendMsg(mAudioHandler,MSG_BROADCAST_AUDIO_BECOMING_NOISY,SENDMSG_REPLACE,0,0,null,0);
mMediaFocusControl.discardAudioFocusOwner();
readAudioSettings(true);
sendMsg(mAudioHandler,MSG_SET_ALL_VOLUMES,SENDMSG_QUEUE,0,0,mStreamStates[AudioSystem.STREAM_MUSIC],0);
}
}