Set lockscreen to “None” programmatically?

后端 未结 7 494
挽巷
挽巷 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: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.

提交回复
热议问题