ROM默认不锁屏,不黑屏,删除设置中休眠时间选项参考Android 6.0.1,其他安卓版本原理差不多
1.Settings 删掉屏幕待机选项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
- 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.禁止锁屏
源码流程:
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,则永不锁屏