Controlling how long the lock screen is visible before the display turns off?

181 views
Skip to first unread message

Soudane GMTA

unread,
Jan 26, 2023, 8:11:41 PM1/26/23
to Tasker
When the lock screen becomes visible, after something like 5 or 10 seconds, the display turns off.

Is there a way in Tasker to increase the amount of time that the lock screen is visible before the display finally turns off?

In other words ...

(1) Power button locks the screen
(2) A second push of the power button turns the display on, and the lock screen is visible.
(3) Time passes
(4) The display turns off.

I'm looking for a way in Tasker to control how much time passes in step #3. I want that step to last much longer than 5 or 10 seconds.

João Dias

unread,
Jan 27, 2023, 4:30:19 AM1/27/23
to tas...@googlegroups.com
Is there a system setting that controls that? If not, then Tasker can't control it either unfortunately.

Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias


Soudane GMTA

unread,
Jan 28, 2023, 11:52:53 AM1/28/23
to Tasker
On Friday, January 27, 2023 at 4:30:19 AM UTC-5 joaomgcd wrote:
Is there a system setting that controls that? If not, then Tasker can't control it either unfortunately.

I found lock_screen_lock_after_timeout as a Secure setting that's modifiable via a "Custom Setting" action. However, it seems to be ignored on my (rooted) device.

I run "Gravity Box", and I discovered that it allows certain settings to be modified via its "Advance Tuning" facility. It allows the "System UI" setting called config_lockScreenDisplayTimeout to be modified, and that indeed controls this particular turn-screen-off timeout on the lock screen.  However, that setting only gets applied at boot time, and any changes to that value during the time that the device is running seem to not be recognized until the next restart.

I'm looking for a way to change this time-out value when my device is running, ideally under the automated control of Tasker. Given all that I have explained here, it seems like I am out of luck. Oh well ...


Soudane GMTA

unread,
Jan 28, 2023, 4:23:09 PM1/28/23
to Tasker
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?

Soudane GMTA

unread,
Jan 29, 2023, 12:42:52 PM1/29/23
to Tasker
On Saturday, January 28, 2023 at 4:23:09 PM UTC-5 Soudane GMTA wrote:
[ ... ]

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.

I now have figured out something more efficient. I got rid of the infinite loop, although the Logcat Entry context is still needed ...

 (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  the lock screen should 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 highest 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 a variable called %DeviceIsLocked to 1 (using math). Make sure that these values are initialized during Tasker's Device Boot profile.  During Tasker startup at boot time, the device starts out locked, and this is why %DeviceIsLocked is initialized to 1.

(3) Create the following task called LockscrenDisplayOff . Make sure that this task's Collision Handling is configured to Abort Existing Task ...
  • Variable Set %locked %DeviceIsLocked (using math)
  • For %var 1:%LockscreenDisplayTimeout
  • ... Wait 1 second
  • ... Variable Set %locked %DeviceIsLocked (using math)
  • End For
  • Turn Off if %locked > 0
    Note that we loop over a set of short wait commands instead of
    issuing a single wait command for the full %LockscreenDisplayTimeout
    number of seconds. I found that this and the repeated setting of the %locked
    variable are needed so that the results of the latest invocations of of the
    Locked, Unlocked, DisplayOn, and DisplayOff tasks (see below) are
    detected as soon as possible while this task is running.

(4) Create the following tasks:
  • Locked task
  • ... VariableSet %DeviceIsLocked 1 (using math)
  • Unlocked task
  • ... VariableSet %DeviceIsLocked 0 (using math)
  • ... Stop LockscreenDisplayOff
  • DisplayOn task
  • ... Perform Task LockscreenDisplayOff with %priority set to 0
  • DisplayOff task
  • ... Stop LockscreenDisplayOff

(5) Create a Tasker profile that runs the Locked task when the device has been locked. The only way I could figure out how to detect that the device has been locked is via a Logcat Entry context match of an appropriate logcat line.

QUESTION: is there a more efficient way to detect when the device has been locked?

(6) Create a Tasker profile that runs the Unlocked task whenever the device is unlocked. This is easily done via a Display Unlocked context.

(7) Create a Tasker profile that uses the Display State context to run the DisplayOn task when the display turns on, and which runs the DisplayOff task when the display turns off. This is done by setting DisplayOn as the context's entry task and DisplayOff as the context's exit task.

These tasks and profiles will cause the LockscreenDisplayOff task to be fired off whenever the device is locked and the display turns on. In this scenario, that task will turn off the display after %LockscreenDisplayTimeout seconds have elapsed.

And whenever you 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.


Reply all
Reply to author
Forward
0 new messages