Android 4.4.源码 如何屏蔽Home键
2016-06-03 19:19
429 查看
做了一个锁屏app替换系统的app ,但是在应用层是无法屏蔽home键的,找了资料,改了源码,终于解决
代码位置
frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java下的
定位到名为interceptKeyBeforeDispatching 的函数
从函数名我们可以知道此函数是是在分发按键消息之前进行拦截。
查看对KEYCODE_HOME home键的处理
// First we always handle the home key here, so applications
// can never break it, although if keyguard is on, we do let
// it handle it, because that gives us the correct 5 second
// timeout.
if (keyCode == KeyEvent.KEYCODE_HOME) {
// If we have released the home key, and didn't do anything else
// while it was pressed, then it is time to go home!
if (!down) {
cancelPreloadRecentApps();
mHomePressed = false;
if (mHomeConsumed) {
mHomeConsumed = false;
return -1;
}
if (canceled) {
Log.i(TAG, "Ignoring HOME; event canceled.");
return -1;
}
// If an incoming call is ringing, HOME is totally disabled.
// (The user is already on the InCallScreen at this point,
// and his ONLY options are to answer or reject the call.)
try {
ITelephony telephonyService = getTelephonyService();
if (telephonyService != null && telephonyService.isRinging()) {
Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
return -1;
}
} catch (RemoteException ex) {
Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
}
// Delay handling home if a double-tap is possible.
if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
mHomeDoubleTapPending = true;
mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
ViewConfiguration.getDoubleTapTimeout());
return -1;
}
// Go home! wdh add 我在此处屏蔽系统的launcher并且return 0,原来是return -1,改为return 0 交由上层app处理home键
//launchHomeFromHotKey();
return 0;
上层app处理:重写onKeyDown屏蔽home 和back
/**
*
* 屏蔽掉返回键
*
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode==KeyEvent.KEYCODE_BACK || keyCode==KeyEvent.KEYCODE_HOME){
return true;
}else {
return super.onKeyDown(keyCode, event);
}
}
参考文章:http://www.cnblogs.com/sphere/archive/2014/12/02/4137814.html
参考文章:http://blog.csdn.net/fulinwsuafcie/article/details/7717408
代码位置
frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java下的
定位到名为interceptKeyBeforeDispatching 的函数
从函数名我们可以知道此函数是是在分发按键消息之前进行拦截。
查看对KEYCODE_HOME home键的处理
// First we always handle the home key here, so applications
// can never break it, although if keyguard is on, we do let
// it handle it, because that gives us the correct 5 second
// timeout.
if (keyCode == KeyEvent.KEYCODE_HOME) {
// If we have released the home key, and didn't do anything else
// while it was pressed, then it is time to go home!
if (!down) {
cancelPreloadRecentApps();
mHomePressed = false;
if (mHomeConsumed) {
mHomeConsumed = false;
return -1;
}
if (canceled) {
Log.i(TAG, "Ignoring HOME; event canceled.");
return -1;
}
// If an incoming call is ringing, HOME is totally disabled.
// (The user is already on the InCallScreen at this point,
// and his ONLY options are to answer or reject the call.)
try {
ITelephony telephonyService = getTelephonyService();
if (telephonyService != null && telephonyService.isRinging()) {
Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
return -1;
}
} catch (RemoteException ex) {
Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
}
// Delay handling home if a double-tap is possible.
if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
mHomeDoubleTapPending = true;
mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
ViewConfiguration.getDoubleTapTimeout());
return -1;
}
// Go home! wdh add 我在此处屏蔽系统的launcher并且return 0,原来是return -1,改为return 0 交由上层app处理home键
//launchHomeFromHotKey();
return 0;
上层app处理:重写onKeyDown屏蔽home 和back
/**
*
* 屏蔽掉返回键
*
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode==KeyEvent.KEYCODE_BACK || keyCode==KeyEvent.KEYCODE_HOME){
return true;
}else {
return super.onKeyDown(keyCode, event);
}
}
参考文章:http://www.cnblogs.com/sphere/archive/2014/12/02/4137814.html
参考文章:http://blog.csdn.net/fulinwsuafcie/article/details/7717408
相关文章推荐
- Android 沉浸式状态栏的实现
- make ls and chmod command on android device
- 第一章:选择开发工具
- [Android]无限循环ViewPager
- [Android5.1]ActivityManagerService启动过程分析
- android的LruCache
- 【原创】如何用Android Studio断点安卓自带Service或Bind类型的Service
- Android Studio --自动删除没有用的资源,给APK减减肥和GSON、RX、EventBus混淆注意
- Android自定义对话框(Dialog)位置,大小
- Android Material Design之CoordinatorLayout全面使用介绍
- Android仿外卖购物车的实现
- android studio 修改project的路径
- Android之查看签名的命令和SharedPreferences以及ContentProvider使用
- android学习之路-使用Intent跳转
- Android AsyncTask源码解析
- Android 发布开源项目到jcenter
- Android高级图片滚动控件,编写3D版的图片轮播器
- make my android ps command on NDK
- System.exit(0)和 System.exit(1)的区别
- Android EditText 文本长度限制(按照一个汉字占俩长度 类似字节)