查看文件
frameworks/base/packages/SettingsProvider/res/values/defaults.xml
可以找到R.integer.def_screen_off_timeout的定义。
<integer name="def_screen_off_timeout">60000</integer>
发现默认值为60000ms,也就是60s。我们只需要把这个参数改为-1。然后重新编译SettingsProvider模块,就OK了。
另外为了防止用户进入系统后,修改锁屏时间,在Setting模块中删除对锁屏时间的设置。这样Android设备就永不锁屏了。
锁屏的代码在LockScreen.java中,可以设置锁屏功能开关的位置。代码位于:frameworks/policies/base/phone/com/android/internal/policy/impl/KeyguardViewMediator.java
该文件中有一个变量定义如下:
/**
* External apps (like the phone app) can tell us to disable the keygaurd.
*/
private boolean mExternallyEnabled = true;
mExternallyEnabled是用来管理是否开启屏幕锁的关键。默认值是打开屏锁,根据注释可以知道他是希望应用程序来修改这个值。但是经过加打印信息发现开机的时候没有任何应用程序会修改它。修改这个值调用如下函数:
/**
* Same semantics as {@link WindowManagerPolicy#enableKeyguard}; provide
* a way for external stuff to override normal keyguard behavior. For instance
* the phone app disables the keyguard when it receives incoming calls.
*/
public void setKeyguardEnabled(boolean enabled) {
synchronized (this) {
if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
mExternallyEnabled = enabled;
if (!enabled && mShowing) {
if (mExitSecureCallback != null) {
if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
// we're in the process of handling a request to verify the user
// can get past the keyguard. ignore extraneous requests to disable / reenable
return;
}
// hiding keyguard that is showing, remember to reshow later
if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "+ "disabling status bar expansion");
mNeedToReshowWhenReenabled = true;
hideLocked();
} else if (enabled && mNeedToReshowWhenReenabled) {
// reenabled after previously hidden, reshow
if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "+ "status bar expansion");
mNeedToReshowWhenReenabled = false;
if (mExitSecureCallback != null) {
if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
mExitSecureCallback.onKeyguardExitResult(false);
mExitSecureCallback = null;
resetStateLocked();
} else {
showLocked();
// block until we know the keygaurd is done drawing (and post a message
// to unblock us after a timeout so we don't risk blocking too long
// and causing an ANR).
mWaitingUntilKeyguardVisible = true;
mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING,KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
while (mWaitingUntilKeyguardVisible) {
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
}
}
}
}
经过上面的讨论我们可以发现我们有两个解决方法:
1、定义变量的时候,给其初始化为false。
2、在launcher模块启动的时候,调用setKeyguardEnabled方法,关闭锁屏功能。