12

I'm really confused. I have just noticed that starting from Android 8 all system calls like /proc/stat will be disabled. Ok, but what is work around to get CPU Usage in Android 8? No system calls at all. Is there some API that I'm not familiar with?

I really hope that there is solution which I can't see now.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Kamen Stoykov
  • 1,715
  • 3
  • 17
  • 31

2 Answers2

8

No, all of /proc/stat has been disabled for non-System apps, as a side-channel.

More information, with an official response from Google here: https://issuetracker.google.com/issues/37140047

Zach Riggle
  • 2,975
  • 19
  • 26
  • Thanks for info. It seems that root users will be more and more with each Android version ;) – Kamen Stoykov Sep 15 '17 at 06:52
  • 6
    seriously @Google, you just keep giving me more reasons to *not* upgrade. – Michael Sep 26 '17 at 18:43
  • @KamenStoykov How do you regain access through root? If you could post some code that would be great. – Flyview Oct 12 '17 at 15:09
  • 1
    Process p = Runtime.getRunime().exec("su"). If user gives you access to SU, then connec to steams (p.getOutputstream(), p.getInputStream()) and start executing commands as you are in shell. You can'n make your main application process to run as root. The target device must have root libraries installed. – Kamen Stoykov Oct 12 '17 at 19:36
  • 1
    @KamenStoykov So basically try reading the same file we were before, but through adb shell commands once su is granted? – Flyview Oct 14 '17 at 23:10
  • 1
    @Flyview exactly – Kamen Stoykov Oct 15 '17 at 06:34
0

Precise cpu usage since oreo seems not possible from normal app. But on Android we can guess the cpu usage from cpu frequency.

I did a small lib that permit to do that. Here is the code that hopefully is precise enough: available as a class or as a simple app.

souch
  • 181
  • 2
  • 3