Android(安卓)7.0 7.1 8.0 应用获取各个应用/proc/内存信息的问题
16lz
2021-01-24
问题由来是:第三方软件(桌面管家)需要获取其他各个app的内存信息,实现一键加速的功能。 关于一键加速如何实现? http://blog.csdn.net/wds1181977/article/details/50997462
原app在获取内存信息的时候,使用了jaredrummler的github开源项目,本质上就是单个应用去访问android的proc底层目录,然后获取数据,再进行加速等操作。
每个应用产生,都会在android底层proc下面产生一个路径,路径的名字以这个应用的pid命名,这个路径下面会有很多关于应用的信息,包括oom_adj等。
获取应用列表的方法是:
/** * @return a list of all running app processes on the device. */ public static List getRunningAppProcesses() { List processes = new ArrayList<>(); File[] files = new File("/proc").listFiles(); for (File file : files) { if (file.isDirectory()) { int pid; try { pid = Integer.parseInt(file.getName()); if(file.getName().matches("[0-9]+")) { Log.v("dengtl - number path "," getName = " + file.getName() + " getAbsolutePath = " +file.getAbsolutePath() + " canRead = " + file.canRead()); } } catch (NumberFormatException e) { continue; } try { processes.add(new AndroidAppProcess(pid)); } catch (AndroidAppProcess.NotAndroidAppProcessException ignored) { } catch (IOException e) { // If you are running this from a third-party app, then system apps will not be // readable on Android 5.0+ if SELinux is enforcing. You will need root access or an // elevated SELinux context to read all files under /proc. // See: https://su.chainfire.eu/#selinux } } } return processes; }
由于在7.1系统,应用不允许访问pro目录下的其他应用的pid的路径,于是会报错。
查阅了大量的文章文献,最终表示,在7.1版本后,就不允许访问了,如下:
查看文章链接: https://www.jianshu.com/p/e1d385bf8a03 http://blog.nsfocus.net/app-client-hijacking-simple-protection/ http://blog.csdn.net/carefulboys/article/details/55252410
https://code.google.com/p/android/issues/detail?id=205565
jaredrummler的github开源项目: https://github.com/jaredrummler/AndroidProcesses
原app在获取内存信息的时候,使用了jaredrummler的github开源项目,本质上就是单个应用去访问android的proc底层目录,然后获取数据,再进行加速等操作。
每个应用产生,都会在android底层proc下面产生一个路径,路径的名字以这个应用的pid命名,这个路径下面会有很多关于应用的信息,包括oom_adj等。
获取应用列表的方法是:
/** * @return a list of all running app processes on the device. */ public static List getRunningAppProcesses() { List processes = new ArrayList<>(); File[] files = new File("/proc").listFiles(); for (File file : files) { if (file.isDirectory()) { int pid; try { pid = Integer.parseInt(file.getName()); if(file.getName().matches("[0-9]+")) { Log.v("dengtl - number path "," getName = " + file.getName() + " getAbsolutePath = " +file.getAbsolutePath() + " canRead = " + file.canRead()); } } catch (NumberFormatException e) { continue; } try { processes.add(new AndroidAppProcess(pid)); } catch (AndroidAppProcess.NotAndroidAppProcessException ignored) { } catch (IOException e) { // If you are running this from a third-party app, then system apps will not be // readable on Android 5.0+ if SELinux is enforcing. You will need root access or an // elevated SELinux context to read all files under /proc. // See: https://su.chainfire.eu/#selinux } } } return processes; }
由于在7.1系统,应用不允许访问pro目录下的其他应用的pid的路径,于是会报错。
查阅了大量的文章文献,最终表示,在7.1版本后,就不允许访问了,如下:
查看文章链接: https://www.jianshu.com/p/e1d385bf8a03 http://blog.nsfocus.net/app-client-hijacking-simple-protection/ http://blog.csdn.net/carefulboys/article/details/55252410
https://code.google.com/p/android/issues/detail?id=205565
jaredrummler的github开源项目: https://github.com/jaredrummler/AndroidProcesses
更多相关文章
- Android&Java的学习新的等
- android 常用的调试方法
- 免root实现 Android改机(一键新机)技术解密。
- 初识 Android(安卓)Native Development Kit (NDK)
- 1.4掌握日志工具的使用——Android第一行代码(第二版)笔记
- android实现原理说明之一_application Intent Task Activity
- Android(安卓)4.4 meminfo 实现分析
- Android(安卓)Studio 中Gradle配置debug使用release的签名
- 32位Ubuntu12.04编译VLC流程