Screen Saver after no input for 10 seconds

Share and discuss your flows and ideas with other users.

Moderator: Martin

Post Reply
User avatar
Posts: 1931
Joined: 21 Jul 2017 17:50

Screen Saver after no input for 10 seconds

Post by Desmanto » 12 Sep 2017 15:40

This set of flow is created based on this thread : When IDLE do something, when touch screen, other
This require accessibility (UI Event) and Draw over other apps permission (Widget). In case the widget doesn't show up, your ROM probably block the overlay permission, please whitelist Automagic or grant the permission.
Screen Saver

The usage of these 2 flows and 2 widgets is to show a screen saver after inactivity for a certain period of time (example 10 seconds). The example usage is for tablet which is already idle/standby 24/7. You want it to do something while idle, but stop immediately when someone use it. The main flow will use UI Event and will be triggered so often based on the input. The other flow is toggle the main flow, to make sure it stop properly. 1 big Widget is the main screen saver, while the other one is Dead Man Switch. In case something wrong, we can use this DMS to hide the overlay of the big widget.

Widget 1 : Screen Saver
I set the size to 720x1280. You can resize and redesigned it to suit your resolution. For landscape use, you need to swap the X/Y. The text there is just example, you can remove it later. There is single tap action to execute the main flow (flow 1), which is used to hide this widget and trigger the count down.

Widget 2 : Screen Saver DMS
I set the size to 200x200. This is for Dead Man Switch, in case the widget Screen Saver is shown, but the flow is disabled by any means (example reach its emergency stop or disabled by other flow), the click action is used to hide both overlay at once, and save you from locking yourself. If there is no this widget, you might need to force restart (power button 10 seconds) if you get stucked by the Screen saver overlay.

Flow 1 : Screen Saver
It has 2 triggers : UI event with Component Clicked and Component Scrolled. Most of the input should be fall into this category. It matches all package name and all component name, so everything will trigger this. In case you use the device for typing for a long time, you also need to add new UI Event Text Selection Changed. But I don't add it there, since too much UI trigger with global match will slow down your device. There is still another invisible trigger, which is "Widget Click", that is trigger by click from Widget 1 (Screen Saver).

The flow continues to check if the trigger is from Widget, then hide the widget. That is what we want to do, since tapping the screensaver should disable it. If the trigger is not from widget (but from UI event), then it will start to count down for 10 seconds (you can change it to suit your need, I suggest not lower than 5 seconds). After sleep, it will launch the app you need (I put it blank here). Then it will show both widget, the Screen Saver and the DMS. Change the Screen saver widget resolution to your device resolution.

Execution policy and emergency stop
This flow use Execution policy "Stop the currently.....", so everytime the flow got triggered, the sleep timer will be reset again and will never reach its time if there is continuous input from user (click and scroll). Since the trigger UI event with input will be triggered so often, we need to increase the Automatic emergency stop. From my test, usually we can max at average 3 input per second (click or scroll), thus we need at least 3x60 = 180, or just 200 for spare. You can increase this, but make sure don't set it higher than needed. You don't know someday somehow the flow might runaway and trigger doomsday if it doesn't hit the emergency stop.

True continues to false
At the widget click true branch, after hiding the widget, you can see the flow continues to the false branch. This is needed because after hiding the screen saver, you maybe not providing any input anymore to the flow. Example you tap the screen (hide the widget), someone called you and you just leave without doing anything. If so, then there will be no trigger and no count down happen, the screen saver won't come out. By connecting it to the false branch, it will ensure the timer still runing, it just hide it first before showing it again after the timer finish.

DMS button
DMS button doesn't execute this flow, it directly just hide the overlay. So if you tap the DMS widget and not providing any input afterward, the screen saver won't appear again. Since it is emergency button, it supposed to be no problem, you have known it. You should put it somewhere around the corner where it is not usually tapped.

You might see the DMS is put parallel to the action showing the Screen Saver widget 1. This is important, you may not put it after. In case of Automagic emergency stop is reached, then at least the DMS will be executed at the same time with the main widget. Both will appear, so you can use the DMS to hide the widget. If you put the DMS after the Main widget, then if the emergency stop exactly at there, you will never have the DMS button appear to rescue you. If you put it before the main widget, DMS button will be covered by the main widget, so you also can't use it as well. You have to put on same level (parallel). Even if emergency stop now at the main widget, at least DMS still get executed if they are in parallel.

I have created the order of the execution so even at parallel execution, DMS will get executed later. In case you edit your flow and disconnect and reconnect the elements, one thing you should pay attention is this parallel connection. After you have finish all, before testing the flow; you have to remove the connection from DMS to the previous blank element (the one I leave for the Launch App). And then recreate the connection again. It is important, so that DMS widget prioritized to be executed later, appear on top of the main widget (so you can click it) despite executed at the same level of step. This is probably hidden feature for parallel execution. Any connection made later will be executed later also when launch in parallel.

Flow 2 : Toggle Screensaver
I actually don't want to make the second flow. But it is necessary to save you from locking yourself, since this is a full screen blocking widget. The proper way to stop the flow 1 is to disable the flow first and immediately stop the flow. If the flow is not stopped within that timer, tapping the disable will still trigger the last breath for the flow, the flow still run and in the end shows the widget. Since the flow is disabled now, tapping the widget 1 can't hide the flow anymore. This will get yourself locked out from your own device. I have put the DMS widget for this case.

But it is also not convenient to enable the flow again. There are times those you might wanna stop the screensaver for a while and reactivate it again after you have finish with your needs. So I think it is better to use a separate shortcut flow to toggle the main flow on/off. So here it is.

Flow 2 start with shortcut, you can install it to home screen. It will then check if flow 1 is enabled. If disabled, enable it and show notif it has been enabled. If enabled, disable it and stop the flow (very important to stop the last breath) and shows the notif it has been disabled.

After you have edit the flow to your need, now you can enable the Flow : Toggle Screen Saver and add the shortcut to your home screen. Tap this to start the screen saver countdown. Nothing happen, you should not do anything until the timer finish and shows the screen saver widget. Tap it to dismiss it. Now try navigate and clicking something for at least longer than the sleep timer you set. You should see the screen saver doesn't appear. Leave it a while and let it appear again. Now try the DMS button, make sure it works first. Then, toggle the shortcut again, you should not see any screen saver appear anymore after no input for as long as the sleep timer.

Thanks to pickone, who had asked about this flow. When creating and testing this flow I have learnt several undocumented features which are very useful (parallel connection execution order, blank element, widget overlapping)
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), Resurrection Remix Official 7.0.2 20190714, Pie 9.0, Rooted.

Post Reply