use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by ParanoidAndroid.
the class MemoryUsageTest method getPss.
private int getPss(String processName) {
ActivityManager am = (ActivityManager) getInstrumentation().getContext().getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
for (RunningAppProcessInfo proc : apps) {
if (!proc.processName.equals(processName)) {
continue;
}
int[] pids = { proc.pid };
MemoryInfo meminfo = am.getProcessMemoryInfo(pids)[0];
return meminfo.getTotalPss();
}
return -1;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project superCleanMaster by joyoyao.
the class AppUtil method getRunningAppProcesses.
/**
* 描述:获取运行的进程列表.
*
* @param context
* @return
*/
public static List<AppProcessInfo> getRunningAppProcesses(Context context) {
ActivityManager activityManager = null;
List<AppProcessInfo> list = null;
PackageManager packageManager = null;
try {
activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
packageManager = context.getApplicationContext().getPackageManager();
list = new ArrayList<AppProcessInfo>();
// 所有运行的进程
List<RunningAppProcessInfo> appProcessList = activityManager.getRunningAppProcesses();
ApplicationInfo appInfo = null;
AppProcessInfo abAppProcessInfo = null;
PackageInfo packageInfo = getPackageInfo(context);
if (mProcessList != null) {
mProcessList.clear();
}
mProcessList = getProcessRunningInfo();
for (RunningAppProcessInfo appProcessInfo : appProcessList) {
abAppProcessInfo = new AppProcessInfo(appProcessInfo.processName, appProcessInfo.pid, appProcessInfo.uid);
appInfo = getApplicationInfo(context, appProcessInfo.processName);
if (appInfo != null) {
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
abAppProcessInfo.isSystem = true;
} else {
abAppProcessInfo.isSystem = false;
}
Drawable icon = appInfo.loadIcon(packageManager);
String appName = appInfo.loadLabel(packageManager).toString();
abAppProcessInfo.icon = icon;
abAppProcessInfo.appName = appName;
} else {
// :服务的命名
if (appProcessInfo.processName.indexOf(":") != -1) {
appInfo = getApplicationInfo(context, appProcessInfo.processName.split(":")[0]);
Drawable icon = appInfo.loadIcon(packageManager);
abAppProcessInfo.icon = icon;
}
abAppProcessInfo.isSystem = true;
abAppProcessInfo.appName = appProcessInfo.processName;
}
/*
* AbPsRow psRow = getPsRow(appProcessInfo.processName);
* if(psRow!=null){ abAppProcessInfo.memory = psRow.mem; }
*/
ProcessInfo processInfo = getMemInfo(appProcessInfo.processName);
abAppProcessInfo.memory = processInfo.memory;
abAppProcessInfo.cpu = processInfo.cpu;
abAppProcessInfo.status = processInfo.status;
abAppProcessInfo.threadsCount = processInfo.threadsCount;
list.add(abAppProcessInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by ResurrectionRemix.
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;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project LshUtils by SenhLinsh.
the class AppUtils method gc.
/**
* 清理后台进程与服务
*
* @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 DroidPlugin by DroidPluginTeam.
the class PluginProcessManager method getCurrentProcessName.
public static String getCurrentProcessName(Context context) {
if (context == null)
return sCurrentProcessName;
synchronized (sGetCurrentProcessNameLock) {
if (sCurrentProcessName == null) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> infos = activityManager.getRunningAppProcesses();
if (infos == null)
return null;
for (RunningAppProcessInfo info : infos) {
if (info.pid == android.os.Process.myPid()) {
sCurrentProcessName = info.processName;
return sCurrentProcessName;
}
}
}
}
return sCurrentProcessName;
}
Aggregations