Tagged: lock

Password lock and hibernate linux from the command line

If you want to put your machine into hibernation, and also require a password on coming back up, do this:

xscreensaver-command -lock && hibernate

You need the xscreensaver package installed.

And the hibernate command seemed to appear in 2012.

You may also want to put the lock command in a script, named ‘lock’, for easier typing:

xscreensaver-command --lock
unix lock

Unix: Locking the screen

If you’re not using KDE or Gnome, you may want a command to lock the screen.

    xscreensaver-command -lock

does just that. If you mix that with pm-suspend, your screen will be locked when you come back from suspend or hibernate:

    xscreensaver-command -lock && pm-suspend

Putting that in a bash file may be a little easier on the fingers.

unix unix-lock

Android: Waking the screen, dismissing the keyguard

You can wake and keep wake the screen using the old:

 mPowerManager = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE);
 mWakeLock = mPowerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK 
  | PowerManager.FULL_WAKE_LOCK 
  | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
 if(mWakeLock.isHeld()) {

And the WAKE_LOCK permission in your manifest. And you can disable the keyguard using the old:

 KeyguardManager keyguardManager = (KeyguardManager) appContext.getSystemService(Context.KEYGUARD_SERVICE); 
 KeyguardLock keyguardLock =  keyguardManager.newKeyguardLock("Tag");

And, again, the KEYGUARD permission.

Or you can use the easier Window flags, which require no permissions since they are only applicable to one Window:

android android-wakelock android-keyguard android-windowflags

Page 1 of 1