最近做的项目要求开机就不锁屏,而且还永远不休眠,哇哦..这直接就可以通过设置改就是了嘛.多简单的事.
什么?这项目没有屏幕,哇哦..改代码吧.
1:禁止锁屏需要更改的代码路径如下:/frameworks/base/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java 贴上相关部分代码。代码位 于 842行左右
/**
* Enable the keyguard if the settings are appropriate.
*/
private void doKeyguardLocked(Bundle options) {
// if another app is disabling us, don't show
if (!mExternallyEnabled) { //让此行永远为true就可以了,这样改后锁屏就不可用了。
if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
// note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
// for an occasional ugly flicker in this situation:
// 1) receive a call with the screen on (no keyguard) or make a call
// 2) screen times out
// 3) user hits key to turn screen back on
// instead, we reenable the keyguard when we know the screen is off and the call
// ends (see the broadcast receiver below)
// TODO: clean this up when we have better support at the window manager level
// for apps that wish to be on top of the keyguard
return;
}
// if the keyguard is already showing, don't bother
if (mKeyguardViewManager.isShowing()) {
if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
return;
}
...........................
More code here
...........................
}//end of the
3:让系统永不休眠的方法还有修改默认值的方法,修改frameworks/base/packages/SettingsProvider/res/values/defaults.xml文件里的def_screen_off_timeout的值为-1
然后在services/java/com/android/server/power/PowerManagerService.java 文件里的 private int getScreenOffTimeoutLocked() 函数里添加如下代码.
int DonotSleeptimeout;
DonotSleeptimeout = mScreenOffTimeoutSetting;
if(DonotSleeptimeout < 0)
{
DonotSleeptimeout = mMaximumScreenOffTimeoutFromDeviceAdmin ;
return Math.max(DonotSleeptimeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
}
在Aandroid 4.2系统下测试ok..