Buggy code:
final int keyCode = event . getKeyCode ( ) ; final boolean isInjected = ( policyFlags & ( WindowManagerPolicy . FLAG_INJECTED ) ) != 0 ; final boolean keyguardActive = ( ( mKeyguardDelegate ) == null ) ? false : interactive ? isKeyguardShowingAndNotOccluded ( ) : mKeyguardDelegate . isShowing ( ) ; if ( PhoneWindowManager . DEBUG_INPUT ) { Log . d ( PhoneWindowManager . TAG , ( ( ( ( ( ( ( "interceptKeyTq<seq2seq4repair_space>keycode=" + keyCode ) + "<seq2seq4repair_space>interactive=" ) + interactive ) + "<seq2seq4repair_space>keyguardActive=" ) + keyguardActive ) + "<seq2seq4repair_space>policyFlags=" ) + ( Integer . toHexString ( policyFlags ) ) ) ) ; } int result ; boolean isWakeKey = ( ( policyFlags & ( WindowManagerPolicy . FLAG_WAKE ) ) != 0 ) || ( event . isWakeKey ( ) ) ; if ( interactive || ( isInjected && ( ! isWakeKey ) ) ) { result = ACTION_PASS_TO_USER ; isWakeKey = false ; } else if ( ( ! interactive ) && ( shouldDispatchInputWhenNonInteractive ( ) ) ) { result = ACTION_PASS_TO_USER ; } else { result = 0 ; if ( isWakeKey && ( ( ! down ) || ( ! ( isWakeKeyWhenScreenOff ( keyCode ) ) ) ) ) { isWakeKey = false ; } } if ( ( PhoneWindowManager . isValidGlobalKey ( keyCode ) ) && ( mGlobalKeyManager . shouldHandleGlobalKey ( keyCode , event ) ) ) { if ( isWakeKey ) { wakeUp ( event . getEventTime ( ) , mAllowTheaterModeWakeFromKey ) ; } 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 && ( ! ( mScreenshotChordVolumeDownKeyTriggered ) ) ) && ( ( ( event . getFlags ( ) ) & ( KeyEvent . FLAG_FALLBACK ) ) == 0 ) ) { mScreenshotChordVolumeDownKeyTriggered = true ; mScreenshotChordVolumeDownKeyTime = event . getDownTime ( ) ; mScreenshotChordVolumeDownKeyConsumed = false ; cancelPendingPowerKeyAction ( ) ; interceptScreenshotChord ( ) ; } } else { mScreenshotChordVolumeDownKeyTriggered = false ; cancelPendingScreenshotChordAction ( ) ; } } else if ( keyCode == ( KeyEvent . KEYCODE_VOLUME_UP ) ) { if ( down ) { if ( ( interactive && ( ! ( mScreenshotChordVolumeUpKeyTriggered ) ) ) && ( ( ( event . getFlags ( ) ) & ( KeyEvent . FLAG_FALLBACK ) ) == 0 ) ) { mScreenshotChordVolumeUpKeyTriggered = true ; cancelPendingPowerKeyAction ( ) ; cancelPendingScreenshotChordAction ( ) ; } } else { mScreenshotChordVolumeUpKeyTriggered = false ; cancelPendingScreenshotChordAction ( ) ; } } if ( down ) { TelecomManager telecomManager = getTelecommService ( ) ; if ( telecomManager != null ) { if ( telecomManager . isRinging ( ) ) { Log . i ( PhoneWindowManager . TAG , ( "interceptKeyBeforeQueueing:" + "<seq2seq4repair_space>VOLUME<seq2seq4repair_space>key-down<seq2seq4repair_space>while<seq2seq4repair_space>ringing:<seq2seq4repair_space>Silence<seq2seq4repair_space>ringer!" ) ) ; telecomManager . silenceRinger ( ) ; result &= ~ ( ACTION_PASS_TO_USER ) ; break ; } if ( ( telecomManager . isInCall ( ) ) && ( ( result & ( ACTION_PASS_TO_USER ) ) == 0 ) ) { MediaSessionLegacyHelper . getHelper ( mContext ) . sendVolumeKeyEvent ( event , false ) ; break ; } } } if ( ( isMusicActive ( ) ) && ( ( result & ( ACTION_PASS_TO_USER ) ) == 0 ) ) { if ( ( ( mVolumeMusicControls ) && down ) && ( keyCode != ( KeyEvent . KEYCODE_VOLUME_MUTE ) ) ) { mIsLongPress = false ; int newKeyCode = ( ( event . getKeyCode ( ) ) == ( KeyEvent . KEYCODE_VOLUME_UP ) ) ? KeyEvent . KEYCODE_MEDIA_NEXT : KeyEvent . KEYCODE_MEDIA_PREVIOUS ; Message msg = mHandler . obtainMessage ( PhoneWindowManager . MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK , new KeyEvent ( event . getDownTime ( ) , event . getEventTime ( ) , event . getAction ( ) , newKeyCode , 0 ) ) ; msg . setAsynchronous ( true ) ; mHandler . sendMessageDelayed ( msg , ViewConfiguration . getLongPressTimeout ( ) ) ; break ; } else { if ( ( mVolumeMusicControls ) && ( ! down ) ) { mHandler . removeMessages ( PhoneWindowManager . MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK ) ; if ( mIsLongPress ) { break ; } } <START_BUG> if ( ( ! ( isScreenOn ( ) ) ) && ( ! ( mVolumeRockerWake ) ) ) { <END_BUG> MediaSessionLegacyHelper . getHelper ( mContext ) . sendVolumeKeyEvent ( KeyEvent . changeAction ( event , ACTION_DOWN ) , true ) ; } } } break ; } case KeyEvent . KEYCODE_ENDCALL : { result &= ~ ( ACTION_PASS_TO_USER ) ; if ( down ) { TelecomManager telecomManager = getTelecommService ( ) ; boolean hungUp = false ; if ( telecomManager != null ) { hungUp = telecomManager . endCall ( ) ; } if ( interactive && ( ! hungUp ) ) { mEndCallKeyHandled = false ; mHandler . postDelayed ( mEndCallLongPress , ViewConfiguration . get ( mContext ) . getDeviceGlobalActionKeyTimeout ( ) ) ; } else { mEndCallKeyHandled = true ; } } else { if ( ! ( mEndCallKeyHandled ) ) { mHandler . removeCallbacks ( mEndCallLongPress ) ; if ( ! canceled ) { if ( ( ( mEndcallBehavior ) & ( System . END_BUTTON_BEHAVIOR_HOME ) ) != 0 ) { if ( goHome ( ) ) { break ; } } if ( ( ( mEndcallBehavior ) & ( System . END_BUTTON_BEHAVIOR_SLEEP ) ) != 0 ) { mPowerManager . goToSleep ( event . getEventTime ( ) , GO_TO_SLEEP_REASON_POWER_BUTTON , 0 ) ; isWakeKey = false ; } } } } break ; } case KeyEvent . KEYCODE_POWER : { result &= ~ ( ACTION_PASS_TO_USER ) ; isWakeKey = false ; if ( down ) { interceptPowerKeyDown ( event , interactive ) ;

Fix:
if ( ! isWakeKey ) {