home.


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:

#!/bin/bash
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()) {
   mWakeLock.release();
 }
 mWakeLock.acquire();

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");
 keyguardLock.disableKeyguard();

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:

 activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
 activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
 activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
 activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
android android-wakelock android-keyguard android-windowflags

Page 1 of 1