KeyguardManager mKeyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
if (mKeyguardManager.inKeyguardRestrictedInputMode()) {
// keyguard on
}
if (mKeyguardManager.inKeyguardRestrictedInputMode()) {
// keyguard on
}