Alternative Delayed Keyguard Enabler (with homescreen Toggler)

I had previously followed the wiki Keyguard Toggle Widget and created a widget on my homescreen1, so that while I'm working away on my PC with my Galaxy S next to me, I didn't want to have to continually spread my messy fingers over it to unlock it when I wanted to look at something. I tailored it a little by changing some of the icons, after downloading some of the sexy looking doodahs from the Icons Page.

But then I realised I was a forgetful so-and-so, and wanted to have the Keyguard automatically re-applied if I walked away from the PC. So I created a Profile with contexts for Not (on) Power and Not USB Plugged with a Display Off event, then put together a suitable task.

Recently, however, marko wanted to know how to create a "grace" period between when the display turns off and the keyguard becoming enabled. After a bit of discussion, I came up with the following solution (xml files are attached at the end - These tasks and profile were written and tested on a stock Samsung Galaxy S GT-I9000, firmware 2.2.1. YMMV.):

+++ Edit, 14th June 2011:
Having just upgraded my Samsung Galaxy S to stock Gingerbread (2.3.3), the widget icon changing task wasn't firing… turns out that the 'Turn On' action is no longer available to Tasker (pesky paranoid android devs!), so because that wasn't firing, neither was the widget icon changing task. In the step through below and in the attached profiles, I have left the action in for those on earlier versions of Android - and noted that the step should be skipped if you are on Gingerbread or later. +++ End of edit

Step by step to create your complete profile

  1. First, tap New to create a new profile - give it the name LockIt
  2. Select State for your first context, and choose Power
  3. Enable the Invert criterion (tap the tick), so the actual context is 'Not on Power'
  4. Click Done

You will now need to create the task

  1. Select New Task + at the top of the Task Selection popup that appeared after step 4
  2. Tap on the blue + at the bottom left to create the first action:
    1. From the Action Category, select Tasker
    2. Select the If Tasker Action
    3. To select a variable label that already exists, tap on the 'luggage tag' icon on the right - in the list that appears, select Keyguard Status. This returns %KEYG into the first field.
    4. Leave the next field as ~, indicating 'matches'
    5. In the next field, enter off - note lowercase for all letters
    6. Tap Done - and the first action has been created, that says 'If the Keyguard is set to off, or is disabled, proceed to the next action. If the Keyguard is on, skip down to the action after the End If action' - although we haven't yet created an End If action, you always have to have one after you have created an If action.
  3. Now we need to create the remaining actions:
    1. Tap the blue + and from the Tasker category select the Wait action. Use the sliders to select whatever time you want to allow after the screen has gone off before your Keyguard is switched on. This will be marko's 'grace period'. Tap Done when, well… done(!)
    2. Tap the blue + and from the Display category, select Keyguard. Tap on the drop down list and select On, then tap on the tick against the If criterion. This then displays the fields to select the appropriate variable - either type in %SCREEN or select Screen from the list of variables available from the 'luggage label'. Leave the next field as ~ and type in off (all lowercase) in the next field. Tap Done. This ensures that the Keyguard is only enabled (after waiting the requisite time from the previous action) if the display is off.
    3. Skip this step if your phone is on Gingerbread or later! However, because the previous action does not actually change anything while the display is off (although it does turn the Keyguard on, this doesn't take affect until the display comes on and then goes off and then comes on again!), we need to turn your device on - Tap the blue + and from the Display category, select Turn On. Tap on the If tick and enter variable %KEYG ~ on (lowercase). Tap Done. What we have now done is use the last three actions to wait for 'n' grace period, set the Keyguard to on and then turn on the display to activate the Keyguard. The Keyguard will not be turned on nor activated, though, if the display is turned back on before the grace time has run out.
    4. (These next actions are only relevant if you have - or intend to - install the Keyguard Toggle Widget, which include tasks to set the widget icon according to the status of the Keyguard. If you don't want to have a Keyguard Toggle widget, you can skip these actions and go to step 5 below)
      1. Tap the blue + and from the Tasker category, select Set Widget Icon. Enter the name of the widget (in my case, Keyguard). Tap the palette on the Icon line and select an appropriate icon you want displayed on your widget when the Keyguard is active. Tap on the If tick and enter variable %KEYG ~ on (lowercase). Tap Done.
      2. I also have a separate task, called KeyguardNotification2, that sends a notification when the Keyguard is enabled. So I now call this task, and you can too: Tap the blue + and from the Tasker category, select Perform Task. Type in the name KeyguardNotification. Tap on the If tick and enter variable %KEYG ~ on (lowercase). Tap Done.
    5. Now we just need to turn off the display with the keyguard enabled - Tap the blue + and from the Display category, select System Lock. Tap on the If tick and enter variable %KEYG ~ on (lowercase). Tap Done.
    6. Last action - Tap the blue + and from the Tasker category, select End If. Tap Done.
    7. With all the actions entered, we now need to make sure that the phone doesn't go to sleep and stop running the task. Tap on the spanner (or wrench as the americans call it) and screwdriver button, and tap to tick Keep Device Awake. Tap Done.
    8. [Optional step] Tap on the blue uppercase A to give your task a name - I called mine Lock3 - just name it and tap Done
    9. Tap Done to close the Task Edit window.
  4. The last steps we need to take are setting approriate profile triggers - we already have the context Not Power, so tap that and select Add. Select whatever contexts you wish to apply, but these are the one's I have:
    1. State -> USB plugged, inverted (ie no USB cable is plugged in). I have this because I plug a cable in when I'm on my motorbike which most of the time supplies power to my SGS… sometimes the connection gets a little loose, so I don't want Tasker to think it's not on power and trigger this profile. Omit this context if you only want the phone to remain unlocked whilst being charged.
    2. Event -> Display Off. This means that when the phone is unplugged, the profile becomes active when the screen turns off.

So there it is4 - I hope it proves useful. After I'd written the basics of the above in response to marko's question, elliot asked for a step-by-step, which is what you have just gone through. Then I found Delay Keyguard - but as it is a slightly different method, and doesn't include any uploaded profiles or tasks, I thought I'd carry on anyway… publish and be damned so to speak!

If they can be improved, or you have any suggestions or questions, please post them here.

XML files for download

Right click on the footnotes below and choose Save Target As, or whatever your browser has for you to download the files

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License