Guest User

Untitled

a guest
Jan 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import android.app.KeyguardManager;
  2. import android.content.ContentResolver;
  3. import android.content.Context;
  4. import android.provider.Settings;
  5. import android.util.Log;
  6.  
  7.  
  8. public class LockTest {
  9.  
  10. public static boolean doesDeviceHaveSecuritySetup(Context context)
  11. {
  12. return isPatternSet(context) || isPassOrPinSet(context);
  13. }
  14.  
  15. /**
  16. * @param context
  17. * @return true if pattern set, false if not (or if an issue when checking)
  18. */
  19. public static boolean isPatternSet(Context context)
  20. {
  21. ContentResolver cr = context.getContentResolver();
  22. try
  23. {
  24. int lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED);
  25. return lockPatternEnable == 1;
  26. }
  27. catch (Exception e)
  28. {
  29. Log.e("==========",e.getMessage());
  30. return false;
  31. }
  32. }
  33.  
  34. /**
  35. * @param context
  36. * @return true if pass or pin set
  37. */
  38. public static boolean isPassOrPinSet(Context context)
  39. {
  40. KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); //api 16+
  41. return keyguardManager.isKeyguardSecure();
  42. }
  43.  
  44. }
Add Comment
Please, Sign In to add comment