今天做了一个需求
手机需要做Back键和Home键不让唤醒屏幕
代码如下
KeyEvent.java(frameworks\base\core\java\android\view)
/** @hide */
public static final boolean isWakeKey(int keyCode) {
switch (keyCode) {
//chc hide back and menu wake
// case KeyEvent.KEYCODE_BACK:
case KeyEvent.KEYCODE_POWER:
// case KeyEvent.KEYCODE_MENU:
case KeyEvent.KEYCODE_SLEEP:
case KeyEvent.KEYCODE_WAKEUP:
case KeyEvent.KEYCODE_PAIRING:
case KeyEvent.KEYCODE_PTT:
return true;
}
return false;
}
PhoneWindowsManager.java
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:
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 false 就是不允许亮屏
}
return true;
}
此方法是所有可以唤醒屏幕的按键
在此方法将对应的按键去掉的就行。
相反 如果需要某个按键需要唤醒屏幕, 在这两个方法添加到return true 就行了,并且确保驱动已经添加了按键的唤醒源,否则无法在深度待机下唤醒