Search in sources :

Example 31 with RunningAppProcessInfo

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;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager)

Example 32 with RunningAppProcessInfo

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();
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) AndroidAppProcess(com.wenming.library.processutil.models.AndroidAppProcess) ArrayList(java.util.ArrayList) ActivityManager(android.app.ActivityManager)

Example 33 with RunningAppProcessInfo

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;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) RemoteException(android.os.RemoteException) Fingerprint(android.hardware.fingerprint.Fingerprint)

Example 34 with RunningAppProcessInfo

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;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) Intent(android.content.Intent) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 35 with RunningAppProcessInfo

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;
}
Also used : MemoryInfo(android.os.Debug.MemoryInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) IActivityManager(android.app.IActivityManager)

Aggregations

RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)35 ActivityManager (android.app.ActivityManager)27 IActivityManager (android.app.IActivityManager)6 RemoteException (android.os.RemoteException)6 Fingerprint (android.hardware.fingerprint.Fingerprint)5 MemoryInfo (android.os.Debug.MemoryInfo)5 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)4 Context (android.content.Context)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)4 Build (android.os.Build)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 PackageInfo (android.content.pm.PackageInfo)3 PackageManager (android.content.pm.PackageManager)3 SuppressLint (android.annotation.SuppressLint)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 Drawable (android.graphics.drawable.Drawable)2 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)2