首页 > 其他分享 >Home key点亮屏幕后, 使手机不自动回到 launcher 界面

Home key点亮屏幕后, 使手机不自动回到 launcher 界面

时间:2023-03-11 15:06:51浏览次数:34  
标签:key launcher KEYCODE oldScreenOn result && Home keyCode

1: 修改 phonewindowmanager.java 中 interceptKeyBeforeQueueing 方法的下面这段 code:
if (keyCode == KeyEvent.KEYCODE_POWER) {
policyFlags |= WindowManagerPolicy.FLAG_WAKE;
}
改为:
if (keyCode == KeyEvent.KEYCODE_POWER || (keyCode == KeyEvent.KEYCODE_HOME && !isScreenOn)) {
policyFlags |= WindowManagerPolicy.FLAG_WAKE;
}


2: 仍然是此方法,对应部分修改为如下:
int result; //参考行

if (((isScreenOn && !mHeadless) || (isInjected && !isWakeKey))) {//参考行
// When the screen is on or if the key is injected pass the key to the application.
Log.d(TAG,"oldScreenOn = "+oldScreenOn);
if(!oldScreenOn && (keyCode == KeyEvent.KEYCODE_HOME)){
Log.d(TAG,"eat the home up because home down has dropped");
result |= ACTION_WAKE_UP;
}else{
result = ACTION_PASS_TO_USER;
}
} else {
// When the screen is off and the key is not injected, determine whether
// to wake the device but don't pass the key to the application.
result = 0;
if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
if (keyguardActive) {
// If the keyguard is showing, let it wake the device when ready.
mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
} else {
// Otherwise, wake the device ourselves.
result |= ACTION_WAKE_UP;
}
}
}

oldScreenOn = isScreenOn;




其中的 oldScreenOn 请定义在 phoneWindowManager 这个 class 中, 如下:
boolean oldScreenOn = true;

标签:key,launcher,KEYCODE,oldScreenOn,result,&&,Home,keyCode
From: https://blog.51cto.com/u_15170706/6114560

相关文章