KeyguardManager myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); if( myKM.inKeyguardRestrictedInputMode()) { //it is locked } else { //it is not locked }
@TargetApi(JELLY_BEAN) public KeyguardManagerAssert hasSecureKeyguard() { isNotNull(); assertThat(actual.isKeyguardSecure()) // .overridingErrorMessage("Expected secure keyguard but was insecure.") // .isTrue(); return this; }
private void init() { mKeyguardLock = ((KeyguardManager) getTargetContext().getSystemService(Context.KEYGUARD_SERVICE)) .newKeyguardLock("CardIOTest"); mKeyguardLock.disableKeyguard(); }
@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); } }
kl = km.newKeyguardLock(getPackageName()); kl.disableKeyguard(); if (km.inKeyguardRestrictedInputMode()) { registerReceiver(mUserPresentReceiver, userPresent); } else {
private void deviceCheck() { if (Build.VERSION.SDK_INT >= 21) { if ((G.isDoKey(context) || isDonate())) { KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); if (keyguardManager.isKeyguardSecure()) { Intent createConfirmDeviceCredentialIntent = keyguardManager.createConfirmDeviceCredentialIntent(null, null); if (createConfirmDeviceCredentialIntent != null) { try { activity.startActivityForResult(createConfirmDeviceCredentialIntent, LOCK_VERIFICATION); } catch (ActivityNotFoundException e) { } } } else { Toast.makeText(activity, context.getText(R.string.android_version), Toast.LENGTH_SHORT).show(); } } else { Api.donateDialog(activity, true); } } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void authenticate() { Intent i=mgr.createConfirmDeviceCredentialIntent("title", "description"); if (i==null) { Toast.makeText(this, "No authentication required!", Toast.LENGTH_SHORT).show(); } else { startActivityForResult(i, REQUEST_CODE); } } }
@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(); }
@TargetApi(JELLY_BEAN) public KeyguardManagerAssert hasUnlockedKeyguard() { isNotNull(); assertThat(actual.isKeyguardLocked()) // .overridingErrorMessage("Expected unlocked keyguard but was locked.") // .isFalse(); return this; }
KeyguardManager kgm = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); boolean isKeyguardUp = kgm.inKeyguardRestrictedInputMode(); KeyguardLock kgl = kgm.newKeyguardLock("Your Activity/Service name"); if(isKeyguardUp){ kgl.disableKeyguard(); isKeyguardUp = false; } wl.acquire(); //use your wake lock once keyguard is down.
if (mgr.isDeviceSecure()) { device.setImageResource(R.drawable.ic_lock_black_24dp); if (mgr.isKeyguardSecure()) { keyguard.setImageResource(R.drawable.ic_lock_black_24dp);
public void deviceCheck() { if (Build.VERSION.SDK_INT >= 21) { if ((G.isDoKey(getApplicationContext()) || isDonate())) { KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); if (keyguardManager.isKeyguardSecure()) { Intent createConfirmDeviceCredentialIntent = keyguardManager.createConfirmDeviceCredentialIntent(null, null); if (createConfirmDeviceCredentialIntent != null) { try { startActivityForResult(createConfirmDeviceCredentialIntent, LOCK_VERIFICATION); } catch (ActivityNotFoundException e) { } } } else { Toast.makeText(this, getText(R.string.android_version), Toast.LENGTH_SHORT).show(); } } else { Api.donateDialog(MainActivity.this, true); } } }
private void requestAuth(int requestCode) { Intent i= mgr.createConfirmDeviceCredentialIntent("title", "description"); if (i==null) { Toast.makeText(this, "No authentication required?!?", Toast.LENGTH_SHORT).show(); } else { startActivityForResult(i, requestCode); } } }
@Test @Config(minSdk = M) public void isDeviceSecure() { assertThat(manager.isDeviceSecure()).isFalse(); ShadowKeyguardManager shadowMgr = shadowOf(manager); shadowMgr.setIsDeviceSecure(true); assertThat(manager.isDeviceSecure()).isTrue(); }
@TargetApi(JELLY_BEAN) public KeyguardManagerAssert hasLockedKeyguard() { isNotNull(); assertThat(actual.isKeyguardLocked()) // .overridingErrorMessage("Expected locked keyguard but was unlocked.") // .isTrue(); return this; }
KeyguardManager kgMgr = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); boolean showing = kgMgr.inKeyguardRestrictedInputMode();
KeyguardManager kgm = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); boolean isKeyguardUp = kgm.inKeyguardRestrictedInputMode(); KeyguardLock kgl = kgm.newKeyguardLock("Your Activity/Service name"); if(isKeyguardUp){ kgl.disableKeyguard(); isKeyguardUp = false; } wl.acquire(); //use your wake lock once keyguard is down.
@TargetApi(JELLY_BEAN) public KeyguardManagerAssert hasInsecureKeyguard() { isNotNull(); assertThat(actual.isKeyguardSecure()) // .overridingErrorMessage("Expected insecure keyguard but was secure.") // .isFalse(); return this; } }
@Test public void testShouldBeAbleToDisableTheKeyguardLock() throws Exception { KeyguardManager.KeyguardLock lock = manager.newKeyguardLock(KEYGUARD_SERVICE); assertThat(shadowOf(lock).isEnabled()).isTrue(); lock.disableKeyguard(); assertThat(shadowOf(lock).isEnabled()).isFalse(); lock.reenableKeyguard(); assertThat(shadowOf(lock).isEnabled()).isTrue(); }
final boolean userProfileSecure = keyguard.isDeviceSecure(); if (userProfileSecure && !keyguard.isKeyguardSecure()) { throw new GeneralSecurityException("keyguard state inconsistent");