Is there any way to get use of application processor with Android 7 (nougat)

In previous versions of Android, I was able to get CPU usage using 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())); 

Android 7 seems to have changed security or something to prevent this. Now, if it is connected to Android Studio, it will give me a line with the processor% of 1. If you run the release version, I see 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 permission entries mentioned here have something to do with this issue.

https://developer.android.com/about/versions/nougat/android-7.0-changes.html#perm

Here is a link to another question on which I posted a solution for loading the processor on Pre-7 releases.

How to get the overall CPU usage of an application from / proc / pid / stat?

+7
android android-7.0-nougat android-permissions
source share
1 answer

Now that we have switched to Oreo, it seems that Google continues to distract this functionality as a security issue, which I would be shocked at if they opened some new API to replace it. See the following issue tracker for a few comments from someone on Google. Their best recommendation is to use / proc / self / stat instead of / proc / stat

https://issuetracker.google.com/issues/37140047

0
source share

All Articles