use of android.app.ActivityManager.RunningAppProcessInfo in project MLib by DaoBillTang.
the class SystemUtils method isAppRunning.
/**
* 判断某个应用当前是否正在运行
*
* @param context
* @param packageName
* @return
*/
public static boolean isAppRunning(Context context, String packageName) {
if (packageName == null) {
return false;
}
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses == null) {
return false;
}
for (RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.processName.equals(packageName)) {
return true;
}
}
return false;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project DroidPlugin by DroidPluginTeam.
the class MyActivityManagerService method runProcessGC.
// 运行进程GC
private void runProcessGC() {
if (mHostContext == null) {
return;
}
ActivityManager am = (ActivityManager) mHostContext.getSystemService(Context.ACTIVITY_SERVICE);
if (am == null) {
return;
}
List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();
List<RunningAppProcessInfo> myInfos = new ArrayList<RunningAppProcessInfo>();
if (infos == null || infos.size() < 0) {
return;
}
List<String> pns = mStaticProcessList.getOtherProcessNames();
pns.add(mHostContext.getPackageName());
for (RunningAppProcessInfo info : infos) {
if (info.uid == android.os.Process.myUid() && info.pid != android.os.Process.myPid() && !pns.contains(info.processName) && mRunningProcessList.isPlugin(info.pid) && !mRunningProcessList.isPersistentApplication(info.pid)) /*&& !mRunningProcessList.isPersistentApplication(info.pid)*/
{
myInfos.add(info);
}
}
Collections.sort(myInfos, sProcessComparator);
for (RunningAppProcessInfo myInfo : myInfos) {
if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_GONE) {
doGc(myInfo);
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_EMPTY) {
doGc(myInfo);
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
doGc(myInfo);
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) {
doGc(myInfo);
} else /*else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE) {
//杀死进程,不能保存状态。但是关我什么事?
}*/
if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) {
// 杀死进程
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
// 看得见
} else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
// 前台进程。
}
}
}
use of android.app.ActivityManager.RunningAppProcessInfo in project VirtualAPK by didi.
the class MyUtils method getProcessName.
public static String getProcessName(Context cxt, int pid) {
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
if (runningApps == null) {
return null;
}
for (RunningAppProcessInfo procInfo : runningApps) {
if (procInfo.pid == pid) {
return procInfo.processName;
}
}
return null;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project AndroidProcess by wenmingvs.
the class ProcessManager method getRunningAppProcessInfo.
/**
* Returns a list of application processes that are running on the device.
* <p/>
* <p><b>NOTE:</b> On Lollipop (SDK 22) this does not provide
* {@link RunningAppProcessInfo#pkgList},
* {@link RunningAppProcessInfo#importance},
* {@link RunningAppProcessInfo#lru},
* {@link RunningAppProcessInfo#importanceReasonCode},
* {@link RunningAppProcessInfo#importanceReasonComponent},
* {@link RunningAppProcessInfo#importanceReasonPid},
* etc. If you need more process information try using
* {@link #getRunningAppProcesses()} or {@link android.app.usage.UsageStatsManager}</p>
*
* @param ctx the application context
* @return a list of RunningAppProcessInfo records, or null if there are no
* running processes (it will not return an empty list). This list ordering is not
* specified.
*/
public static List<RunningAppProcessInfo> getRunningAppProcessInfo(Context ctx) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
List<AndroidAppProcess> runningAppProcesses = ProcessManager.getRunningAppProcesses();
List<RunningAppProcessInfo> appProcessInfos = new ArrayList<>();
for (AndroidAppProcess process : runningAppProcesses) {
RunningAppProcessInfo info = new RunningAppProcessInfo(process.name, process.pid, null);
info.uid = process.uid;
// TODO: Get more information about the process. pkgList, importance, lru, etc.
appProcessInfos.add(info);
}
return appProcessInfos;
}
ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
return am.getRunningAppProcesses();
}
use of android.app.ActivityManager.RunningAppProcessInfo in project realm-java by realm.
the class Utils method getMyProcessName.
public static String getMyProcessName(Context context) {
String processName = "";
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> infoList = am.getRunningAppProcesses();
if (infoList == null) {
throw new RuntimeException("getRunningAppProcesses() returns 'null'.");
}
for (RunningAppProcessInfo info : infoList) {
try {
if (info.pid == Process.myPid()) {
processName = info.processName;
break;
}
} catch (Exception ignored) {
}
}
return processName;
}
Aggregations