Locking and unlocking an android device programmatically

How to unlock and lock a screen
Back pocket code snippet
*Note*
For the following to work you need reference to an activity that can talk to the window object.