Android system cancels automatic lock screen

Source: Internet
Author: User
Tags stmt tty mode

Locking the screen is necessary for mobile terminals, but it is not necessary for set-top box products.     So this article describes how to make Android devices never lock the screen. The lock screen time of the Android system is stored in the setting database and is Settings.System.SCREEN_OFF_TIMEOUT. View Settingsprovider source code, view the following file source:
Frameworks/base/packages/settingsprovider/src/com/android/providers/settings/databasehelper.java
The code for viewing the Loadsystemsettings () function is as follows: private void loadsystemsettings (Sqlitedatabase db) {
Sqlitestatement stmt = db.compilestatement ("INSERT OR IGNORE into system (Name,value)"
+ "VALUES (?,?);");

Resources R = Mcontext.getresources ();

Loadbooleansetting (stmt, Settings.System.DIM_SCREEN,
R.bool.def_dim_screen);
Loadsetting (stmt, Settings.System.STAY_ON_WHILE_PLUGGED_IN,
"1". Equals (Systemproperties.get ("Ro.kernel.qemu"))? 1:0);
Loadintegersetting (stmt, Settings.System.SCREEN_OFF_TIMEOUT,
R.integer.def_screen_off_timeout);

Set Default CDMA emergency tone
Loadsetting (stmt, Settings.System.EMERGENCY_TONE, 0);

Set Default CDMA Call Auto Retry
Loadsetting (stmt, Settings.System.CALL_AUTO_RETRY, 0);

Set Default CDMA DTMF type
Loadsetting (stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);

Set Default Hearing aid
Loadsetting (stmt, Settings.System.HEARING_AID, 0);

Set Default TTY Mode
Loadsetting (stmt, Settings.System.TTY_MODE, 0);

Loadbooleansetting (stmt, Settings.System.AIRPLANE_MODE_ON,
R.BOOL.DEF_AIRPLANE_MODE_ON);

Loadstringsetting (stmt, Settings.System.AIRPLANE_MODE_RADIOS,
R.string.def_airplane_mode_radios);

Loadstringsetting (stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
R.string.airplane_mode_toggleable_radios);

Loadbooleansetting (stmt, Settings.System.AUTO_TIME,
R.bool.def_auto_time); Sync Time to Nitz

Loadintegersetting (stmt, Settings.System.SCREEN_BRIGHTNESS,
r.integer.def_screen_brightness);

Loadbooleansetting (stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
R.bool.def_screen_brightness_automatic_mode);

Loaddefaultanimationsettings (stmt);

Loadbooleansetting (stmt, Settings.System.ACCELEROMETER_ROTATION,
R.bool.def_accelerometer_rotation);

Loaddefaulthapticsettings (stmt);

Stmt.close ();
Copy code from the code we can see that if Settings.System.SCREEN_OFF_TIMEOUT is not initialized (the first time the system starts, the field is definitely not initialized), it will take advantage of the r.integer.def_screen in the resource _off_timeout to initialize. In order for the system to never lock the screen, we need to set the resource r.integer.def_screen_off_timeout to 1. View Files
Frameworks/base/packages/settingsprovider/res/values/defaults.xml
You can find the definition of r.integer.def_screen_off_timeout.
<integer name= "Def_screen_off_timeout" >60000</integer>
The default value is 60000ms, that is, 60s. We just need to change this parameter to-1. Then recompile the Settingsprovider module and it's OK.
In addition, in order to prevent users from entering the system, modify the lock screen time, in the setting module to remove the lock screen time settings. This way, Android devices will never lock the screen.
It turned out that my Android device would never lock the screen for the first time after it was burned, but when the device was rebooted, it went into the lock-screen state, and after unlocking it would never lock the screen again (because it never timed out).     It seems that "the revolution has not yet succeeded, comrades still need to work hard" ah. So why did not go into the lock after the start of the screen state. is not the system has the Timeout lock screen value to modify it. I checked the contents of the settings.db through sqlite3 and found that the value of the Timeout lock screen was still-1. After the boot, the system does not go to the database to see the screen Timeout lock screen value, directly lock the screen.
But how to boot after the lock screen state does not go. This is a very thoughtless question. After go, I know that the code of the lock screen is in the Lockscreen.java, and then the track, finally found the position that can set the lock screen function switch. The code is located at:
Frameworks/policies/base/phone/com/android/internal/policy/impl/keyguardviewmediator.java
One of the variables in the file is defined as follows:
/**
* External apps (like the phone app) can tell us to disable the Keygaurd.
*/
Private Boolean mexternallyenabled = true;
Mexternallyenabled is the key to managing whether a screen lock is turned on. The default value is to open the screen lock, and according to the annotation you know that he wants the application to modify this value. However, after printing the information found that no application will modify it. Modify this value to call the following function:/**
* 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 are 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 are done drawing (and post a message
To unblock us on 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");
}
}
}
Copy code after the discussion above we can see that we have two solutions:

1. When defining a variable, initialize it to false.
2, when the Launcher module starts, calls the Setkeyguardenabled method, turns off the lock screen function.

I'm too lazy to modify the Laucher module, and my solution is to modify its initial value to False when defining mexternallyenabled. Friends can choose the solution according to their own actual situation. My code is as follows:
/**
* External apps (like the phone app) can tell us to disable the Keygaurd.
*/
Private Boolean mexternallyenabled = false;
After this modification, the Android device will not go into the lock screen until it is turned on, unless you call the Setkeyguardenabled method display in the application to open the feature. Because the timeout is 1, it will never go into the lock screen interface. Completely satisfied with my needs, and finally it's done.


Http://www.devdiv.com/Android-android system cancels automatic lock screen-thread-84556-1-1.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.