Search in sources :

Example 1 with AndroidAppProcess

use of com.jaredrummler.android.processes.models.AndroidAppProcess in project AnExplorer by 1hakr.

the class AppsProvider method getRunningAppProcessInfo.

/**
 * Returns a list of application processes that are running on the device.
 *
 * @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) {
    ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> appProcessInfos = new ArrayList<>();
    String prevProcess = "";
    if (Utils.hasNougat()) {
        List<RunningServiceInfo> runningServices = am.getRunningServices(1000);
        for (RunningServiceInfo process : runningServices) {
            RunningAppProcessInfo info = new RunningAppProcessInfo(process.process, process.pid, null);
            info.uid = process.uid;
            info.importance = process.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
            if (!prevProcess.equals(process.process)) {
                prevProcess = process.process;
                appProcessInfos.add(info);
            }
        }
        return appProcessInfos;
    } else if (Utils.hasLollipopMR1()) {
        List<AndroidAppProcess> runningAppProcesses = AndroidProcesses.getRunningAppProcesses();
        for (AndroidAppProcess process : runningAppProcesses) {
            RunningAppProcessInfo info = new RunningAppProcessInfo(process.name, process.pid, null);
            info.uid = process.uid;
            info.importance = process.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
            // TODO: Get more information about the process. pkgList, importance, lru, etc.
            appProcessInfos.add(info);
        }
        return appProcessInfos;
    }
    return am.getRunningAppProcesses();
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) AndroidAppProcess(com.jaredrummler.android.processes.models.AndroidAppProcess) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ActivityManager(android.app.ActivityManager)

Example 2 with AndroidAppProcess

use of com.jaredrummler.android.processes.models.AndroidAppProcess in project AnExplorer by 1hakr.

the class AppsProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder) throws FileNotFoundException {
    final MatrixCursor result = new DocumentCursor(resolveDocumentProjection(projection), docId);
    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    try {
        if (docId.startsWith(ROOT_ID_USER_APP)) {
            List<PackageInfo> allAppList = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
            for (PackageInfo packageInfo : allAppList) {
                includeAppFromPackage(result, docId, packageInfo, false, null);
            }
        } else if (docId.startsWith(ROOT_ID_SYSTEM_APP)) {
            List<PackageInfo> allAppList = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
            for (PackageInfo packageInfo : allAppList) {
                includeAppFromPackage(result, docId, packageInfo, true, null);
            }
        } else if (docId.startsWith(ROOT_ID_PROCESS)) {
            if (Utils.hasNougat()) {
                List<RunningServiceInfo> runningServices = activityManager.getRunningServices(1000);
                for (RunningServiceInfo process : runningServices) {
                    includeAppFromService(result, docId, process, null);
                }
            } else if (Utils.hasLollipopMR1()) {
                List<AndroidAppProcess> runningAppProcesses = AndroidProcesses.getRunningAppProcesses();
                for (AndroidAppProcess process : runningAppProcesses) {
                    includeAppFromProcess(result, docId, process, null);
                }
            } else {
                List<RunningAppProcessInfo> runningProcessesList = activityManager.getRunningAppProcesses();
                for (RunningAppProcessInfo processInfo : runningProcessesList) {
                    includeAppFromProcess(result, docId, processInfo, null);
                }
            }
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) PackageInfo(android.content.pm.PackageInfo) RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) AndroidAppProcess(com.jaredrummler.android.processes.models.AndroidAppProcess) ArrayList(java.util.ArrayList) List(java.util.List) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Aggregations

RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)2 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)2 AndroidAppProcess (com.jaredrummler.android.processes.models.AndroidAppProcess)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ActivityManager (android.app.ActivityManager)1 PackageInfo (android.content.pm.PackageInfo)1 MatrixCursor (dev.dworks.apps.anexplorer.cursor.MatrixCursor)1