I figured out how to do it!! (This requires a rooted device running
GravityBox) ...
(1) Go into
GravityBox, and using its
Advanced Tuning facility, go to the
System UI section and set
config_lockScreenDisplayTimeout to the longest number of milliseconds for which I would ever want the lock screen to remain visible before the display turns off. In my case, I want this maximum timeout value to be 5 minutes (300000 milliseconds). This value could be set to be a lot higher, but I don't know the maximum value that will be accepted.
Note that the device needs to be rebooted before this setting takes effect.
(2) Set a Tasker variable called %LockscreenDisplayTimeout to the currently desired timeout in seconds to use between the device being locked and the screen being turned off. Also initialize variables called %DeviceIsLocked and %DisplayStartTime to 0 (using math). Make sure that all these values are initialized during Tasker's Device Boot profile.
(3) Create a Tasker context that sets
%DeviceIsLocked to 1 (using math) whenever the device is locked. The only way I could figure out how to detect that the device has been locked is via a
Logcat Entry profile match of an appropriate logcat line.
QUESTION: is there a more efficient way to detect when the device has been locked?
(4) Create a Tasker context that sets
%DeviceIsLocked to 0 (using math) whenever the device is unlocked. This is easily done via a
Display Unlocked profile.
(5) Create a Tasker context that uses the Display State profile to set %DisplayStartTime to the current %TIMES value (using math) when the display turns on, and which sets %DisplayStartTime to 0 (using math) when the display turns off. This is done via two tasks, one called DisplayOn that gets run as the profile's entry task and one called DisplayOff that gets run as the profile's exit task.
(6) Create a task called LockscreenMonitor which does the following:
Repeatedly run the following code inside of an infinite loop:
- Set a local variable (using math) called %waittime to be 1/2 of the current value of %LockscreenDisplayTimeout.
- Invoke the Wait action for %waittime seconds
- If %DisplayStartTime < 1
- ... set a local variable called %displayduration to 0
- else
- ... set a local variable called %displayduration to %TIMES - %DisplayStartTime
- endif
- If %DeviceIsLocked > 0 AND %displayduration > %LockscreenDisplayTimeout
- ... Run the Turn Off action to turn the screen off
- endif
(7) During the Device Boot profile and after step #2 (above) has been executed, invoke the LockscreenMonitor task with %priority == 0 . This causes the LockscreenMonitor task to run permanently in the background.
Now, whenever I want to change the lockscreen display-turn-off timeout value, all that needs to be done is to set the %LockscreenDisplayTimeout variable to a different value.
This code is not very efficient, given that it uses Logcat Entry and there is an infinite loop running, but it's the best that I could come up with so far.
Can anyone suggest a way to make this more efficient?