在进行android系统开发的时候,有些特定的情况需要设置系统永不锁屏,永不休眠。本篇文章给大家介绍android 永不锁屏,开机不锁屏,删除设置中休眠时间选项,需要的朋友一起学习吧。
android 6.0.1
create:2016-02-29
1.settings 删掉屏幕待机选项
1
2
3
4
5
6
7
8
9
|
packages/apps/settings/res/xml/display_settings.xml
<!-- hide screen sleep
<listpreference
android:key= "screen_timeout"
android:title= "@string/screen_timeout"
android:summary= "@string/screen_timeout_summary"
android:persistent= "false"
android:entries= "@array/screen_timeout_entries"
android:entryvalues= "@array/screen_timeout_values" /> -->
|
注释掉这个listpreference
packages/apps/settings/src/com/android/settings/displaysettings.java
添加if条件,如果没有找到这个preference就不执行相关操作;具体可以参考被隐藏的 night_mode
1
2
3
4
5
6
7
8
9
|
mscreentimeoutpreference = (listpreference) findpreference(key_screen_timeout);
if (mscreentimeoutpreference != null ) {
final long currenttimeout = settings.system.getlong(resolver, screen_off_timeout,
fallback_screen_timeout_value);
mscreentimeoutpreference.setvalue(string.valueof(currenttimeout));
mscreentimeoutpreference.setonpreferencechangelistener( this );
disableunusabletimeouts(mscreentimeoutpreference);
updatetimeoutpreferencedescription(currenttimeout);
}
|
2.禁止锁屏
1
2
3
4
|
frameworks/base/packages/settingsprovider/res/values/defaults.xml
<bool name= "def_lockscreen_disabled" > false </bool> 改为 true ;即默认禁止锁屏
frameworks/base/core/res/res/values/config.xml
<integer name= "config_multiusermaximumusers" > 1 </integer> 不允许多用户;即最大用户数为 1
|
分别编译frameworks/base/packages/settingsprovider 与 frameworks/base
编译后push 到 system/priv-app/settingsprovider/settingsprovider.apk system/framework/framework.jar
删去机器中对应的oat目录。重启或恢复出厂设置。第一次开机时,会先出现status bar,launcher要等一会才出来。
之后重启就可以直接进入launcher。机器会默认不锁屏。但还是会进入sleep状态。
源码流程:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
frameworks/base/packages/settingsprovider/src/com/android/providers/settings/databasehelper.java
if (upgradeversion == 54 ) // 版本为54才会设置timeout
......
private void upgradescreentimeoutfromnever(sqlitedatabase db) {
// see if the timeout is -1 (for "never").
cursor c = db.query(table_system, new string[] { "_id" , "value" }, "name=? and value=?" ,
new string[] { settings.system.screen_off_timeout, "-1" },
null , null , null );
sqlitestatement stmt = null ;
if (c.getcount() > 0 ) {
c.close();
try {
stmt = db.compilestatement( "insert or replace into system(name,value)"
+ " values(?,?);" );
// set the timeout to 30 minutes in milliseconds
loadsetting(stmt, settings.system.screen_off_timeout,
integer.tostring( 30 * 60 * 1000 ));
} finally {
if (stmt != null ) stmt.close();
}
} else {
c.close();
}
}
......
if (systemproperties.getboolean( "ro.lockscreen.disable.default" , false ) == true ) {
loadsetting(stmt, settings.system.lockscreen_disabled, "1" );
} else {
loadbooleansetting(stmt, settings.system.lockscreen_disabled,
r.bool.def_lockscreen_disabled);
}
|
timeout若是-1,则永不锁屏
读取"ro.lockscreen.disable.default",如果默认为true,则设置禁止锁屏;否则从xml中读配置
1
2
3
|
frameworks/base/packages/settingsprovider/res/values/defaults.xml
<integer name= "def_screen_off_timeout" > 60000 </integer>
<bool name= "def_lockscreen_disabled" > false </bool>`
|
禁止锁屏默认为false
以上内容是小编给大家介绍的设置android系统永不锁屏永不休眠的方法,希望对大家有所帮助。