use of android.app.ActivityManager.RunningAppProcessInfo in project carat by amplab.
the class SamplingLibrary method getRunningAppInfo.
public static List<ProcessInfo> getRunningAppInfo(Context c) {
List<RunningAppProcessInfo> runningProcs = getRunningProcessInfo(c);
List<RunningServiceInfo> runningServices = getRunningServiceInfo(c);
List<ProcessInfo> l = new ArrayList<ProcessInfo>();
if (runningProcs != null) {
for (RunningAppProcessInfo pi : runningProcs) {
if (pi == null)
continue;
ProcessInfo item = new ProcessInfo();
item.setImportance(CaratApplication.importanceString(pi.importance));
item.setPId(pi.pid);
item.setPName(pi.processName);
l.add(item);
}
}
if (runningServices != null) {
for (RunningServiceInfo pi : runningServices) {
if (pi == null)
continue;
ProcessInfo item = new ProcessInfo();
item.setImportance(pi.foreground ? "Foreground app" : "Service");
item.setPId(pi.pid);
item.setPName(pi.clientPackage);
l.add(item);
}
}
return l;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project carat by amplab.
the class SamplingLibrary method getRunningProcessInfo.
/**
* Populate running process info into the runningAppInfo WeakReference list, and return its value.
* @param context the Context
* @return the value of the runningAppInfo WeakReference list after setting it.
*/
private static List<RunningAppProcessInfo> getRunningProcessInfo(Context context) {
if (runningAppInfo == null || runningAppInfo.get() == null) {
ActivityManager pActivityManager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningProcs = pActivityManager.getRunningAppProcesses();
/*
* TODO: Is this the right thing to do? Remove part after ":" in
* process names
*/
for (RunningAppProcessInfo i : runningProcs) {
if (i != null && i.processName != null) {
int idx = i.processName.lastIndexOf(':');
if (idx <= 0)
idx = i.processName.length();
i.processName = i.processName.substring(0, idx);
}
}
runningAppInfo = new WeakReference<List<RunningAppProcessInfo>>(runningProcs);
}
return runningAppInfo.get();
}
use of android.app.ActivityManager.RunningAppProcessInfo in project Lazy by l123456789jy.
the class AppUtils method gc.
/**
* 清理后台进程与服务
*
* @param context 应用上下文对象context
* @return 被清理的数量
*/
public static int gc(Context context) {
long i = getDeviceUsableMemory(context);
// 清理掉的进程数
int count = 0;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// 获取正在运行的service列表
List<RunningServiceInfo> serviceList = am.getRunningServices(100);
if (serviceList != null) {
for (RunningServiceInfo service : serviceList) {
if (service.pid == android.os.Process.myPid())
continue;
try {
android.os.Process.killProcess(service.pid);
count++;
} catch (Exception e) {
e.getStackTrace();
}
}
}
// 获取正在运行的进程列表
List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
if (processList != null) {
for (RunningAppProcessInfo process : processList) {
// 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
// pkgList 得到该进程下运行的包名
String[] pkgList = process.pkgList;
for (String pkgName : pkgList) {
if (DEBUG) {
}
try {
am.killBackgroundProcesses(pkgName);
count++;
} catch (Exception e) {
// 防止意外发生
e.getStackTrace();
}
}
}
}
}
if (DEBUG) {
}
return count;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project KJFrameForAndroid by kymjs.
the class SystemTool method gc.
/**
* 清理后台进程与服务
*
* @param cxt
* 应用上下文对象context
* @return 被清理的数量
*/
public static int gc(Context cxt) {
long i = getDeviceUsableMemory(cxt);
// 清理掉的进程数
int count = 0;
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
// 获取正在运行的service列表
List<RunningServiceInfo> serviceList = am.getRunningServices(100);
if (serviceList != null)
for (RunningServiceInfo service : serviceList) {
if (service.pid == android.os.Process.myPid())
continue;
try {
android.os.Process.killProcess(service.pid);
count++;
} catch (Exception e) {
e.getStackTrace();
continue;
}
}
// 获取正在运行的进程列表
List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
if (processList != null)
for (RunningAppProcessInfo process : processList) {
// 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
// pkgList 得到该进程下运行的包名
String[] pkgList = process.pkgList;
for (String pkgName : pkgList) {
KJLoger.debug("======正在杀死包名:" + pkgName);
try {
am.killBackgroundProcesses(pkgName);
count++;
} catch (Exception e) {
// 防止意外发生
e.getStackTrace();
continue;
}
}
}
}
KJLoger.debug("清理了" + (getDeviceUsableMemory(cxt) - i) + "M内存");
return count;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by DirtyUnicorns.
the class FingerprintService method isForegroundActivity.
private boolean isForegroundActivity(int uid, int pid) {
try {
List<RunningAppProcessInfo> procs = ActivityManagerNative.getDefault().getRunningAppProcesses();
int N = procs.size();
for (int i = 0; i < N; i++) {
RunningAppProcessInfo proc = procs.get(i);
if (proc.pid == pid && proc.uid == uid && proc.importance == IMPORTANCE_FOREGROUND) {
return true;
}
}
} catch (RemoteException e) {
Slog.w(TAG, "am.getRunningAppProcesses() failed");
}
return false;
}
Aggregations