Force automagic to save global variables

Post your questions and help other users.

Moderator: Martin

Post Reply
pa7z2kd
Posts: 12
Joined: 28 Jul 2015 18:45

Force automagic to save global variables

Post by pa7z2kd » 04 Nov 2015 20:28

Is there a way to do it? A made a program to automatic cpu undervolting and I need to save variables before possible reboot

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Force automagic to save global variables

Post by MURTUMA » 05 Nov 2015 05:29

Global vars are saved. They are case sensitive so be sure you write "global_x" instead of "Global_x".

pa7z2kd
Posts: 12
Joined: 28 Jul 2015 18:45

Re: Force automagic to save global variables

Post by pa7z2kd » 05 Nov 2015 05:58

They are not saving instantly after every values changing but periodically (and before android shutdown). I need to save them manually.

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Force automagic to save global variables

Post by MURTUMA » 05 Nov 2015 06:48

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.

pa7z2kd
Posts: 12
Joined: 28 Jul 2015 18:45

Re: Force automagic to save global variables

Post by pa7z2kd » 05 Nov 2015 09:47

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.

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Force automagic to save global variables

Post by MURTUMA » 06 Nov 2015 05:59

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.

pa7z2kd
Posts: 12
Joined: 28 Jul 2015 18:45

Re: Force automagic to save global variables

Post by pa7z2kd » 06 Nov 2015 10:43

I made saving and restoring variables using actions 'write to file' and 'init text file variable'

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Force automagic to save global variables

Post by Martin » 06 Nov 2015 19:41

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

pa7z2kd
Posts: 12
Joined: 28 Jul 2015 18:45

Re: Force automagic to save global variables

Post by pa7z2kd » 09 Nov 2015 14:58

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

Post Reply