SoFunction
Updated on 2025-03-11

How to set the Android system to never lock the screen and never sleep

When developing Android system, some specific situations require setting the system to never lock the screen and never sleep. This article introduces you to Android that never locks the screen, does not lock the screen when it is turned on, and deletes the sleep time option in the settings. If you need it, let’s learn together.

Android 6.0.1
Create:2016-02-29

Delete the screen standby option

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" /> --> 

Comment out this ListPreference

packages/apps/Settings/src/com/android/settings/

Add if condition, if this preference is not found, no related operations will be performed; for details, please refer to the hidden night_mode

mScreenTimeoutPreference = (ListPreference) findPreference(KEY_SCREEN_TIMEOUT);
if (mScreenTimeoutPreference !=null ) {
final long currentTimeout = (resolver, SCREEN_OFF_TIMEOUT,
FALLBACK_SCREEN_TIMEOUT_VALUE);
((currentTimeout));
(this);
disableUnusableTimeouts(mScreenTimeoutPreference);
updateTimeoutPreferenceDescription(currentTimeout);
}

2. No lock screen

frameworks/base/packages/SettingsProvider/res/values/
&lt;bool name="def_lockscreen_disabled"&gt;false&lt;/bool&gt; Change to true;That is, the default screen lock is prohibited
frameworks/base/core/res/res/values/
&lt;integer name="config_multiuserMaximumUsers"&gt;1&lt;/integer&gt; Multiple users are not allowed;That is, the maximum number of users is1

Compile frameworks/base/packages/SettingsProvider and frameworks/base respectively

After compilation, push to system/priv-app/SettingsProvider/ system/framework/

Delete the corresponding oat directory in the machine. Restart or restore factory settings. When the computer is turned on for the first time, the status bar will appear first, and the launcher will have to wait for a while before it comes out.

After that, you can directly enter the launcher. The machine will not lock the screen by default. But it will still enter sleep state.

Source code process:

frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/
if (upgradeVersion == 54)// Timeout will be set only if version 54......
private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) {
// See if the timeout is -1 (for "Never").
Cursor c = (TABLE_SYSTEM, new String[] { "_id", "value" }, "name=? AND value=?",
new String[] { .SCREEN_OFF_TIMEOUT, "-1" },
null, null, null);
SQLiteStatement stmt = null;
if (() &gt; 0) {
();
try {
stmt = ("INSERT OR REPLACE INTO system(name,value)"
+ " VALUES(?,?);");
// Set the timeout to 30 minutes in milliseconds
loadSetting(stmt, .SCREEN_OFF_TIMEOUT,
(30 * 60 * 1000));
} finally {
if (stmt != null) ();
}
} else {
();
}
}
......
if (("", false) == true) {
loadSetting(stmt, .LOCKSCREEN_DISABLED, "1");
} else {
loadBooleanSetting(stmt, .LOCKSCREEN_DISABLED,
.def_lockscreen_disabled);
}

If timeout is -1, the screen will never be locked.

Read "", if the default is true, set to prohibit the lock screen; otherwise read the configuration from the XML

frameworks/base/packages/SettingsProvider/res/values/
<integer name="def_screen_off_timeout">60000</integer>
<bool name="def_lockscreen_disabled">false</bool>` 

The default lock screen is false

The above content is the method of setting up the Android system to never lock the screen and never sleep. I hope it will be helpful to everyone.