Set lockscreen to “None” programmatically?

后端 未结 7 490
挽巷
挽巷 2020-12-30 04:12

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 applicatio

相关标签:
7条回答
  • 2020-12-30 04:32

    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


    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
    
    0 讨论(0)
  • 2020-12-30 04:41

    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.

    0 讨论(0)
  • 2020-12-30 04:42

    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

    0 讨论(0)
  • 2020-12-30 04:42

    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.

    0 讨论(0)
  • 2020-12-30 04:44

    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().

    0 讨论(0)
  • 2020-12-30 04:47

    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);

    0 讨论(0)
提交回复
热议问题