android - check whether lock was enabled or not -


i have check whether system lock enabled or not in settings.

i used below line code

boolean b = android.provider.settings.system.getint(                         getcontentresolver(),settings.system.lock_pattern_enabled, 0)==1; 

it returns true if set pattern lock , false if set pin/password password.

i need check whether lock enabled or not either pattern/pin/password lock in settings.

my code works pattern lock not pin/password lock.

so please tell me how check type of locks.

so question pretty old seems there no answer yet. after source code (from ramakrishna's link) research , self experiments i'm wrote simple class job.

public class locktype {     private final static string password_type_key = "lockscreen.password_type";      /**      * constant means android using unlock method not described here.      * possible new methods added in future releases.      */     public final static int something_else = 0;      /**      * android using "none" or "slide" unlock method. seems there no way determine method used.      * in both cases you'll "password_quality_something" , "lock_pattern_enabled" == 0.      */     public final static int none_or_slider = 1;      /**      * android using "face unlock" "pattern" additional unlock method. android don't allow select      * "face unlock" without additional unlock method.      */     public final static int face_with_pattern = 3;      /**      * android using "face unlock" "pin" additional unlock method. android don't allow select      * "face unlock" without additional unlock method.      */     public final static int face_with_pin = 4;      /**      * android using "face unlock" additional unlock method not described here.      * possible new methods added in future releases. values 5 8 reserved situation.      */     public final static int face_with_something_else = 9;      /**      * android using "pattern" unlock method.      */     public final static int pattern = 10;      /**      * android using "pin" unlock method.      */     public final static int pin = 11;      /**      * android using "password" unlock method password containing letters.      */     public final static int password_alphabetic = 12;      /**      * android using "password" unlock method password containing both letters , numbers.      */     public final static int password_alphanumeric = 13;      /**      * returns current unlock method integer value. can see possible values above      * @param contentresolver need pass contentresolver settings.secure.getlong(...) ,      *                        settings.secure.getint(...)      * @return current unlock method integer value      */     public static int getcurrent(contentresolver contentresolver)     {         long mode = android.provider.settings.secure.getlong(contentresolver, password_type_key,                 devicepolicymanager.password_quality_something);         if (mode == devicepolicymanager.password_quality_something)         {             if (android.provider.settings.secure.getint(contentresolver, settings.secure.lock_pattern_enabled, 0) == 1)             {                 return locktype.pattern;             }             else return locktype.none_or_slider;         }         else if (mode == devicepolicymanager.password_quality_biometric_weak)         {             string datadirpath = environment.getdatadirectory().getabsolutepath();             if (nonemptyfileexists(datadirpath + "/system/gesture.key"))             {                 return locktype.face_with_pattern;             }             else if (nonemptyfileexists(datadirpath + "/system/password.key"))             {                 return locktype.face_with_pin;             }             else return face_with_something_else;         }         else if (mode == devicepolicymanager.password_quality_alphanumeric)         {             return locktype.password_alphanumeric;         }         else if (mode == devicepolicymanager.password_quality_alphabetic)         {             return locktype.password_alphabetic;         }         else if (mode == devicepolicymanager.password_quality_numeric)         {             return locktype.pin;         }         else return locktype.something_else;     }      private static boolean nonemptyfileexists(string filename)     {         file file = new file(filename);         return file.exists() && file.length() > 0;     } } 

now need do

int locktype = locktype.getcurrent(getcontentresolver()); 

from activity class. if want check set of lock types use switch statement

switch (locktype)  {     case locktype.face_with_pattern:     case locktype.face_with_pin:     case locktype.pattern:         /* */         break; } 

or if want "face unlock" no matter additional method

if (locktype >= locktype.face_with_pattern && locktype <= locktype.face_with_something_else) {     /* */ } 

edit: so, i'm test class on 3 phones , seems not phones correctly detect face unlock method. on phones password_quality_biometric_weak returns , password_quality_something on anothers. think can check file contains info face unlock exists , not empty, similar password/pin , pattern methods. don't know file is.

edit2: looks found problem after android 4.3 sorce code research. that's because lock settings moved new location (/data/system/locksettings.db) , seems there no way setting database (rw-rw---- permissions , "system" owner , group root can job).


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -