Set lockscreen to “None” programmatically?

ⅰ亾dé卋堺 提交于 2019-11-29 06:43:22

问题


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.


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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




回答5:


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



回答6:


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




回答7:


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.



来源:https://stackoverflow.com/questions/22142940/set-lockscreen-to-none-programmatically

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