Page 1 of 1

Kill-Start Gravity when display goes on-off

Posted: 25 Apr 2014 08:38
by choo
Hi All,

I'm using an app called Gravity and trying to have Automagic kill or start it every time the display turns off or on. The reason is that all programs I tried that tinkle with the wakelock functions (nci) (Gravity, Screebl, Smart Screen, et al.) prevent my phone from entering the deep sleep state by maintaining the "proximity" wakelock on all the time even when the screen is reported to have been off (checked with BetterBatteryStats and CPU Spy). So I thought I'd use Automagic to (partially) do the job properly.

Some of the issues I'm having are that Gravity is a bit difficult to kill or restart. I understand because it's the nature of the program. Still I made it through by using the "Control UI" actions instead of Kill or Launch app. So I have 2 flows:

#1 Display off - Kill Gravity
Trigger: Display off
Action: Sleep 20000ms
Action: Launch Gravity - default
Control UI: check(on);sleep(500);click(close settings)

#2 Display on - Start Gravity
Trigger: Display on
Action: Launch Gravity - default
Control UI: uncheck(off);sleep(500);click(close settings)

The problem is that Automagic stalls at the step display off (I think, I could not test further), and nothing gets done. After the display gets on again, I do have the Gravity app page but the buttons were not triggered as expected. Both flows work fine when I execute them in Automagic but not outside, i.e. when the display goes on-off by itself.

Any suggestion, pointers or even the whole shebang to execute the flows ;) would be appreciated.

Re: Kill-Start Gravity when display goes on-off

Posted: 25 Apr 2014 14:10
by Martin
Hi,

Action Control UI requires that the display is turned on and unlocked, otherwise Automagic can not 'see' the structure of the user interface.
You could try to force-stop Gravity with an action Execute Root Command: am force-stop <package name> when you don't want that Gravity runs in the background. You can use the [...]-button to select the command from the list of example commands which will also show a list to pick the package name from. Unfortunately this action requires root.

Regards,
Martin

Re: Kill-Start Gravity when display goes on-off

Posted: 25 Apr 2014 15:18
by choo
Hi Martin,

I understand your solution but unfortunately, I haven't rooted my phone as it is still under manufacturer's warranty. I read somewhere that rooted phone, even returned to original ROM state won't be acceptable as untouched phones.

Would it be possible for Automagic to temporarily resurrect the display to do this task in the killing phase and then set the screen back to sleep so that the system can enter deep sleep? I think that the other phase to start Gravity after the screen has turn back on would not encounter such an issue. Could you please point me towards a way to do that? I tried already but could not find a way to turn the screen back on for a couple of seconds. Sorry, I don't have any programming background and do this mostly by trial and errors and mostly with your suggestions and what I can find on this forum. Thanks.

Re: Kill-Start Gravity when display goes on-off

Posted: 26 Apr 2014 11:29
by Martin
Hi,

Temporarily turning the screen on, unlock and disable gravity would be quite complex and would possibly interfere with the screen on flow.

I just saw that Gravity supports the plugin protocol, so you can use an action Plugin to pause/resume Gravity.

Regards,
Martin

Re: Kill-Start Gravity when display goes on-off

Posted: 01 May 2014 14:32
by choo
Hello Martin,

I'm sorry for not having come back to you earlier, I did not have the chance to reinstall Gravity to test again until today. Your suggestion worked great :D and I'm very happy. Thank you for the great responses and response time.

Re: Kill-Start Gravity when display goes on-off

Posted: 02 May 2014 08:32
by Martin
No problem, I'm glad it's working :)