Program: 198949
Project: 198949
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public int interceptKeyBeforeQueueing(KeyEvent event,int policyFlags){
  if (!mSystemBooted) {
    return 0;
  }
  final boolean interactive=(policyFlags & FLAG_INTERACTIVE) != 0;
  final boolean down=event.getAction() == KeyEvent.ACTION_DOWN;
  final boolean canceled=event.isCanceled();
  final int keyCode=event.getKeyCode();
  final boolean isInjected=(policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
  final boolean keyguardActive=(mKeyguardDelegate == null ? false : (interactive ? mKeyguardDelegate.isShowingAndNotHidden() : mKeyguardDelegate.isShowing()));
  if (keyCode == KeyEvent.KEYCODE_POWER || keyCode == KeyEvent.KEYCODE_SLEEP || keyCode == KeyEvent.KEYCODE_WAKEUP) {
    policyFlags|=WindowManagerPolicy.FLAG_WAKE;
  }
  if (DEBUG_INPUT) {
    Log.d(TAG,"String_Node_Str" + keyCode + "String_Node_Str"+ interactive+ "String_Node_Str"+ keyguardActive+ "String_Node_Str"+ Integer.toHexString(policyFlags));
  }
  int result;
  boolean isWakeKey=(policyFlags & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
  if (interactive || (isInjected && !isWakeKey)) {
    result=ACTION_PASS_TO_USER;
  }
 else {
    result=0;
    if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
      isWakeKey=false;
    }
  }
  if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode,event)) {
    return result;
  }
  boolean useHapticFeedback=down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 && event.getRepeatCount() == 0;
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_MUTE:
{
      if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (down) {
          if (interactive && !mVolumeDownKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
            mVolumeDownKeyTriggered=true;
            mVolumeDownKeyTime=event.getDownTime();
            mVolumeDownKeyConsumedByScreenshotChord=false;
            cancelPendingPowerKeyAction();
            interceptScreenshotChord();
          }
        }
 else {
          mVolumeDownKeyTriggered=false;
          cancelPendingScreenshotChordAction();
        }
      }
 else       if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (down) {
          if (interactive && !mVolumeUpKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
            mVolumeUpKeyTriggered=true;
            cancelPendingPowerKeyAction();
            cancelPendingScreenshotChordAction();
          }
        }
 else {
          mVolumeUpKeyTriggered=false;
          cancelPendingScreenshotChordAction();
        }
      }
      if (down) {
        ITelephony telephonyService=getTelephonyService();
        if (telephonyService != null) {
          try {
            if (telephonyService.isRinging()) {
              Log.i(TAG,"String_Node_Str" + "String_Node_Str");
              telephonyService.silenceRinger();
              result&=~ACTION_PASS_TO_USER;
              break;
            }
            if (telephonyService.isOffhook() && (result & ACTION_PASS_TO_USER) == 0) {
              handleVolumeKey(AudioManager.STREAM_VOICE_CALL,keyCode);
              break;
            }
          }
 catch (          RemoteException ex) {
            Log.w(TAG,"String_Node_Str",ex);
          }
        }
        if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
          handleVolumeKey(AudioManager.STREAM_MUSIC,keyCode);
          break;
        }
      }
      break;
    }
case KeyEvent.KEYCODE_ENDCALL:
{
    result&=~ACTION_PASS_TO_USER;
    if (down) {
      ITelephony telephonyService=getTelephonyService();
      boolean hungUp=false;
      if (telephonyService != null) {
        try {
          hungUp=telephonyService.endCall();
        }
 catch (        RemoteException ex) {
          Log.w(TAG,"String_Node_Str",ex);
        }
      }
      interceptPowerKeyDown(!interactive || hungUp);
    }
 else {
      if (interceptPowerKeyUp(canceled)) {
        if ((mEndcallBehavior & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
          if (goHome()) {
            break;
          }
        }
        if ((mEndcallBehavior & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
          mPowerManager.goToSleep(event.getEventTime());
          isWakeKey=false;
        }
      }
    }
    break;
  }
case KeyEvent.KEYCODE_POWER:
{
  result&=~ACTION_PASS_TO_USER;
  if (down) {
    mImmersiveModeConfirmation.onPowerKeyDown(interactive,event.getDownTime(),isImmersiveMode(mLastSystemUiFlags));
    if (interactive && !mPowerKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
      mPowerKeyTriggered=true;
      mPowerKeyTime=event.getDownTime();
      interceptScreenshotChord();
    }
    ITelephony telephonyService=getTelephonyService();
    boolean hungUp=false;
    if (telephonyService != null) {
      try {
        if (telephonyService.isRinging()) {
          telephonyService.silenceRinger();
        }
 else         if ((mIncallPowerBehavior & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 && telephonyService.isOffhook() && isScreenOn) {
          hungUp=telephonyService.endCall();
        }
      }
 catch (      RemoteException ex) {
        Log.w(TAG,"String_Node_Str",ex);
      }
    }
    interceptPowerKeyDown(!interactive || hungUp || mVolumeDownKeyTriggered|| mVolumeUpKeyTriggered);
  }
 else {
    mPowerKeyTriggered=false;
    cancelPendingScreenshotChordAction();
    if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
      powerShortPress(event.getEventTime());
      isWakeKey=false;
    }
    mPendingPowerKeyUpCanceled=false;
  }
  break;
}
case KeyEvent.KEYCODE_SLEEP:
{
result&=~ACTION_PASS_TO_USER;
if (!mPowerManager.isInteractive()) {
  useHapticFeedback=false;
}
mPowerManager.goToSleep(event.getEventTime());
isWakeKey=false;
break;
}
case KeyEvent.KEYCODE_WAKEUP:
{
result&=~ACTION_PASS_TO_USER;
break;
}
case KeyEvent.KEYCODE_MEDIA_PLAY:
case KeyEvent.KEYCODE_MEDIA_PAUSE:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if (down) {
ITelephony telephonyService=getTelephonyService();
if (telephonyService != null) {
try {
if (!telephonyService.isIdle()) {
  break;
}
}
 catch (RemoteException ex) {
Log.w(TAG,"String_Node_Str",ex);
}
}
}
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MUTE:
case KeyEvent.KEYCODE_MEDIA_STOP:
case KeyEvent.KEYCODE_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
case KeyEvent.KEYCODE_MEDIA_REWIND:
case KeyEvent.KEYCODE_MEDIA_RECORD:
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
{
if ((result & ACTION_PASS_TO_USER) == 0) {
mBroadcastWakeLock.acquire();
Message msg=mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,new KeyEvent(event));
msg.setAsynchronous(true);
msg.sendToTarget();
}
break;
}
case KeyEvent.KEYCODE_CALL:
{
if (down) {
ITelephony telephonyService=getTelephonyService();
if (telephonyService != null) {
try {
if (telephonyService.isRinging()) {
Log.i(TAG,"String_Node_Str" + "String_Node_Str");
telephonyService.answerRingingCall();
result&=~ACTION_PASS_TO_USER;
}
}
 catch (RemoteException ex) {
Log.w(TAG,"String_Node_Str",ex);
}
}
}
break;
}
}
if (useHapticFeedback) {
performHapticFeedbackLw(null,HapticFeedbackConstants.VIRTUAL_KEY,false);
}
if (isWakeKey) {
mPowerManager.wakeUp(event.getEventTime());
}
return result;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public int interceptKeyBeforeQueueing(KeyEvent event,int policyFlags){
  if (!mSystemBooted) {
    return 0;
  }
  final boolean interactive=(policyFlags & FLAG_INTERACTIVE) != 0;
  final boolean down=event.getAction() == KeyEvent.ACTION_DOWN;
  final boolean canceled=event.isCanceled();
  final int keyCode=event.getKeyCode();
  final boolean isInjected=(policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
  final boolean keyguardActive=(mKeyguardDelegate == null ? false : (interactive ? mKeyguardDelegate.isShowingAndNotHidden() : mKeyguardDelegate.isShowing()));
  if (keyCode == KeyEvent.KEYCODE_POWER || keyCode == KeyEvent.KEYCODE_SLEEP || keyCode == KeyEvent.KEYCODE_WAKEUP) {
    policyFlags|=WindowManagerPolicy.FLAG_WAKE;
  }
  if (DEBUG_INPUT) {
    Log.d(TAG,"String_Node_Str" + keyCode + "String_Node_Str"+ interactive+ "String_Node_Str"+ keyguardActive+ "String_Node_Str"+ Integer.toHexString(policyFlags));
  }
  int result;
  boolean isWakeKey=(policyFlags & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
  if (interactive || (isInjected && !isWakeKey)) {
    result=ACTION_PASS_TO_USER;
  }
 else {
    result=0;
    if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
      isWakeKey=false;
    }
  }
  if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode,event)) {
    return result;
  }
  boolean useHapticFeedback=down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 && event.getRepeatCount() == 0;
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_MUTE:
{
      if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (down) {
          if (interactive && !mVolumeDownKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
            mVolumeDownKeyTriggered=true;
            mVolumeDownKeyTime=event.getDownTime();
            mVolumeDownKeyConsumedByScreenshotChord=false;
            cancelPendingPowerKeyAction();
            interceptScreenshotChord();
          }
        }
 else {
          mVolumeDownKeyTriggered=false;
          cancelPendingScreenshotChordAction();
        }
      }
 else       if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (down) {
          if (interactive && !mVolumeUpKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
            mVolumeUpKeyTriggered=true;
            cancelPendingPowerKeyAction();
            cancelPendingScreenshotChordAction();
          }
        }
 else {
          mVolumeUpKeyTriggered=false;
          cancelPendingScreenshotChordAction();
        }
      }
      if (down) {
        ITelephony telephonyService=getTelephonyService();
        if (telephonyService != null) {
          try {
            if (telephonyService.isRinging()) {
              Log.i(TAG,"String_Node_Str" + "String_Node_Str");
              telephonyService.silenceRinger();
              result&=~ACTION_PASS_TO_USER;
              break;
            }
            if (telephonyService.isOffhook() && (result & ACTION_PASS_TO_USER) == 0) {
              handleVolumeKey(AudioManager.STREAM_VOICE_CALL,keyCode);
              break;
            }
          }
 catch (          RemoteException ex) {
            Log.w(TAG,"String_Node_Str",ex);
          }
        }
        if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
          handleVolumeKey(AudioManager.STREAM_MUSIC,keyCode);
          break;
        }
      }
      break;
    }
case KeyEvent.KEYCODE_ENDCALL:
{
    result&=~ACTION_PASS_TO_USER;
    if (down) {
      ITelephony telephonyService=getTelephonyService();
      boolean hungUp=false;
      if (telephonyService != null) {
        try {
          hungUp=telephonyService.endCall();
        }
 catch (        RemoteException ex) {
          Log.w(TAG,"String_Node_Str",ex);
        }
      }
      interceptPowerKeyDown(!interactive || hungUp);
    }
 else {
      if (interceptPowerKeyUp(canceled)) {
        if ((mEndcallBehavior & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
          if (goHome()) {
            break;
          }
        }
        if ((mEndcallBehavior & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
          mPowerManager.goToSleep(event.getEventTime());
          isWakeKey=false;
        }
      }
    }
    break;
  }
case KeyEvent.KEYCODE_POWER:
{
  result&=~ACTION_PASS_TO_USER;
  if (down) {
    mImmersiveModeConfirmation.onPowerKeyDown(interactive,event.getDownTime(),isImmersiveMode(mLastSystemUiFlags));
    if (interactive && !mPowerKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
      mPowerKeyTriggered=true;
      mPowerKeyTime=event.getDownTime();
      interceptScreenshotChord();
    }
    ITelephony telephonyService=getTelephonyService();
    boolean hungUp=false;
    if (telephonyService != null) {
      try {
        if (telephonyService.isRinging()) {
          telephonyService.silenceRinger();
        }
 else         if ((mIncallPowerBehavior & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 && telephonyService.isOffhook() && interactive) {
          hungUp=telephonyService.endCall();
        }
      }
 catch (      RemoteException ex) {
        Log.w(TAG,"String_Node_Str",ex);
      }
    }
    interceptPowerKeyDown(!interactive || hungUp || mVolumeDownKeyTriggered|| mVolumeUpKeyTriggered);
  }
 else {
    mPowerKeyTriggered=false;
    cancelPendingScreenshotChordAction();
    if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
      powerShortPress(event.getEventTime());
      isWakeKey=false;
    }
    mPendingPowerKeyUpCanceled=false;
  }
  break;
}
case KeyEvent.KEYCODE_SLEEP:
{
result&=~ACTION_PASS_TO_USER;
if (!mPowerManager.isInteractive()) {
  useHapticFeedback=false;
}
mPowerManager.goToSleep(event.getEventTime());
isWakeKey=false;
break;
}
case KeyEvent.KEYCODE_WAKEUP:
{
result&=~ACTION_PASS_TO_USER;
break;
}
case KeyEvent.KEYCODE_MEDIA_PLAY:
case KeyEvent.KEYCODE_MEDIA_PAUSE:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if (down) {
ITelephony telephonyService=getTelephonyService();
if (telephonyService != null) {
try {
if (!telephonyService.isIdle()) {
  break;
}
}
 catch (RemoteException ex) {
Log.w(TAG,"String_Node_Str",ex);
}
}
}
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MUTE:
case KeyEvent.KEYCODE_MEDIA_STOP:
case KeyEvent.KEYCODE_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
case KeyEvent.KEYCODE_MEDIA_REWIND:
case KeyEvent.KEYCODE_MEDIA_RECORD:
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
{
if ((result & ACTION_PASS_TO_USER) == 0) {
mBroadcastWakeLock.acquire();
Message msg=mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,new KeyEvent(event));
msg.setAsynchronous(true);
msg.sendToTarget();
}
break;
}
case KeyEvent.KEYCODE_CALL:
{
if (down) {
ITelephony telephonyService=getTelephonyService();
if (telephonyService != null) {
try {
if (telephonyService.isRinging()) {
Log.i(TAG,"String_Node_Str" + "String_Node_Str");
telephonyService.answerRingingCall();
result&=~ACTION_PASS_TO_USER;
}
}
 catch (RemoteException ex) {
Log.w(TAG,"String_Node_Str",ex);
}
}
}
break;
}
}
if (useHapticFeedback) {
performHapticFeedbackLw(null,HapticFeedbackConstants.VIRTUAL_KEY,false);
}
if (isWakeKey) {
mPowerManager.wakeUp(event.getEventTime());
}
return result;
}