r/tasker • u/Blitzdroids • Jun 23 '23
Looking for task to kill all running background applications
Not quite sure how to do this using ADB WiFi with no root. Basically I just need it to query all applications currently running in the background and return them in a list so that I can use Kill or am force-stop app package to stop it. For this to work right, I would need the app package name parsed out for each app stored in an array, and nothing more.
Anyone know a way to do this with Tasker? I am always connected to ADB TCP port 5555 so anything requiring that is okay.
The goal here is to prep my phone for intense gaming. Not interested in a profile since profiles require resources which I'm trying to limit.
Edit:
So thanks for your input guys. If you could take a look at my custom made task that is designed to be shared. It gets the background packages and runs it through an app info action to display the app names in a list. You can also setup an application ignore list which will ignore any applications in it. The list can be updated fairly easily just by running the task and pressing available options.
My concern is that the applications it's querying aren't actually running in the background or they aren't being killed properly.
Feedback requested. App Kill Booster (TaskerNet Import)
2
u/Blitzdroids Jul 01 '23
So thanks for your input guys. If you could take a look at my custom made task that is designed to be shared. It gets the background packages and runs it through an app info action to display the app names in a list. You can also setup an application ignore list which will ignore any applications in it. The list can be updated fairly easily just by running the task and pressing available options.
My concern is that the applications it's querying aren't actually running in the background or they aren't being killed properly.
Feedback requested. App Kill Booster (TaskerNet Import)
4
u/agnostic-apollo LG G5, 7.0 stock, rooted Jun 24 '23 edited Jun 24 '23
The
pm list packages -3command can be used to list 3rd party apps as shown above. The-aflag will match uninstalled and secondary user packages as well, which is not required for your case.To check if an app is running, simply running
pidof '<package_name>'should work, but more reliable way would be something likedumpsys activity processes '<package_name>' | grep -A5 -aE 'All known processes:' | grep -aE 'ProcessRecord{', likedumpsys activity processes 'net.dinglisch.android.taskerm' | grep -A5 -aE 'All known processes:' | grep -aE 'ProcessRecord{'since that will list processes state based on android internal records. Apps can have multiple app processes and they can change process names as well.Using
psandpidofisn't reliable because any app/process can start processes with the name of an app package name, which will then show in the output, giving a false positive, unless you check the uid as well.https://developer.android.com/guide/topics/manifest/service-element#proc
https://cs.android.com/android/platform/superproject/+/android-13.0.0_r54:frameworks/base/services/core/java/com/android/server/pm/PackageManagerShellCommand.java;l=866
https://cs.android.com/android/platform/superproject/+/android-13.0.0_r54:frameworks/base/core/java/android/content/pm/PackageManager.java;l=1031
https://cs.android.com/android/platform/superproject/+/android-13.0.0_r54:frameworks/base/core/java/android/content/pm/PackageManager.java;l=1111
u/Ratchet_Guy u/HunterXProgrammer
3
u/Ratchet_Guy Moderator Jun 24 '23
/u/agnostic-apollo probably has a Shell Command or something to get that list :)
3
u/HunterXProgrammer Jun 24 '23 edited Jun 24 '23
Since forever, whenever I use multiple lines in [ADB Wifi] action, Tasker sort of chokes out 3 of 10 times and the action just times out . I've learned to live with using one-liners.
Here is a one-liner I'd use -
whitelist="net.dinglisch.android.taskerm,com.termux" && echo $(/system/bin/ps -e -o USER,NAME | grep -E "^u0_a" | sed 's/.* //g' | grep -Eo "(^$(echo $(pm list packages -3 | sed 's/package://g' | grep -Ev "(^$(echo $whitelist | sed 's/ *//g' | sed 's/\./\\\./g' | sed 's/,/\$\|\^/g')$)") | sed 's/\./\\\./g' | sed 's/ /\$\|\^/g')$)") | sed 's/ / \& am force-stop /g' | sed -E 's/^/am force-stop /' | sed -E 's/$/ \&/' | sh && waitThe
whitelistcontains comma seperated package names you'd like to avoid killing.This one-liner will only get the list of user installed apps (we avoid system apps) and check if it's running and proceed to kill the app if it's running.