Last active
October 30, 2017 23:50
-
-
Save yakivmospan/57e9358cf8dad6ddca789133e4cbf089 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val keyguardManager: KeyguardManager | |
init { | |
keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager | |
} | |
fun isDeviceSecure(): Boolean = if (hasMarshmallow()) keyguardManager.isDeviceSecure else keyguardManager.isKeyguardSecure | |
// Used to block application if no lock screen is setup. | |
fun showDeviceSecurityAlert(): AlertDialog { | |
return AlertDialog.Builder(context) | |
.setTitle(R.string.lock_title) | |
.setMessage(R.string.lock_body) | |
.setPositiveButton(R.string.lock_settings, { _, _ -> context.openLockScreenSettings() }) | |
.setNegativeButton(R.string.lock_exit, { _, _ -> System.exit(0) }) | |
.setCancelable(BuildConfig.DEBUG) | |
.show() | |
} | |
fun hasMarshmallow() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment