Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if PIN/password/pattern is required to unlock phone?

How can I detect if the phone is locked by a password, pin or pattern?

thank you!

like image 793
Shatazone Avatar asked Oct 24 '11 17:10

Shatazone


People also ask

How can I check my phone unlock pattern?

Reset your pattern (Android 4.4 or lower only) After you've tried to unlock your phone multiple times, you'll see "Forgot pattern." Tap Forgot pattern. Enter the Google Account username and password you previously added to your phone. Reset your screen lock. Learn how to set a screen lock.

How can I unlock my Android if I forgot PIN to verify PIN?

The 'Forgot Pattern' Feature If you've failed to unlock your phone 5 times, you'll have a message pop up. At the bottom right of your screen, you'll see a “Forgot Pattern?” button. Tap it. You can then enter your Google account details and Google will send you through an e-mail with your new unlock code.

How can I unlock my phone if I forgot my pattern and backup PIN?

Tap on Forgot Pattern, and you'll see a prompt to enter your Google account information. Type in your email address and password. You now have the option of resetting your lock screen pattern. Simply tap on the Sign-in tab, then go to the Screen Unlock settings and set a new lock screen pattern.


3 Answers

Two methods

  1. Check programatically - API 16+

https://gist.github.com/doridori/54c32c66ef4f4e34300f

Note that you dont need to check for face unlock as that requires that a pin/pass fallback is set.

  1. Device Admin Policies

Can also look into the Device Admin Policies which allow restrictions on how the app is setup regarding security including pin/pass set restrictions

  • Device Administration
  • Enhancing Security with Device Management Policies

As an aside, these are the lock types you want to check for if using an encrypted Keystore. Check here for more info.

like image 140
Dori Avatar answered Nov 11 '22 00:11

Dori


You can use the Settings.Secure class to query information about the security in place on an android device. For example, to see if the user has a lock pattern enabled you'd do:

ContentResolver cr = getContentResolver();
int lockPatternEnable = 
  Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED);

lockPatternEnable would then have a 0 if it wasn't enabled and a 1 if it was enabled.

like image 27
Kurtis Nusbaum Avatar answered Nov 10 '22 23:11

Kurtis Nusbaum


This should be OK for Android API 16 and up, according to the documentation. I tested it on 19 and it seems to work.

private boolean IsDeviceSecured () {
    KeyguardManager keyguardManager =
            (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); //api 16+
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return keyguardManager.isDeviceSecure();
    }
    return keyguardManager.isKeyguardSecure ();
}
like image 32
VSim Avatar answered Nov 11 '22 00:11

VSim