I want to check whether the device screen lock is enabled or not and I am using the standard API provided by Android SDK as shown below. But I am receiving
D/StrictMode: StrictMode policy violation; ~duration=127 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=4259847 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1449)
Here is the code I tried.
val km = requireContext().getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager?
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//Returns whether the device is secured with a PIN, pattern or password.
km?.isDeviceSecure ?: false
} else {
//Return whether the keyguard is secured by a PIN, pattern or password or a SIM card is currently locked.
km?.isKeyguardSecure ?: false
}
I set up strict mode as shown below on my Application class
private fun enableStrictMode() {
StrictMode.setThreadPolicy(
Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build()
)
}
As this is a standard API provided by the Android SDK, why this happen? Anyway, this is just the case of Strictmode and if I disable the strict mode, there will not be any warning on the LogCat.
Am I doing something wrong?