I am essentially trying to execute the same result as executing the command:
"top -n 1 -s cpu | grep -E 'list_of_package_names'"
on a machine that supports shell functions such as pipeing (|) will return. These are the strings returned by the top command containing the package name filtered by grep. Usually pretty simple things with shell functions, however for my newbie, Android does not come with a shell command, and access to this command can only be achieved using Runtime:
Process p = Runtime.getRuntime().exec(...);
and then get the input stream and read it.
The problem is that it Runtime.getRuntime().exec(...);does not know how to handle the shell language and the command pipeline. So, is there a way to pass the output of the top command to the input of the grep command to essentially create the same functionality? Or is there a way to run commands from a script or anything else that can achieve this result?
On the other hand, I used the adb client / server protocol in my shell commands to verify the syntax is correct, for example:
Runtime.getRuntime().exec("adb shell top -n 1 -s cpu | grep -E '" + shellParams + "'");
This returns the expected result, since the adb shell contains shell functions, but cannot be used outside of debugging, i.e. at runtime.
Any help would be greatly appreciated, this is my first post, so please let me know if I should structure my answer in a completely different way.