if (mgr.isDeviceSecure()) { device.setImageResource(R.drawable.ic_lock_black_24dp);
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mgr=(KeyguardManager)getSystemService(KEYGUARD_SERVICE); ImageView device=findViewById(R.id.device); ImageView keyguard=findViewById(R.id.keyguard); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M) { if (mgr.isDeviceSecure()) { device.setImageResource(R.drawable.ic_lock_black_24dp); } else { device.setImageResource(R.drawable.ic_lock_open_black_24dp); } } else { device.setImageResource(R.drawable.ic_help_black_24dp); } if (mgr.isKeyguardSecure()) { keyguard.setImageResource(R.drawable.ic_lock_black_24dp); } else { keyguard.setImageResource(R.drawable.ic_lock_open_black_24dp); } }
@Test @Config(minSdk = M) public void isDeviceSecureByUserId() { assertThat(manager.isDeviceSecure(USER_ID)).isFalse(); ShadowKeyguardManager shadowMgr = shadowOf(manager); shadowMgr.setIsDeviceSecure(USER_ID, true); assertThat(manager.isDeviceSecure(USER_ID)).isTrue(); assertThat(manager.isDeviceSecure(USER_ID + 1)).isFalse(); shadowMgr.setIsDeviceSecure(USER_ID, false); assertThat(manager.isDeviceSecure(USER_ID)).isFalse(); }
@Test @Config(minSdk = M) public void isDeviceSecure() { assertThat(manager.isDeviceSecure()).isFalse(); ShadowKeyguardManager shadowMgr = shadowOf(manager); shadowMgr.setIsDeviceSecure(true); assertThat(manager.isDeviceSecure()).isTrue(); }
/** * Tells if the {@link FingerprintManager#isHardwareDetected()}, {@link FingerprintManager#hasEnrolledFingerprints()}, * and {@link KeyguardManager#isDeviceSecure()} * * @return true if yes, false otherwise * @throws SecurityException If the hardware is not available, or the permission are not set */ public boolean isFingerprintAuthAvailable() throws SecurityException { return mFingerprintManager.isHardwareDetected() && mFingerprintManager.hasEnrolledFingerprints() && ((KeyguardManager) mIcon.getContext().getSystemService(Context.KEYGUARD_SERVICE)).isDeviceSecure(); }
public static boolean isDeviceSecured(Context context) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { KeyguardManager manager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); return manager.isDeviceSecure(); } // reflection code from the other answers here ... }
/** * @return true if pass or pin or pattern loacks screen */ @TargetApi(23) private boolean isDeviceLocked() { try { KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); //api 23+ return keyguardManager.isDeviceSecure(); } catch (Exception ex) { FlyveLog.e(this.getClass().getName() + ", isDeviceLocked", ex.getMessage()); return false; } } }
return !keyguardMgr.isDeviceSecure();
break; case 1: // lock screen if (!keyguardManager.isDeviceSecure()) { Toast.makeText(this, R.string.no_screen_lock, Toast.LENGTH_LONG).show();
final boolean userProfileSecure = keyguard.isDeviceSecure(); if (userProfileSecure && !keyguard.isKeyguardSecure()) { throw new GeneralSecurityException("keyguard state inconsistent");
if (mFingerprintManagerCompat.isHardwareDetected() && mFingerprintManagerCompat.hasEnrolledFingerprints() && getSystemService(KeyguardManager.class).isDeviceSecure()) { loadFingerprint();