Enable or disable PatternLock screen from code

I tried to find a way to temporarily turn off the PatternLock screen. I do not want the lock to be completely disabled, but the user does not need to re-enter his template all the time.

My idea is to write a service that disables the template after some user actions and reactivates it after some time. (and even more)

There are applications on the market that do something like this (i.e. AutoLock or TogglePattern), so there should be a solution.

I know that I can completely lock the lock using:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) 

or

 KeyguardLock.disableKeyguard() 

But that is not what I need.

I saw the class com.android.internal.widget.LockPatternUtils in android sources, which is used by the settings activity, but this class is not (at least as far as I know) an accessible "normal" application.

Do you have any suggestions?

+4
source share
2 answers

Have you tried looking at the code for com.android.internal.widget.LockPatternUtils and doing what it does?

This one has something like this:

 public void setLockPatternEnabled(boolean enabled) { setBoolean(android.provider.Settings.System.LOCK_PATTERN_ENABLED, enabled); } private void setBoolean(String systemSettingKey, boolean enabled) { android.provider.Settings.System.putInt( mContentResolver, systemSettingKey, enabled ? 1 : 0); } 

You might be able to do something similar in your code.

+3
source

Starting with version 2.0 (API level 5), you can use this window flag to prevent the lock screen from showing while your window is displayed:

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SHOW_WHEN_LOCKED

You can also use this flag to prohibit insecure key lock when your window is displayed:

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_DISMISS_KEYGUARD

Please note that this does not allow you to bypass the lock screen outside of your application environment, which is an intentional design decision.

There is also an older API that allows you to hide the lock screen in the same way as tracking lock:

http://developer.android.com/reference/android/app/KeyguardManager.html#newKeyguardLock(java.lang.String)

Using this API is not recommended on new platforms because it is very easy to make mistakes and cause bad behavior (the screen does not lock when the user expected this), and in principle it is impossible to have clean transitions between actions with an unlocked state. For example, this is the API that was originally used to hide the lock screen when it was displayed, but from 2.0 it switched to the new cleanup window flags. Similarly for an alarm, etc.

+4
source

Source: https://habr.com/ru/post/1300181/


All Articles