Search in sources :

Example 51 with RunningAppProcessInfo

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

Example 52 with RunningAppProcessInfo

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) {
        // 前台进程。
        }
    }
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ArrayList(java.util.ArrayList) ActivityManager(android.app.ActivityManager)

Example 53 with RunningAppProcessInfo

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

Example 54 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 55 with RunningAppProcessInfo

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

Aggregations

RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)61 ActivityManager (android.app.ActivityManager)52 ArrayList (java.util.ArrayList)9 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)8 IOException (java.io.IOException)8 IActivityManager (android.app.IActivityManager)6 Context (android.content.Context)6 Build (android.os.Build)6 RemoteException (android.os.RemoteException)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 Fingerprint (android.hardware.fingerprint.Fingerprint)5 MemoryInfo (android.os.Debug.MemoryInfo)5 SuppressLint (android.annotation.SuppressLint)4 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)4 TestCrashException (com.microsoft.appcenter.crashes.model.TestCrashException)4 Device (com.microsoft.appcenter.ingestion.models.Device)4