我想检查设备屏幕锁定是否已启用,并且我正在使用Android SDK提供的标准API,如下所示。但是我收到
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)
这是我尝试的代码。
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
}
我在Application类上设置了如下所示的严格模式
private fun enableStrictMode() {
StrictMode.setThreadPolicy(
Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build()
)
}
由于这是Android SDK提供的标准API,为什么会发生这种情况?无论如何,这只是Strictmode的情况,如果我禁用严格模式,则LogCat上不会有任何警告。
我做错什么了吗?