Android 物理按键在屏幕灭的时候会唤醒手机修改

时间:2021-12-30 14:33:57

关于物理按键

在android手机系统开发过程中发现,物理按键HOME,BACK,MENU,会在手机屏灭的时候唤醒手机

关于手机按键唤醒屏的源码在PhoneWindowManager.java中

具体的修改方案:

    /**
* When the screen is off we ignore some keys that might otherwise typically
* be considered wake keys. We filter them out here.
*
* {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
* is always considered a wake key.
*/
private boolean isWakeKeyWhenScreenOff(int keyCode) {
switch (keyCode) {
// ignore volume keys unless docked
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_MUTE:
/*SUN:jicong.wang add for ignore home back menu key*/
case KeyEvent.KEYCODE_HOME:
case KeyEvent.KEYCODE_BACK:
case KeyEvent.KEYCODE_MENU:
/*SUN:jicong.wang add for ignor home back menu key*/
return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;

// ignore media and camera keys
case KeyEvent.KEYCODE_MUTE:
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_PLAY:
case KeyEvent.KEYCODE_MEDIA_PAUSE:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
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:
case KeyEvent.KEYCODE_CAMERA:
return false;
}
return true;
}