@TargetApi(JELLY_BEAN) public KeyguardManagerAssert hasLockedKeyguard() { isNotNull(); assertThat(actual.isKeyguardLocked()) // .overridingErrorMessage("Expected locked keyguard but was unlocked.") // .isTrue(); return this; }
@TargetApi(JELLY_BEAN) public KeyguardManagerAssert hasUnlockedKeyguard() { isNotNull(); assertThat(actual.isKeyguardLocked()) // .overridingErrorMessage("Expected unlocked keyguard but was locked.") // .isFalse(); return this; }
@Test public void testIsKeyguardLocked() { assertThat(manager.isKeyguardLocked()).isFalse(); ShadowKeyguardManager shadowMgr = shadowOf(manager); shadowMgr.setKeyguardLocked(true); assertThat(manager.isKeyguardLocked()).isTrue(); }
/** * 判断是否锁屏 * * @return */ @TargetApi(16) public boolean isKeyguardLocked() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { return false; } else { return keyguardManager.isKeyguardLocked(); } }
@TargetApi(JELLY_BEAN) public KeyguardManagerAssert hasLockedKeyguard() { isNotNull(); assertThat(actual.isKeyguardLocked()) // .overridingErrorMessage("Expected locked keyguard but was unlocked.") // .isTrue(); return this; }
@TargetApi(JELLY_BEAN) public KeyguardManagerAssert hasUnlockedKeyguard() { isNotNull(); assertThat(actual.isKeyguardLocked()) // .overridingErrorMessage("Expected unlocked keyguard but was locked.") // .isFalse(); return this; }
@Override public void onReceive(Context context, Intent intent) { KeyguardManager kgm = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { TapAndTurnApplication.log(Log.INFO, "BroadcastReceiver", "screen off"); if (isActive) { physicalOrientationSensor.disable(); orientationButtonOverlay.hide(); if (TapAndTurnApplication.settings.getBoolean(SettingsKeys.RESTORE_DEFAULT_ON_SCREEN_OFF, true)) screenRotatorOverlay.forceOrientation(WindowManagerSensor.queryDefaultOrientation(windowManager, getResources().getConfiguration())); } } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON) && !kgm.isKeyguardLocked() || intent.getAction().equals(Intent.ACTION_USER_PRESENT)) { TapAndTurnApplication.log(Log.INFO, "BroadcastReceiver", "screen on or user present"); if (isActive) { physicalOrientationSensor.enable(); } } } };
@Override protected void apply(MutableStatusBarNotification evolving) { MutableNotification notification = evolving.getNotification(); Bundle extras = notification.extras; boolean recast = extras.getBoolean(NOTIFICATION_EXTRA_RECAST, false); NotificationUtils.Messages messages = NotificationUtils.parseMessages(notification); String[] captchas = mCaptchaUtils.findSmsCaptchas(messages.texts); if (captchas.length == 0) return; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) notification.setChannelId(recast ? NOTIFICATION_CHANNEL_CAPTCHA_SILENT : NOTIFICATION_CHANNEL_CAPTCHA_NORMAL); else notification.priority = recast ? Notification.PRIORITY_LOW : Notification.PRIORITY_HIGH; KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); if (mSettings.isCaptchaHideOnLocked() && keyguardManager != null && keyguardManager.isKeyguardLocked()) applyKeyguardLocked(notification, evolving.getKey(), messages, captchas); else applyKeyguardUnlocked(notification, evolving.getKey(), messages, captchas); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; notification.visibility = Notification.VISIBILITY_PUBLIC; extras.putBoolean(Global.NOTIFICATION_EXTRA_APPLIED, true); mAppliedKeys.add(evolving.getKey()); Log.i(TAG, "Applied " + evolving.getKey()); }