Java Code Examples for android.app.KeyguardManager#isKeyguardLocked()
The following examples show how to use
android.app.KeyguardManager#isKeyguardLocked() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverlayServiceCommon.java From heads-up with GNU General Public License v3.0 | 7 votes |
private boolean isLocked() { if (preferences.getBoolean("off_as_locked", false)) { initPowerManager(); if (!powerManager.isScreenOn()) { isLocked = true; return isLocked; } } KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); final boolean isKeyguardLocked; if (Build.VERSION.SDK_INT >= 16) isKeyguardLocked = keyguardManager.isKeyguardLocked(); else isKeyguardLocked = keyguardManager.inKeyguardRestrictedInputMode(); Mlog.v(logTag, isKeyguardLocked + " " + LOCKSCREEN_APPS.contains(currentPackage)); isLocked = isKeyguardLocked || (currentPackage != null && LOCKSCREEN_APPS.contains(currentPackage)); return isLocked; }
Example 2
Source File: VolumePanel.java From Noyze with Apache License 2.0 | 7 votes |
/** Start an activity. Returns true if successful. */ @SuppressWarnings("deprecation") protected boolean startActivity(Intent intent) { Context context = getContext(); if (null == context || null == intent) return false; // Disable the Keyguard if necessary. KeyguardManager mKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); if (mKM.isKeyguardLocked() && !mKM.isKeyguardSecure()) { mKeyguardLock = mKM.newKeyguardLock(getName()); mKeyguardLock.disableKeyguard(); } try { // Necessary because we're in a background Service! intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); return true; } } catch (ActivityNotFoundException anfe) { LOGE("VolumePanel", "Error launching Intent: " + intent.toString(), anfe); } catch (SecurityException se) { LOGE("VolumePanel", "Error launching Intent: " + intent.toString(), se); Toast.makeText(context, R.string.permission_error, Toast.LENGTH_SHORT).show(); } return false; }
Example 3
Source File: OverlayServiceCommon.java From heads-up with GNU General Public License v3.0 | 6 votes |
private void dismissKeyguard() { if (Build.VERSION.SDK_INT >= 16) { if (!preferences.getBoolean("dismiss_keyguard", false)) return; KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); if (keyguardManager.isKeyguardLocked()) { Mlog.d(logTag, "attempt exit"); Intent intent = new Intent(); intent.setClass(getApplicationContext(), KeyguardRelock.class); intent.setAction(Intent.ACTION_SCREEN_ON); startService(intent); } } }
Example 4
Source File: CaptchaDecoratorService.java From nevo-decorators-sms-captchas with GNU General Public License v3.0 | 5 votes |
@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()); }
Example 5
Source File: VolumePanel.java From Noyze with Apache License 2.0 | 5 votes |
/** Start an activity. Returns true if successful. */ @SuppressWarnings("deprecation") protected boolean startActivity(Intent intent) { Context context = getContext(); if (null == context || null == intent) return false; // Disable the Keyguard if necessary. KeyguardManager mKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); if (mKM.isKeyguardLocked() && !mKM.isKeyguardSecure()) { mKeyguardLock = mKM.newKeyguardLock(getName()); mKeyguardLock.disableKeyguard(); } try { // Necessary because we're in a background Service! intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); return true; } } catch (ActivityNotFoundException anfe) { LOGE("VolumePanel", "Error launching Intent: " + intent.toString(), anfe); } catch (SecurityException se) { LOGE("VolumePanel", "Error launching Intent: " + intent.toString(), se); Toast.makeText(context, R.string.permission_error, Toast.LENGTH_SHORT).show(); } return false; }
Example 6
Source File: ScreenMonitor.java From talkback with Apache License 2.0 | 4 votes |
/** * Returns whether the device is currently locked. * * @return {@code true} if device is locked. */ public static boolean isDeviceLocked(AccessibilityService service) { KeyguardManager keyguardManager = (KeyguardManager) service.getSystemService(Context.KEYGUARD_SERVICE); return ((keyguardManager != null) && keyguardManager.isKeyguardLocked()); }
Example 7
Source File: EventPreferencesScreen.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
void doHandleEvent(EventsHandler eventsHandler/*, boolean forRestartEvents*/) { if (_enabled) { int oldSensorPassed = getSensorPassed(); if ((Event.isEventPreferenceAllowed(EventPreferencesScreen.PREF_EVENT_SCREEN_ENABLED, eventsHandler.context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED)) { //PPApplication.logE("EventPreferencesScreen.doHandleEvent", "xxx"); //boolean isScreenOn; //PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); boolean keyguardShowing = false; if (_whenUnlocked) { KeyguardManager kgMgr = (KeyguardManager) eventsHandler.context.getSystemService(Context.KEYGUARD_SERVICE); if (kgMgr == null) eventsHandler.notAllowedScreen = true; else keyguardShowing = kgMgr.isKeyguardLocked(); } /*if (PPApplication.logEnabled()) { PPApplication.logE("EventPreferencesScreen.doHandleEvent", "PPApplication.isScreenOn=" + PPApplication.isScreenOn); PPApplication.logE("EventPreferencesScreen.doHandleEvent", "keyguardShowing=" + keyguardShowing); }*/ if (!eventsHandler.notAllowedScreen) { if (_eventType == EventPreferencesScreen.ETYPE_SCREENON) { // event type = screen is on if (_whenUnlocked) // passed if screen is on and unlocked if (PPApplication.isScreenOn) { eventsHandler.screenPassed = !keyguardShowing; } else { eventsHandler.screenPassed = !keyguardShowing; } //screenPassed = PPApplication.isScreenOn && (!keyguardShowing); else eventsHandler.screenPassed = PPApplication.isScreenOn; } else { // event type = screen is off if (_whenUnlocked) { // passed if screen is off and locked eventsHandler.screenPassed = keyguardShowing; //screenPassed = (!PPApplication.isScreenOn) && keyguardShowing; } else eventsHandler.screenPassed = !PPApplication.isScreenOn; } //PPApplication.logE("EventPreferencesScreen.doHandleEvent", "screenPassed="+screenPassed); } if (!eventsHandler.notAllowedScreen) { if (eventsHandler.screenPassed) setSensorPassed(EventPreferences.SENSOR_PASSED_PASSED); else setSensorPassed(EventPreferences.SENSOR_PASSED_NOT_PASSED); } } else eventsHandler.notAllowedScreen = true; int newSensorPassed = getSensorPassed() & (~EventPreferences.SENSOR_PASSED_WAITING); if (oldSensorPassed != newSensorPassed) { //PPApplication.logE("[TEST BATTERY] EventPreferencesScreen.doHandleEvent", "screen - sensor pass changed"); setSensorPassed(newSensorPassed); DatabaseHandler.getInstance(eventsHandler.context).updateEventSensorPassed(_event, DatabaseHandler.ETYPE_SCREEN); } } }
Example 8
Source File: NotificationUtils.java From AcDisplay with GNU General Public License v2.0 | 4 votes |
/** * Return whether the keyguard requires a password to unlock and may * have any privacy restrictions. */ public static boolean isSecure(@NonNull Context context) { KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); return km.isKeyguardSecure() && km.isKeyguardLocked(); }