Set lockscreen to "None" programmatically?
Asked Answered
G

9

18

I have the requirement to disable the lock screen and set the lock screen type to "None". My device is rooted (can run with SU permission) + can run as a system application with system permissions (under /system/app).

I have tried a few things to no avail.

Try 1

This seems to be deprecated and not working.

KeyguardManager manager = (KeyguardManager) this.getSystemService(KEYGUARD_SERVICE);
KeyguardLock lock = manager.newKeyguardLock("abc");
lock.disableKeyguard(); 

Try 2

This didn't work either.

  1. Mount system partition as writable
  2. Edit /data/data/com.android.providers.settings/databases/settings.db
  3. Execute the following SQL.

    INSERT OR REPLACE INTO system (name, value) VALUES ('lockscreen.disabled', '1');
    INSERT OR REPLACE INTO secure (name, value) VALUES ('lockscreen.disabled', '1');

Try 3

Rebooted the machine but still no luck.

android.provider.Settings.Secure.putLong(mContentResolver, Settings.Secure.LOCK_PATTERN_ENABLED, false);`
android.provider.Settings.Secure.putLong(mContentResolver, "lockscreen.password_type", DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);`
android.provider.Settings.Secure.putLong(mContentResolver, "lockscreen.password_type_alternate", DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
android.provider.Settings.Secure.putLong(mContentResolver, "lockscreen.disabled", true);

Is there anything else that I can try?

Please note that I do not want to disable the keyguard only when application is running.

Glass answered 3/3, 2014 at 9:28 Comment(5)
Which android version?Pop
I am running on Android 4.1Glass
#9724928 - hope this helpsJahncke
I would like to hear from your progress. Any solution so far?Pop
@RanhiruCooray reached anything ?Informality
S
15

You can try this:

adb shell sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '1' WHERE name = 'lockscreen.disabled'"

adb shell sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '0' WHERE name = 'lockscreen.password_type'"

adb shell sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '0' WHERE name = 'lockscreen.password_type_alternate'"

It works on my rooted Nexus 4.

Saum answered 5/6, 2014 at 4:47 Comment(5)
Running the 1st command and then rebooting the phone worked for me.Derose
Related source code: github.com/android/platform_frameworks_base/blob/…Chiccory
For /data/data/com.android.providers.settings/databases/settings.db it is said that it's best to use adb shell settings put secure lockscreen.disabled 1 to modify the database. Is there a similar utility to modify locksettings.db instead of direct sqlite call?Affer
@Affer One can adb pull those files, as detailed here.Ninanincompoop
This can be done easier with locksettings command: adb shell locksettings set-disabled trueLimy
P
4

After searching a little bit in the android source i stick now within a function called onPreferenceTreeClick from the class ChooseLockGeneric which seems to be called when the unlock method is chosen (in the preferences).

In that method updateUnlockMethodAndFinish is called which sets the unlock method. So maybe calling updateUnlockMethodAndFinish(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,true); could be exactly what you want.

I don't know whether this fit your needs and don't know whether this works (maybe there are any visibility problems or security mechanisms). I am just speculating.

EDIT: This could help also: startFragment(this,"com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment",SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);

Pop answered 3/3, 2014 at 11:19 Comment(0)
S
3

use adb shell locksettings clear --old xxxx to instantly remove the lockscreen lock (even when the phone is in locked state) xxxx is the pattern number, refer below image. Example: locksettings clear --old 1236

To again set the pattern use: locksettings set-pattern 1236

enter image description here


usage:

   locksettings set-pattern [--old OLD_CREDENTIAL] NEW_PATTERN
   locksettings set-pin [--old OLD_CREDENTIAL] NEW_PIN
   locksettings set-password [--old OLD_CREDENTIAL] NEW_PASSWORD
   locksettings clear [--old OLD_CREDENTIAL]
   locksettings verify [--old OLD_CREDENTIAL]
   locksettings set-disabled DISABLED
   locksettings get-disabled
Sedentary answered 1/10, 2018 at 15:12 Comment(0)
H
3

I know this is a late answer, but you can try command line "locksettings set-disabled true".
It works perfectly for me.

Human answered 10/5, 2021 at 6:17 Comment(0)
M
2

you have to declare this uses-permission on AndroidManifest:

<uses-permission android:name="android.permission.WAKE_LOCK" />

And in your code:

PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Lock");
wakeLock.acquire();

when your application is destroyed or paused to release this lock using below:

wakeLock.release();

I suggested to call the acquire inside the onResume() of your activity and the release in onPause().

Mcclary answered 3/3, 2014 at 10:5 Comment(1)
Thanks but this is ONLY when the application is running. This doesn't disable the lock screen of the device.Glass
T
2

I tried modifying /data/system/locksettings.db as was suggested by @ByteHamster, with no luck.

adb shell sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '1' WHERE name = 'lockscreen.disabled'"

I then renamed the locksettings.db to locksettings.db.old and rebooted. The lockscreen was gone and Android rebuilt the locksettings.db file itself.

I am using TWRP recovery on a Samsung Galaxy S4.

Tracery answered 24/10, 2015 at 16:40 Comment(2)
adb shell settings put secure lockscreen.disabled 1Absquatulate
Does this require a rooted device or anything?Edson
T
1

I would like to explore exilit answer. From the source, we finally get into this:

mChooseLockSettingsHelper.utils().clearLock(false);
mChooseLockSettingsHelper.utils().setLockScreenDisabled(disabled);

The utils is the com.android.internal.widget.LockPatternUtils object and we can somehow get it by reflection. Here is the code:

    try{
            Class lockPatternUtilsCls = Class.forName("com.android.internal.widget.LockPatternUtils");
            Constructor lockPatternUtilsConstructor = 
                lockPatternUtilsCls.getConstructor(new Class[]{Context.class});
            Object lockPatternUtils = lockPatternUtilsConstructor.newInstance(MyActivity.this);

            Method clearLockMethod = lockPatternUtils.getClass().getMethod("clearLock", boolean.class);
            Method setLockScreenDisabledMethod = lockPatternUtils.getClass().getMethod("setLockScreenDisabled", boolean.class);

            clearLockMethod.invoke(lockPatternUtils, false);
            setLockScreenDisabledMethod.invoke(lockPatternUtils, true);                 
            Log.d(TAG, "set lock screen to NONE SUC");
    }catch(Exception e){
            Log.e(TAG, "set lock screen to NONE failed", e);
    }

Well my testing app is with signed with platform key and a system app. I think it will be a must.

Updated: Noticed that the methods arguments are changed on Android 6.

Tilley answered 6/10, 2015 at 5:57 Comment(0)
H
1

I have acheived in root tablet,

Below is my full procedure

adb push sqlite3 /sdcard/sqlite3

adb shell

su

mount -o remount,rw /system

cp /sdcard/sqlite3 /system/xbin/sqlite3

chmod 755 /system/xbin/sqlite3

mount -o remount,ro /system

adb shell sqlite3 /data/system/locksettings.db

UPDATE locksettings SET value = '1' WHERE name = 'lockscreen.disabled'

You can download the file from http://www.digitechhub.com/sqlite3

Hynes answered 27/5, 2016 at 5:36 Comment(0)
A
0

On rooted nexus 5, In terminal via twrp recovery I simply rm /data/system/locksettings.db and reboot

Anticlimax answered 12/2, 2022 at 12:36 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Edy

© 2022 - 2024 — McMap. All rights reserved.