问题由来是:第三方软件(桌面管家)需要获取其他各个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

更多相关文章

  1. Android&Java的学习新的等
  2. android 常用的调试方法
  3. 免root实现 Android改机(一键新机)技术解密。
  4. 初识 Android(安卓)Native Development Kit (NDK)
  5. 1.4掌握日志工具的使用——Android第一行代码(第二版)笔记
  6. android实现原理说明之一_application Intent Task Activity
  7. Android(安卓)4.4 meminfo 实现分析
  8. Android(安卓)Studio 中Gradle配置debug使用release的签名
  9. 32位Ubuntu12.04编译VLC流程

随机推荐

  1. 原生Android也能做Web开发了
  2. android 焦点问题
  3. Annroid交互式视觉设计控件一
  4. APP开发实战95-动态Vector基础
  5. 关于android的Menu理解
  6. Android(安卓)实现首次开机启动wizardset
  7. APK 瘦身
  8. android学习笔记36:消息提示
  9. android电池(四):电池 电量计(MAX17040)驱动
  10. 解决 duplicate entry: com/android/voll