Buggy code:
boolean isWakeKey = ( ( ( policyFlags & ( WindowManagerPolicy . FLAG_WAKE ) ) != 0 ) || ( event . isWakeKey ( ) ) ) || isVolumeWakeKey ; 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 ( mGlobalKeyManager . shouldHandleGlobalKey ( keyCode , event ) ) { if ( isWakeKey ) { mPowerManager . wakeUp ( event . getEventTime ( ) ) ; } return result ; } boolean useHapticFeedback = ( down && ( ( policyFlags & ( WindowManagerPolicy . FLAG_VIRTUAL ) ) != 0 ) ) && ( ( event . getRepeatCount ( ) ) == 0 ) ; if ( ( mDeviceKeyHandler ) != null ) { try { if ( mDeviceKeyHandler . handleKeyEvent ( event ) ) { return 0 ; } } catch ( Exception e ) { Slog . w ( PhoneWindowManager . TAG , "Could<seq2seq4repair_space>not<seq2seq4repair_space>dispatch<seq2seq4repair_space>event<seq2seq4repair_space>to<seq2seq4repair_space>device<seq2seq4repair_space>key<seq2seq4repair_space>handler" , e ) ; } } 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 ; mVolumeUpKeyTime = event . getDownTime ( ) ; mVolumeUpKeyConsumedByScreenshotChord = false ; cancelPendingPowerKeyAction ( ) ; interceptScreenshotLog ( ) ; } } else { mVolumeUpKeyTriggered = 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 ( ) ) ) && ( ! ( mVolumeWakeScreen ) ) ) { <END_BUG> MediaSessionLegacyHelper . getHelper ( mContext ) . sendVolumeKeyEvent ( KeyEvent . changeAction ( event , ACTION_DOWN ) , true ) ; } } } break ; } case KeyEvent . KEYCODE_HOME : if ( ( down && ( ! interactive ) ) && ( mHomeWakeScreen ) ) { isWakeKey = 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 ( ) ; } interceptPowerKeyDown ( ( ( ! interactive ) || hungUp ) ) ; } else { if ( interceptPowerKeyUp ( 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 ) ; if ( down ) { if ( ( interactive && ( ! ( mPowerKeyTriggered ) ) ) && ( ( ( event . getFlags ( ) ) & ( KeyEvent . FLAG_FALLBACK ) ) == 0 ) ) { mPowerKeyTriggered = true ; mPowerKeyTime = event . getDownTime ( ) ; interceptScreenshotChord ( ) ; interceptScreenshotLog ( ) ; } TelecomManager telecomManager = getTelecommService ( ) ;

Fix:
if ( ! isWakeKey ) {