"Run on system startup" and "System settings get" with "When changed"

80 views
Skip to first unread message

yak...@gmail.com

unread,
Jun 21, 2018, 3:01:28 PM6/21/18
to automa...@googlegroups.com

My system likes to restore a variable at random times, so I have a simple flow consisting of a loop that "System setting set" the variable, then "System setting get" the variable but only proceeds "When changed".  Automate is also set to "Run on system startup".

However, after a system reboot, if the system restores the variable before Automate runs, the flow does not work because the flow resumes in the get block but does not find the variable to have been changed.

I am wondering if there is a workaround for this?  Is there a way to always resume after a restart to the beginning?  Or to know there has been a restart?


I am also curious how "When changed" works (I am not familiar with Android system calls).  Edit: Android is event based, so it may be something like https://stackoverflow.com/questions/6190779/monitor-android-system-settings-values/6191153, which is better than reading the variable repeatedly and testing for changes myself.


ldgo...@gmail.com

unread,
Jun 21, 2018, 3:15:39 PM6/21/18
to Automate
You could add a block before the "when changed" block that is an "immediate" block. Then attach the "immediate" block to the "when changed" block.  That way you get an immediate read and then you can loop back to the "when changed" block for the rest of the flow, making it wait and not use as much battery.


On Thursday, June 21, 2018 at 12:01:28 PM UTC-7, andyk88 wrote:

My system likes to restore a variable at random times, so I have a simple flow consisting of a loop that "System setting set" the variable, then "System setting get" the variable but only proceeds "When changed".  Automate is also set to "Run on system startup".

However, after a system reboot, if the system restores the variable before Automate runs, the flow does not work because the flow resumes in the get block but does not find the variable to have been changed.

I am wondering if there is a workaround for this?  Is there a way to always resume after a restart to the beginning?  Or to know there has been a restart?

I am also curious how "When changed" works (I am not familiar with Android system calls).  Does it become a flag so the system call is pending (i.e., does not return) until the variable is changed?


andyk88

unread,
Jun 21, 2018, 3:43:03 PM6/21/18
to Automate
Thank you for the suggestion.  But wouldn't the flow still be waiting in the "When changed" block when the system is being powered off, so when the system restarts, it resumes in the same "When changed" block and becomes stuck there?

Henrik "The Developer" Lindqvist

unread,
Jun 21, 2018, 3:57:07 PM6/21/18
to Automate
Use the Broadcast receive block with action Boot completed to detect a reboot, then "reset" the setting.



On Thursday, June 21, 2018 at 9:01:28 PM UTC+2, andyk88 wrote:

My system likes to restore a variable at random times, so I have a simple flow consisting of a loop that "System setting set" the variable, then "System setting get" the variable but only proceeds "When changed".  Automate is also set to "Run on system startup".

However, after a system reboot, if the system restores the variable before Automate runs, the flow does not work because the flow resumes in the get block but does not find the variable to have been changed.

I am wondering if there is a workaround for this?  Is there a way to always resume after a restart to the beginning?  Or to know there has been a restart?

I am also curious how "When changed" works (I am not familiar with Android system calls).  Does it become a flag so the system call is pending (i.e., does not return) until the variable is changed?


ldgo...@gmail.com

unread,
Jun 21, 2018, 4:30:59 PM6/21/18
to Automate
Possibly. I assumed that after a reboot, all of the flows would start at the beginning. Whatever item had not changed would still not have changed, it would just be. But I'm not the programmer. It's just how I solved for the problem in one of my flows.

andyk88

unread,
Jun 21, 2018, 4:38:41 PM6/21/18
to Automate

After a reboot, it seems a flow resumes in the same block as before, not the beginning.

andyk88

unread,
Jun 21, 2018, 5:11:45 PM6/21/18
to automa...@googlegroups.com

Thank you very much!

I notice there are actually "Boot completed" and "Automate service started".  Would "Automate service started" better capture all restart events, for example also after Automate is force stopped (and then restarted)?


Edit: Boot completed is an intent.  I am guessing "Automate service started" happens after startService() is called.

https://developer.android.com/reference/android/content/Intent#ACTION_BOOT_COMPLETED


As to how to use the "Broadcast receive" block, I found this topic:

https://groups.google.com/forum/#!msg/automate-user/Yr7GI3vzTMs/PGTvFmhbAgAJ

So I connected "Flow beginning" to "Fork".  One side of "Fork" goes to the existing set/get loop.  Another side of "Fork" goes to "Broadcast receive", which goes to set, then loops back to "Broadcast receive" as a separate new loop.

The get in the existing loop becomes unstuck by virtue of the set in the new loop.

So far it seems to work (I tried to "force stop" Automate, changed the variable using Settings Database Editor, then ran Automate again).  I will see if it continues to work, but wow, Automate is really powerful!

Thank you very much again!

Henrik "The Developer" Lindqvist

unread,
Jun 21, 2018, 8:37:08 PM6/21/18
to Automate
"Automate service started" is broadcast after every Automate restart, i.e. after a low-memory situation, or device reboot.
"Boot completed" is only broadcast after system reboot.



On Thursday, June 21, 2018 at 11:11:45 PM UTC+2, andyk88 wrote:

Thank you very much!

I notice there are actually "Boot completed" and "Automate service started".  Would "Automate service started" better capture all restart events, for example also after Automate is force stopped (and then restarted)?


Edit: Boot completed is an intent.  I am guessing "Automate service started" happens after startService() is called.

https://developer.android.com/reference/android/content/Intent#ACTION_BOOT_COMPLETED


As to how to use the "Broadcast receive" block, I found this topic:

https://groups.google.com/forum/#!msg/automate-user/Yr7GI3vzTMs/PGTvFmhbAgAJ

So I connected "Flow beginning" to "Fork".  One side of "Fork" goes to the existing set/get loop.  Another side of "Fork" goes to "Broadcast receive", which goes to set, then loop back to "Broadcast receive" as a separate new loop.

andyk88

unread,
Jun 21, 2018, 8:40:39 PM6/21/18
to Automate
Thank you very much for the clarification! So "Automate service started" does seem to better capture more situations when the system can restore the variable when Automate is not running.

Henrik "The Developer" Lindqvist

unread,
Jun 21, 2018, 9:41:45 PM6/21/18
to Automate
Yes,
Reply all
Reply to author
Forward
0 new messages