In previous releases of Android I was able to get the CPU usage by using a top call
String[] cmd = {
"sh",
"-c",
"top -m 1000 -d 0 -n 1 | grep \"" + aAppPID + "\""};
lProcess = Runtime.getRuntime().exec(cmd);
BufferedReader lReader = new BufferedReader(new InputStreamReader(lProcess.getInputStream()));
It appears that Android 7 has changed the security or something to not allow this. Now, if attached to Android Studio it will give me a line with a CPU % of 1. If running a release version I am seeing that it does not return any lines.
Does anyone know if there is a Permission that can be added to allow this?
My best guess is that the permissions notes documented here have something to do with this problem.
https://developer.android.com/about/versions/nougat/android-7.0-changes.html#perm
Here is a link to another question that I posted a solution to get CPU usage on Pre-7 releases.
How do I get the total CPU usage of an application from /proc/pid/stat?