Code example for KeyguardManager

Methods: newKeyguardLock

0
   */ 
  @Nullable 
  protected KeyguardManager.KeyguardLock tryToAcquireKeyguardLock() {
    KeyguardManager keyguardManager = (KeyguardManager) getContext()
        .getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock acquiredLock
        = keyguardManager.newKeyguardLock(LOG_TAG);
 
    try { 
      acquiredLock.disableKeyguard();
    } catch (SecurityException exception) {
      Log.w(LOG_TAG, "Could not disable the keyguard for testing; it must be "
          + "disabled manually.", exception);
      acquiredLock = null;
    } 
 
    return acquiredLock;
  } 
 
  /** 
   * Obtains locks to eliminate manual interaction during automation and starts