use of android.app.ActivityManager.RunningAppProcessInfo in project ZI by yixia.
the class ProcessHelper method isProcessRunning.
public static boolean isProcessRunning(Context ctx, String name) {
ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
for (RunningAppProcessInfo app : apps) {
if (app.processName.equals(name)) {
return true;
}
}
return false;
}
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 android_frameworks_base by AOSPA.
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 android_frameworks_base by ResurrectionRemix.
the class DevUtils method killForegroundApplication.
/**
* Kills the top most / most recent user application, but leaves out the launcher.
* This is function governed by {@link Settings.Secure.KILL_APP_LONGPRESS_BACK}.
*
* @param context the current context, used to retrieve the package manager.
* @return {@code true} when a user application was found and closed.
*/
public static boolean killForegroundApplication(Context context) {
boolean targetKilled = false;
try {
final Intent intent = new Intent(Intent.ACTION_MAIN);
String defaultHomePackage = "com.android.launcher";
intent.addCategory(Intent.CATEGORY_HOME);
final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0);
if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
defaultHomePackage = res.activityInfo.packageName;
}
IActivityManager am = ActivityManagerNative.getDefault();
List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
for (RunningAppProcessInfo appInfo : apps) {
int uid = appInfo.uid;
// root, phone, etc.)
if (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID && appInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
if (appInfo.pkgList != null && (appInfo.pkgList.length > 0)) {
for (String pkg : appInfo.pkgList) {
if (!pkg.equals("com.android.systemui") && !pkg.equals(defaultHomePackage)) {
am.forceStopPackage(pkg, UserHandle.USER_CURRENT);
targetKilled = true;
break;
}
}
} else {
Process.killProcess(appInfo.pid);
targetKilled = true;
break;
}
}
}
} catch (RemoteException remoteException) {
// Do nothing; just let it go.
}
return targetKilled;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project android_frameworks_base by ResurrectionRemix.
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;
}
Aggregations