Page 1 of 1

Force automagic to save global variables

Posted: 04 Nov 2015 20:28
by pa7z2kd
Is there a way to do it? A made a program to automatic cpu undervolting and I need to save variables before possible reboot

Re: Force automagic to save global variables

Posted: 05 Nov 2015 05:29
by MURTUMA
Global vars are saved. They are case sensitive so be sure you write "global_x" instead of "Global_x".

Re: Force automagic to save global variables

Posted: 05 Nov 2015 05:58
by pa7z2kd
They are not saving instantly after every values changing but periodically (and before android shutdown). I need to save them manually.

Re: Force automagic to save global variables

Posted: 05 Nov 2015 06:48
by MURTUMA
Try these two flows: http://automagic4android.com/flow.php?i ... b207835e7e

Enable flow4 and execute manually flow3. Flow4 executes every time a new value is assigned to var "global_test". To be able to be executed the variable must be saved immediately as it gets a new value.

From here, you can draw conclusion that global variables are saved at the moment the value is set. Otherwise it would skip some times it's supposed to execute.

The variables are saved to "internal storage/Automagic/variables.bin" and will retain their values over boot. Just make sure no app is restricting access or deleting that file.

If all this is not true in your case, there must be something wrong on your phone or Automagic installation.

Re: Force automagic to save global variables

Posted: 05 Nov 2015 09:47
by pa7z2kd
After changing global var automagic saves it in RAM, and only later in internal storage. So if android will reboot right after var changing it will not be saved and will not be retained after boot.

Re: Force automagic to save global variables

Posted: 06 Nov 2015 05:59
by MURTUMA
I wasn't aware of that detail. I don't remember anyone else complaining about this so I believe it's not long time before vars gets saved to variables.bin. One way to circumvent this is by having a flow to init variables at boot. Ofcourse it's not feasible in all situations. Are you using trigger Shutdown? Many phones allow only very short flows to run to the end before shutting down.

Re: Force automagic to save global variables

Posted: 06 Nov 2015 10:43
by pa7z2kd
I made saving and restoring variables using actions 'write to file' and 'init text file variable'

Re: Force automagic to save global variables

Posted: 06 Nov 2015 19:41
by Martin
Hi,

Global variables are saved whenever a flow ends and should also be saved when Automagic is stopped. How are you rebooting the device, using a regular shutdown procedure with action Reboot or are you using something faster like Execute Root Command: reboot -p?
As a workaround you could create a dummy flow without triggers or actions and use an action Execute Flows: dummy flow which will cause the global variables to be saved.

Regards,
Martin

Re: Force automagic to save global variables

Posted: 09 Nov 2015 14:58
by pa7z2kd
My flow decreasing cpu voltage each 20 minutes until cpu stops, and when cpu stops, screen freezes for few seconds and phone rebooting. So it's not like a normal rebooting, no one program can't react to it (because cpu is off). So I have to save variables to file manually before next undervolting