AntonioRedondo / AnotherMonitor

Monitors and records the CPU and memory usage of Android devices
https://play.google.com/store/apps/details?id=org.anothermonitor
GNU General Public License v3.0
1.1k stars 335 forks source link

can we get cpu usage on high api level device by add native binder service to service manager? #16

Open jsrdzhk opened 3 years ago

jsrdzhk commented 3 years ago

Hello!If we add binder native service to aosp source tree,modify sepolicy and add the service into service manager.Can we get cpu usage info by service's code?For example,use popen to exec "top -m 1 -n 1" to get the cpu usage.

update: android removed popen on bionic libc🥲

AntonioRedondo commented 3 years ago

Hello @jsrdzhk,

I don't think it's possible to access service CPU usage by service from my app. Neither I'm planning to implement this anytime soon.

What you could do is to clone the repo and have a look to the ActivityProcesses.java class. I think there is a chance you could modify logic there to access services and show them on screen. Although I'm not sure if this is possible at all with current Android API restrictions.

jsrdzhk commented 3 years ago

😂I copy the popen code into my native service and rename it to popen_s.After that,I can execute shell cmd such as top -m 1 -n 1 or cat /proc/cpuinfo to get cpu usage.Anyway,I will read the code of ActivityProcess.java to see if there's a more elegent way to solve this problem.