Android changes source code control and never locks the screen

Source: Internet
Author: User
Tags tty mode

Screen locking is very necessary for mobile terminals, but it is not necessary for set-top box products. This article describes how to keep the Android device locked.
The lock time of the Android system is stored in the setting database, and the field is settings. system. screen_off_timeout. View the settingsprovider source code and the source code of the following file:
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 ();
}
From the code, we can see that if settings. system. if screen_off_timeout is not initialized (This field is certainly not initialized when the system is started for the first time), the R in the resource will be used. integer. def_screen_off_timeout to initialize. To keep the system locked, set 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 60000 ms, that is, 60 s. We only need to change this parameter to-1. Then re-compile the settingsprovider module.
In addition, to prevent users from entering the system and modify the lock time, delete the lock time setting in the setting module. In this way, the Android device will never be locked.
Later, I found that my Android device will never lock the screen after it is started for the first time. However, after the device is restarted, it enters the lock status and will no longer lock the screen after it is unlocked (because it never times out ). It seems that "The revolution has not yet succeeded, and comrades still need to work hard.
Why is the screen lock status not displayed after startup? Does the system modify the timeout lock value? I used sqlite3 to view the settings. DB content and found that the value of the timeout lock screen is still-1. It indicates that after the screen is started, the system does not go to the database to view the screen timeout lock value, and the screen is locked directly.
But how can I not go into the screen lock status after the instance is turned on? This is a very troublesome question. After going through go, I know that the lock screen code is in lockscreen. java. Then I found the location where I can set the lock screen function. The code is located:
Frameworks/policies/base/phone/COM/Android/Internal/policy/impl/keyguardviewmediator. Java
The file contains a variable 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 to enable screen lock. The default value is to open the screen lock. According to the comment, you can know that you want the application to modify this value. However, after printing information, it is found that no application will modify it at startup. To modify this value, 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 has es incoming CILS.
*/
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, "previusly 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 ");
}
}
}
}
After the above discussion, we can find that we have two solutions:
1. initialize a variable to false.
2. When the launcher module is started, call the setkeyguardenabled method to disable the screen lock function.
I am too lazy to modify the laucher module. My solution is to change the initial value to false when defining mexternallyenabled. You can select a solution based on your 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 screen lock status will not be displayed after the Android device is started, unless you call the setkeyguardenabled method in the application to enable this function. Because the set timeout value is-1, the screen lock page is never displayed. I have completely met my needs and I have finally achieved success. Happy ~!!

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.