5.0获取当前打开的应用信息
来源:互联网 发布:centos 7web服务器 编辑:程序博客网 时间:2024/05/29 18:37
public String getForegroundApp() {
File[] files = new File("/proc").listFiles();
int lowestOomScore = Integer.MAX_VALUE;
String foregroundProcess = null;
for (File file : files) {
if (!file.isDirectory()) {
continue;
}
int pid;
try {
pid = Integer.parseInt(file.getName());
} catch (NumberFormatException e) {
continue;
}
try {
String cgroup = read(String.format("/proc/%d/cgroup", pid));
String[] lines = cgroup.split("\n");
if (lines.length != 2) {
continue;
}
String cpuSubsystem = lines[0];
String cpuaccctSubsystem = lines[1];
if (!cpuaccctSubsystem.endsWith(Integer.toString(pid))) {
// not an application process
continue;
}
if (cpuSubsystem.endsWith("bg_non_interactive")) {
// background policy
continue;
}
String cmdline = read(String.format("/proc/%d/cmdline", pid));
// String cmdline = read(String.format("ps -A |grep pid", pid));
Log.e("cmdline",cmdline);
if (cmdline.contains("com.android.systemui")) {
continue;
}
int uid = Integer.parseInt(
cpuaccctSubsystem.split(":")[2].split("/")[1].replace("uid_", ""));
if (uid >= 1000 && uid <= 1038) {
// system process
continue;
}
int appId = uid - AID_APP;
int userId = 0;
// loop until we get the correct user id.
// 100000 is the offset for each user.
while (appId > AID_USER) {
appId -= AID_USER;
userId++;
}
if (appId < 0) {
continue;
}
// u{user_id}_a{app_id} is used on API 17+ for multiple user account support.
// String uidName = String.format("u%d_a%d", userId, appId);
File oomScoreAdj = new File(String.format("/proc/%d/oom_score_adj", pid));
if (oomScoreAdj.canRead()) {
int oomAdj = Integer.parseInt(read(oomScoreAdj.getAbsolutePath()));
if (oomAdj != 0) {
continue;
}
}
int oomscore = Integer.parseInt(read(String.format("/proc/%d/oom_score", pid)));
if (oomscore < lowestOomScore) {
lowestOomScore = oomscore;
foregroundProcess = cmdline;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return foregroundProcess;
}
File[] files = new File("/proc").listFiles();
int lowestOomScore = Integer.MAX_VALUE;
String foregroundProcess = null;
for (File file : files) {
if (!file.isDirectory()) {
continue;
}
int pid;
try {
pid = Integer.parseInt(file.getName());
} catch (NumberFormatException e) {
continue;
}
try {
String cgroup = read(String.format("/proc/%d/cgroup", pid));
String[] lines = cgroup.split("\n");
if (lines.length != 2) {
continue;
}
String cpuSubsystem = lines[0];
String cpuaccctSubsystem = lines[1];
if (!cpuaccctSubsystem.endsWith(Integer.toString(pid))) {
// not an application process
continue;
}
if (cpuSubsystem.endsWith("bg_non_interactive")) {
// background policy
continue;
}
String cmdline = read(String.format("/proc/%d/cmdline", pid));
// String cmdline = read(String.format("ps -A |grep pid", pid));
Log.e("cmdline",cmdline);
if (cmdline.contains("com.android.systemui")) {
continue;
}
int uid = Integer.parseInt(
cpuaccctSubsystem.split(":")[2].split("/")[1].replace("uid_", ""));
if (uid >= 1000 && uid <= 1038) {
// system process
continue;
}
int appId = uid - AID_APP;
int userId = 0;
// loop until we get the correct user id.
// 100000 is the offset for each user.
while (appId > AID_USER) {
appId -= AID_USER;
userId++;
}
if (appId < 0) {
continue;
}
// u{user_id}_a{app_id} is used on API 17+ for multiple user account support.
// String uidName = String.format("u%d_a%d", userId, appId);
File oomScoreAdj = new File(String.format("/proc/%d/oom_score_adj", pid));
if (oomScoreAdj.canRead()) {
int oomAdj = Integer.parseInt(read(oomScoreAdj.getAbsolutePath()));
if (oomAdj != 0) {
continue;
}
}
int oomscore = Integer.parseInt(read(String.format("/proc/%d/oom_score", pid)));
if (oomscore < lowestOomScore) {
lowestOomScore = oomscore;
foregroundProcess = cmdline;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return foregroundProcess;
}
0 0
- 5.0获取当前打开的应用信息
- android获取用户当前正在打开的应用程序的信息
- 获取当前电脑上打开的端口信息
- 使用python编写脚本获取手机当前应用的信息
- 安卓开发获取当前手机应用信息的方法
- 获取当前运行应用信息的几种方法
- Android:获取应用信息,打开、卸载应用
- 获取当前设备所有应用基础信息
- 获取当前脚本的信息
- 获取当前的位置信息
- (获取应用的包名/应用名等信息)打开、安装和卸载应用
- 获取当前打开的WORD文件路径
- Android 下 如何获取当前运行的应用信息(代码)
- 获取当前应用的版本号/应用名称
- 获取app应用版本的信息和当前设备的各种信息,跳转到appstore(二)
- 获取当前调用函数的信息
- 获取当前用户的组织信息
- 获取当前登录者的信息
- windwos操作系统版本
- objective-C 编程全解-第15章 消息发送模式 中
- Spring开发中的异常处理
- 根据日期计算是星期几
- Linux安装svn并添加用户权限
- 5.0获取当前打开的应用信息
- Swift - 自定义tabbar的封装
- jQuery的选择器中的通配符[id^='code'](
- iOS 无线打印功能(AirPrint)
- IOS Top100的第三方库整理
- JavaScript表单序列化
- kiss原则
- 为什么说完善思维方式比知识结构更重要
- objective-C 编程全解-第15章 消息发送模式 下 NSUndoManager 撤销管理器