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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128

9 Answers9

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.

ByteHamster
  • 4,884
  • 9
  • 38
  • 53
superb
  • 963
  • 1
  • 10
  • 21
  • Running the 1st command and then rebooting the phone worked for me. – Caner Aug 15 '14 at 13:42
  • Related source code: https://github.com/android/platform_frameworks_base/blob/3f453164ec884d26a556477027b430cb22a9b7e3/services/core/java/com/android/server/LockSettingsStorage.java – Zifei Tong Jul 10 '15 at 11:33
  • 2
    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? – farmir Aug 04 '15 at 03:04
  • @farmir One can `adb pull` those files, as detailed [here](https://www.reddit.com/r/Android/comments/1r2zha/how_i_managed_to_use_my_android_device_with_a). – musically_ut Apr 06 '16 at 19:33
  • 1
    This can be done easier with `locksettings` command: `adb shell locksettings set-disabled true` – Ber May 17 '21 at 12:51
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);

exilit
  • 1,156
  • 11
  • 23
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
GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
3

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

MadHatter
  • 301
  • 3
  • 12
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().

林果皞
  • 7,539
  • 3
  • 55
  • 70
Solution
  • 604
  • 4
  • 10
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.

jmatocha
  • 21
  • 4
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.

Yeung
  • 2,202
  • 2
  • 27
  • 50
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

Satheesh
  • 1,252
  • 11
  • 11
0

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

  • 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](/help/how-to-answer). – Community Feb 12 '22 at 13:57