Set lockscreen to “None” programmatically?

99封情书 提交于 2019-11-30 06:48:55
superb

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.

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

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.

Solution

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

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

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!