Program: 42344
Project: 42344
Buggy source:
/** 
 * A key was pressed down and not handled by anything else in the window.
 * @see #onKeyUp
 * @see android.view.KeyEvent
 */
protected boolean onKeyDown(int featureId,int keyCode,KeyEvent event){
  final KeyEvent.DispatcherState dispatcher=mDecor != null ? mDecor.getKeyDispatcherState() : null;
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN:
{
      AudioManager audioManager=(AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
      if (audioManager != null) {
        audioManager.adjustSuggestedStreamVolume(keyCode == KeyEvent.KEYCODE_VOLUME_UP ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER,mVolumeControlStreamType,AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE);
      }
      return true;
    }
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
  if (mTelephonyManager == null) {
    mTelephonyManager=(TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE);
  }
if (mTelephonyManager != null && mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
  return true;
}
case KeyEvent.KEYCODE_MUTE:
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_STOP:
case KeyEvent.KEYCODE_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
case KeyEvent.KEYCODE_MEDIA_REWIND:
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
{
Intent intent=new Intent(Intent.ACTION_MEDIA_BUTTON,null);
intent.putExtra(Intent.EXTRA_KEY_EVENT,event);
getContext().sendOrderedBroadcast(intent,null);
return true;
}
case KeyEvent.KEYCODE_CAMERA:
{
if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
break;
}
if (event.getRepeatCount() == 0) {
dispatcher.startTracking(event,this);
}
 else if (event.isLongPress() && dispatcher.isTracking(event)) {
dispatcher.performedLongPress(event);
mDecor.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
sendCloseSystemWindows();
Intent intent=new Intent(Intent.ACTION_CAMERA_BUTTON,null);
intent.putExtra(Intent.EXTRA_KEY_EVENT,event);
getContext().sendOrderedBroadcast(intent,null);
}
return true;
}
case KeyEvent.KEYCODE_MENU:
{
onKeyDownPanel((featureId < 0) ? FEATURE_OPTIONS_PANEL : featureId,event);
return true;
}
case KeyEvent.KEYCODE_BACK:
{
if (event.getRepeatCount() > 0) break;
if (featureId < 0) break;
dispatcher.startTracking(event,this);
return true;
}
case KeyEvent.KEYCODE_CALL:
{
if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
break;
}
if (event.getRepeatCount() == 0) {
dispatcher.startTracking(event,this);
}
 else if (event.isLongPress() && dispatcher.isTracking(event)) {
dispatcher.performedLongPress(event);
mDecor.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
Intent intent=new Intent(Intent.ACTION_VOICE_COMMAND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
sendCloseSystemWindows();
getContext().startActivity(intent);
}
 catch (ActivityNotFoundException e) {
startCallActivity();
}
}
return true;
}
case KeyEvent.KEYCODE_SEARCH:
{
if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
break;
}
if (event.getRepeatCount() == 0) {
dispatcher.startTracking(event,this);
}
 else if (event.isLongPress() && dispatcher.isTracking(event)) {
Configuration config=getContext().getResources().getConfiguration();
if (config.keyboard == Configuration.KEYBOARD_NOKEYS || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
Intent intent=new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
sendCloseSystemWindows();
getContext().startActivity(intent);
mDecor.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
dispatcher.performedLongPress(event);
}
 catch (ActivityNotFoundException e) {
}
}
}
break;
}
}
return false;
}

Fixed version (ground truth):
/** 
 * A key was pressed down and not handled by anything else in the window.
 * @see #onKeyUp
 * @see android.view.KeyEvent
 */
protected boolean onKeyDown(int featureId,int keyCode,KeyEvent event){
  final KeyEvent.DispatcherState dispatcher=mDecor != null ? mDecor.getKeyDispatcherState() : null;
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN:
{
      AudioManager audioManager=(AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
      if (audioManager != null) {
        audioManager.adjustSuggestedStreamVolume(keyCode == KeyEvent.KEYCODE_VOLUME_UP ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER,mVolumeControlStreamType,AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE);
      }
      return true;
    }
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
  if (mTelephonyManager == null) {
    mTelephonyManager=(TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE);
  }
if (mTelephonyManager != null && mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
  return true;
}
case KeyEvent.KEYCODE_MUTE:
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_STOP:
case KeyEvent.KEYCODE_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
case KeyEvent.KEYCODE_MEDIA_REWIND:
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
{
Intent intent=new Intent(Intent.ACTION_MEDIA_BUTTON,null);
intent.putExtra(Intent.EXTRA_KEY_EVENT,event);
getContext().sendOrderedBroadcast(intent,null);
return true;
}
case KeyEvent.KEYCODE_CAMERA:
{
if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
break;
}
if (event.getRepeatCount() == 0) {
dispatcher.startTracking(event,this);
}
 else if (event.isLongPress() && dispatcher.isTracking(event)) {
dispatcher.performedLongPress(event);
mDecor.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
sendCloseSystemWindows();
Intent intent=new Intent(Intent.ACTION_CAMERA_BUTTON,null);
intent.putExtra(Intent.EXTRA_KEY_EVENT,event);
getContext().sendOrderedBroadcast(intent,null);
}
return true;
}
case KeyEvent.KEYCODE_MENU:
{
onKeyDownPanel((featureId < 0) ? FEATURE_OPTIONS_PANEL : featureId,event);
return true;
}
case KeyEvent.KEYCODE_BACK:
{
if (event.getRepeatCount() > 0) break;
if (featureId < 0) break;
dispatcher.startTracking(event,this);
return true;
}
case KeyEvent.KEYCODE_CALL:
{
if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
break;
}
if (event.getRepeatCount() == 0) {
dispatcher.startTracking(event,this);
}
 else if (event.isLongPress() && dispatcher.isTracking(event)) {
dispatcher.performedLongPress(event);
mDecor.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
Intent intent=new Intent(Intent.ACTION_VOICE_COMMAND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
sendCloseSystemWindows();
getContext().startActivity(intent);
}
 catch (ActivityNotFoundException e) {
startCallActivity();
}
}
return true;
}
case KeyEvent.KEYCODE_SEARCH:
{
if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
break;
}
if (event.getRepeatCount() == 0) {
dispatcher.startTracking(event,this);
}
 else if (event.isLongPress() && dispatcher.isTracking(event)) {
Configuration config=getContext().getResources().getConfiguration();
if (config.keyboard == Configuration.KEYBOARD_NOKEYS || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
Intent intent=new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
sendCloseSystemWindows();
getContext().startActivity(intent);
mDecor.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
dispatcher.performedLongPress(event);
return true;
}
 catch (ActivityNotFoundException e) {
}
}
}
break;
}
}
return false;
}