Greenify alternative: Automagic

Post your questions and help other users.

Moderator: Martin

Friend1
Posts: 52
Joined: 03 May 2017 06:00

Greenify alternative: Automagic

Post by Friend1 » 13 Dec 2017 07:00

Hi,

I want to kill all running user tasks when screen off. Can I use General Broadcast trigger to do this? Please give me a example to get ruuning task list if it's possible. If screen state is on, launch only Automagic if not running or may prevent it from kill. Thanks.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Greenify alternative: Automagic

Post by Desmanto » 13 Dec 2017 16:09

You need to use execute root command (of course need root)

Code: Select all

dumpsys activity | grep top-activity
to get the current foreground app. Grab the pid using regex and use

Code: Select all

kill {pid}
to kill to it. However, It seems the screen should be on to do it.

Dumpsys can be used to get more info about running app. The one I think you should be care about is not the foreground, but background services those probably running all day long without you noticing.

My phone has battery optimizer, which will "kill" any unwhitelisted app after 5 minutes off. Maybe you should find if you have that option too
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Friend1
Posts: 52
Joined: 03 May 2017 06:00

Re: Greenify alternative: Automagic

Post by Friend1 » 14 Dec 2017 06:43

Hi Desmanto,

Thank you for your attention. Can you give me a example for regex usage for parse this output?
14.12.2017 11:20:25.560 [Flow1] Action 'Execute Root Command: dumpsys -l as root in ' stderr=
14.12.2017 11:20:25.561 [Flow1] Action 'Execute Root Command: dumpsys -l as root in ' exit_code=0
14.12.2017 11:20:25.562 [Flow1] End executing action 'Execute Root Command: dumpsys -l as root in '
14.12.2017 11:20:25.563 [Flow1] Flow continues executing with the next step.
14.12.2017 11:20:25.564 [Flow1] Start executing action 'Script: log({stdout})'
14.12.2017 11:20:25.574 [Flow1] Currently running services:
AAL
BWC
DmAgent
NvRAMAgent
PPLAgent
SurfaceFlinger
accessibility
account
activity
alarm
android.security.keystore
anrmanager
appops
appwidget
assetatlas
audio
audioprofile
backup
battery
batterypropreg
batterystats
bluetooth_manager
bluetooth_profile_manager
clipboard
commontime_management
connectivity
consumer_ir
content
country_detector
cpuinfo
dbinfo
device_policy
devicestoragemonitor
diskstats
display
dreams
drm.drmManager
dropbox
entropy
gfxinfo
hardware
input
input_method
iphonesubinfo
iphonesubinfo2
isms
isms2
kjrnlfb
location
lock_settings
media.VTS
media.audio_flinger
media.audio_policy
media.camera
media.player
media_router
meminfo
memory.dumper
mobile
mount
mtk-agps
mtk-perfservice
mtk.codecservice
netpolicy
netstats
network_management
notification
package
permission
phone
phoneEx
power
print
procstats
samplingprofiler
scheduling_policy
search
search_engine
sensorservice
serial
servicediscovery
simphonebook
simphonebook2
statusbar
telephony.registry
telephony.registry2
textservices
uimode
updatelock
usagestats
usb
user
user.fb_incallsvc
user.kjournald
user.kjrnlfb
vibrator
wallpaper
wifi
wifip2p
window

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Greenify alternative: Automagic

Post by Desmanto » 14 Dec 2017 15:22

dumpsys -l give not much information about the app. You have to get the package name or the PID as my previous post. Or you can use

Code: Select all

service list
which gives more detail. However, most of the services shown are system related. It seems there is no user apps service there. So maybe this is not the proper way.

It seems you only concern about the recent apps only. You can try

Code: Select all

dumpsys activity | grep -i 'run #'
This will list all recent running apps, which probably suitable for your needs. See if these are what you need. I am still working on the regex. We can take out the package name and kill it later.

To check the output of the command, just attach a debug dialog after the execute root command. You can check the result of the stdout.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Friend1
Posts: 52
Joined: 03 May 2017 06:00

Re: Greenify alternative: Automagic

Post by Friend1 » 15 Dec 2017 07:14

Hi Desmanto,

Can i retrieve only recent apps list[/color] by using

Code: Select all

dumpsys activity
? For example:

Recent tasks:
* Recent #1: TaskRecord{42627518 #2 A=com.android.shlylauncher2 U=0 sz=1}
* Recent #2: TaskRecord{42c7d2b8 #157 A=com.android.systemui U=0 sz=1}
* Recent #3: TaskRecord{42637e08 #156 A=ch.gridvision.ppam.androidautomagic U=0 sz=0}
* Recent #4: TaskRecord{42a07170 #164 A=com.gbwhatsapp U=0 sz=1}
* Recent #5: TaskRecord{42bbdce8 #162 A=android.task.mms U=0 sz=1}
* Recent #6: TaskRecord{425d1a68 #159 A=android.task.contacts U=0 sz=1}


dumpsys activity command is returning too much data, it is possible to specify this with command parameter (if any).
In other case may need to parse all data line by line to determine recent tasks and use them. Thanks for your suggestions.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Greenify alternative: Automagic

Post by Desmanto » 15 Dec 2017 14:39

Use my previous code

Code: Select all

dumpsys activity | grep -i 'run #'
the grep will ensure I only grab the line with 'run #'; which in my result is the recent list. If you want to grab the '* Recent #', you can change the grep part

Code: Select all

dumpsys activity | grep -i '* Recent #'
Or maybe try with ': TaskRecord{' too

If you are using as mine, grep the 'run #', you can use the following script to iterate over the recent list and save it to list rec

Code: Select all

find = findAll(stdout, 'Run #\\d+: ActivityRecord\\{\\w+ u0 (.*)/.* \\w+\\}', true);

rec = newList();
for(i in find)
  addElement(rec, i[1]);
The result is the list of package name from recent menu in list rec. You can remove the element which contain automagic package name too, or any other app you want to exclude. Then loop over the list to kill each app which is not whitelisted.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Friend1
Posts: 52
Joined: 03 May 2017 06:00

Re: Greenify alternative: Automagic

Post by Friend1 » 18 Dec 2017 11:10

Hi Desmanto,

findAll functiun not working on my phone (MTK6592 based, android 4.4.2, rooted). Automagic v1.31 premium. Any other suggestions? Thanks.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Greenify alternative: Automagic

Post by Desmanto » 18 Dec 2017 13:45

findAll() was introduced in Automagic 1.33.0 and extended again to have capturing group in 1.34.0.
Please update your Automagic to the latest version to use the function.

Without regex, it is quite difficult to parse the text properly. Too complicated.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Friend1
Posts: 52
Joined: 03 May 2017 06:00

Re: Greenify alternative: Automagic

Post by Friend1 » 20 Dec 2017 06:29

Hi Desmanto,

Code: Select all

find = findAll(stdout, 'Run #\\d+: ActivityRecord\\{\\w+ u0 (.*)/.* \\w+\\}', true);
Since RegEx does not return any value, I try to do task termination with split command. I uploaded my flow
flow_KillRecent_20171220_090917.xml
Clear Rescent Tasks (not working)
(4.28 KiB) Downloaded 1067 times
Can you help me for working flow? Thank you very much.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Greenify alternative: Automagic

Post by Desmanto » 20 Dec 2017 14:47

Additonal argument true at findAll() only available in 1.34.0. You have to update to that version first.

Without capturing group, we still can use 1.33.0 findAll() + matches() to capture that. But that is deprecated already, since we have stable 1.34.0. (why should we use less effective function).

You flow loop only without storing the variable to new element, thus won't work. Should declared a newList() variable first to store the loop result, as you see at my previous post.
Using my script, the rec will contain something like [com.android.chrome, com.whatsapp, com.teslacoilsw.launcher].
Then using we loop similar to the template - loop over list to loop all element (package name) and kill each of them using Kill App/Kill App Process.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply