Here are the examples of the java api class android.app.KeyguardManager taken from open source projects.
1. U2020TestRunner#onStart()
Project: u2020
File: U2020TestRunner.java
File: U2020TestRunner.java
@SuppressLint("MissingPermission") @Override public void onStart() { // Inform the app we are an instrumentation test before the object graph is initialized. DebugU2020Module.instrumentationTest = true; Context app = getTargetContext().getApplicationContext(); String name = U2020TestRunner.class.getSimpleName(); // Unlock the device so that the tests can input keystrokes. KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE); keyguard.newKeyguardLock(name).disableKeyguard(); // Wake up the screen. PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE); wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name); wakeLock.acquire(); super.onStart(); }
2. U2020TestRunner#onStart()
Project: sbt-android
File: U2020TestRunner.java
File: U2020TestRunner.java
@Override public void onStart() { // Inform the app we are an instrumentation test before the object graph is initialized. DebugU2020Module.instrumentationTest = true; Context app = getTargetContext().getApplicationContext(); String name = U2020TestRunner.class.getSimpleName(); // Unlock the device so that the tests can input keystrokes. KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE); keyguard.newKeyguardLock(name).disableKeyguard(); // Wake up the screen. PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE); wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name); wakeLock.acquire(); super.onStart(); }
3. RxBindingTestRunner#onStart()
Project: RxBinding
File: RxBindingTestRunner.java
File: RxBindingTestRunner.java
@Override public void onStart() { Context app = getTargetContext().getApplicationContext(); String name = RxBindingTestRunner.class.getSimpleName(); // Unlock the device so that the tests can input keystrokes. KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE); keyguard.newKeyguardLock(name).disableKeyguard(); // Wake up the screen. PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE); wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name); wakeLock.acquire(); super.onStart(); }
4. PaperworkTestRunner#onStart()
Project: paperwork
File: PaperworkTestRunner.java
File: PaperworkTestRunner.java
@Override public void onStart() { Context app = getTargetContext().getApplicationContext(); String name = getClass().getSimpleName(); KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE); keyguard.newKeyguardLock(name).disableKeyguard(); PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE); wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name); wakeLock.acquire(); super.onStart(); }
5. MonitorService#unlockScreen()
Project: luckymoney
File: MonitorService.java
File: MonitorService.java
private void unlockScreen() { KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); final KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("MyKeyguardLock"); keyguardLock.disableKeyguard(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyWakeLock"); wakeLock.acquire(); }
6. CleanContactsRunner#onStart()
Project: Clean-Contacts
File: CleanContactsRunner.java
File: CleanContactsRunner.java
@Override public void onStart() { Context app = getTargetContext().getApplicationContext(); String name = CleanContactsRunner.class.getSimpleName(); // Unlock the device so that the tests can input keystrokes. KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE); keyguard.newKeyguardLock(name).disableKeyguard(); // Wake up the screen. PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE); wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name); wakeLock.acquire(); super.onStart(); }
7. SmoothieApplicationModuleTest#testModule_shouldReturnSystemServices()
Project: toothpick
File: SmoothieApplicationModuleTest.java
File: SmoothieApplicationModuleTest.java
@Test public void testModule_shouldReturnSystemServices() throws Exception { //GIVEN Activity activity = Robolectric.buildActivity(Activity.class).create().get(); Application application = RuntimeEnvironment.application; Scope appScope = Toothpick.openScope(application); appScope.installModules(new SmoothieApplicationModule(application)); //WHEN Application injectedApp = appScope.getInstance(Application.class); LocationManager locationManager = appScope.getInstance(LocationManager.class); WindowManager windowManager = appScope.getInstance(WindowManager.class); ActivityManager activityManager = appScope.getInstance(ActivityManager.class); PowerManager powerManager = appScope.getInstance(PowerManager.class); AlarmManager alarmManager = appScope.getInstance(AlarmManager.class); NotificationManager notificationManager = appScope.getInstance(NotificationManager.class); KeyguardManager keyguardManager = appScope.getInstance(KeyguardManager.class); Vibrator vibrator = appScope.getInstance(Vibrator.class); ConnectivityManager connectivityManager = appScope.getInstance(ConnectivityManager.class); //WifiManager wifiManager = appScope.getInstance(WifiManager.class); InputMethodManager inputMethodManager = appScope.getInstance(InputMethodManager.class); SensorManager sensorManager = appScope.getInstance(SensorManager.class); TelephonyManager telephonyManager = appScope.getInstance(TelephonyManager.class); AudioManager audioManager = appScope.getInstance(AudioManager.class); DownloadManager downloadManager = appScope.getInstance(DownloadManager.class); //THEN assertThat(injectedApp, is(RuntimeEnvironment.application)); assertThat(locationManager, notNullValue()); assertThat(windowManager, notNullValue()); assertThat(activityManager, notNullValue()); assertThat(powerManager, notNullValue()); assertThat(alarmManager, notNullValue()); assertThat(notificationManager, notNullValue()); assertThat(keyguardManager, notNullValue()); assertThat(vibrator, notNullValue()); assertThat(connectivityManager, notNullValue()); //assertThat(wifiManager, notNullValue()); assertThat(inputMethodManager, notNullValue()); assertThat(sensorManager, notNullValue()); assertThat(telephonyManager, notNullValue()); assertThat(audioManager, notNullValue()); assertThat(downloadManager, notNullValue()); }
8. WindowAttachmentTest#setUp()
Project: screenshot-tests-for-android
File: WindowAttachmentTest.java
File: WindowAttachmentTest.java
@Before public void setUp() throws Exception { mContext = InstrumentationRegistry.getTargetContext(); injectInstrumentation(InstrumentationRegistry.getInstrumentation()); super.setUp(); KeyguardManager km = (KeyguardManager) getInstrumentation().getTargetContext().getSystemService(Context.KEYGUARD_SERVICE); mLock = km.newKeyguardLock("SelectAtTagActivityTest"); mLock.disableKeyguard(); }
9. ApplicationUtil#releaseScreenLock()
Project: RxAndroidBootstrap
File: ApplicationUtil.java
File: ApplicationUtil.java
/** * Release the devices screen lock. * @param context */ public static void releaseScreenLock(Context context) { KeyguardManager keyguardManager = (KeyguardManager) context.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG"); keyguardLock.disableKeyguard(); }
10. KeyguardManagerTest#testIsInRestrcitedInputMode()
Project: robolectric
File: KeyguardManagerTest.java
File: KeyguardManagerTest.java
@Test public void testIsInRestrcitedInputMode() { Activity activity = new Activity(); KeyguardManager mgr = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE); assertThat(mgr.inKeyguardRestrictedInputMode(), equalTo(false)); ShadowKeyguardManager shadowMgr = Robolectric.shadowOf(mgr); shadowMgr.setinRestrictedInputMode(true); assertThat(mgr.inKeyguardRestrictedInputMode(), equalTo(true)); }
11. ADAppUtil#isSleeping()
Project: QDNews
File: ADAppUtil.java
File: ADAppUtil.java
/** * ?????????? * * @param context * @return */ public static boolean isSleeping(Context context) { KeyguardManager kgMgr = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); boolean isSleeping = kgMgr.inKeyguardRestrictedInputMode(); Logger.d(TAG, isSleeping ? "?????.." : "?????..."); return isSleeping; }
12. ApplicationUtil#releaseScreenLock()
Project: MVPAndroidBootstrap
File: ApplicationUtil.java
File: ApplicationUtil.java
/** * Release the devices screen lock. * @param context */ public static void releaseScreenLock(Context context) { KeyguardManager keyguardManager = (KeyguardManager) context.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG"); keyguardLock.disableKeyguard(); }
13. LockscreenUtil#isStandardKeyguardState()
Project: LinLock
File: LockscreenUtil.java
File: LockscreenUtil.java
public boolean isStandardKeyguardState() { boolean isStandardKeyguqrd = false; KeyguardManager keyManager = (KeyguardManager) mContext.getSystemService(mContext.KEYGUARD_SERVICE); if (null != keyManager) { isStandardKeyguqrd = keyManager.isKeyguardSecure(); } return isStandardKeyguqrd; }
14. SystemTool#isSleeping()
Project: KJFrameForAndroid
File: SystemTool.java
File: SystemTool.java
/** * ?????????? */ public static boolean isSleeping(Context context) { KeyguardManager kgMgr = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); boolean isSleeping = kgMgr.inKeyguardRestrictedInputMode(); return isSleeping; }
15. DeviceNotifications#isPrivacyModeActive()
Project: k-9
File: DeviceNotifications.java
File: DeviceNotifications.java
private boolean isPrivacyModeActive() { KeyguardManager keyguardService = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); boolean privacyModeAlwaysEnabled = K9.getNotificationHideSubject() == NotificationHideSubject.ALWAYS; boolean privacyModeEnabledWhenLocked = K9.getNotificationHideSubject() == NotificationHideSubject.WHEN_LOCKED; boolean screenLocked = keyguardService.inKeyguardRestrictedInputMode(); return privacyModeAlwaysEnabled || (privacyModeEnabledWhenLocked && screenLocked); }
16. Formatter#get()
Project: HeadsUp
File: Formatter.java
File: Formatter.java
@NonNull public Data get(@NonNull Context context, @NonNull OpenNotification notification) { KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); boolean secure = km.isKeyguardSecure() && km.isKeyguardLocked(); boolean hiddenContent = secure && hasHiddenContent(); boolean hiddenActions = secure && hasHiddenActions(); // Get the title CharSequence title = NullUtils.whileNotNull(notification.titleBigText, notification.titleText); // Get the subtitle CharSequence subtitle; if (hiddenContent) { PackageManager pm = context.getPackageManager(); try { ApplicationInfo appInfo = pm.getApplicationInfo(notification.getPackageName(), 0); subtitle = pm.getApplicationLabel(appInfo); } catch (PackageManager.NameNotFoundException e) { subtitle = null; } } else { subtitle = CsUtils.join(" ", notification.subText, notification.infoText); } // Get message text CharSequence[] messages; if (hiddenContent) { Resources res = context.getResources(); CharSequence message = res.getString(R.string.privacy_mode_hidden_content); SpannableString spannableMessage = new SpannableString(message); spannableMessage.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannableMessage.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); messages = new CharSequence[] { spannableMessage }; } else { CharSequence message = NullUtils.whileNotNull(notification.messageBigText, notification.messageText); messages = message != null ? new CharSequence[] { message } : null; messages = (CharSequence[]) NullUtils.whileNotNull(notification.messageTextLines, messages); } // Get actions Action[] actions; if (hiddenActions) { actions = null; } else { actions = notification.getActions(); } return new Data(title, subtitle, messages, actions); }
17. FloatWindow#isUnmovable()
Project: CallerInfo
File: FloatWindow.java
File: FloatWindow.java
private boolean isUnmovable(int id) { KeyguardManager km = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE); return id == SETTING_FRONT || id == SEARCH_FRONT || km.inKeyguardRestrictedInputMode(); }
18. MainController#updateKeyguardLocked()
Project: browser-android
File: MainController.java
File: MainController.java
private void updateKeyguardLocked() { KeyguardManager keyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); if (keyguardManager != null) { boolean isLocked = keyguardManager.isKeyguardLocked(); //Log.d(SCREEN_LOCK_TAG, "keyguardManager.isKeyguardLocked():" + mCanDisplay); setCanDisplay(!isLocked); } }
19. LockscreenUtil#isStandardKeyguardState()
Project: Android-LockScreenSample-DisableHomeButtonKey
File: LockscreenUtil.java
File: LockscreenUtil.java
public boolean isStandardKeyguardState() { boolean isStandardKeyguqrd = false; KeyguardManager keyManager = (KeyguardManager) mContext.getSystemService(mContext.KEYGUARD_SERVICE); if (null != keyManager) { isStandardKeyguqrd = keyManager.isKeyguardSecure(); } return isStandardKeyguqrd; }
20. KeyguardUtils#isDeviceLocked()
Project: AcDisplay
File: KeyguardUtils.java
File: KeyguardUtils.java
/** * Returns whether the device is currently locked and requires a PIN, * pattern or password to unlock. */ @SuppressLint("NewApi") public static boolean isDeviceLocked(@NonNull Context context) { KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); return isDeviceLocked(km); }
21. NotificationUtils#isSecure()
Project: AcDisplay
File: NotificationUtils.java
File: NotificationUtils.java
/** * 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(); }