com.jaredrummler.android.processes.AndroidProcesses Java Examples

The following examples show how to use com.jaredrummler.android.processes.AndroidProcesses. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CoreService.java    From MemoryCleaner with Apache License 2.0 5 votes vote down vote up
@Override protected Long doInBackground(Void... params) {
    long beforeMemory = 0;
    long endMemory = 0;
    ActivityManager.MemoryInfo memoryInfo
            = new ActivityManager.MemoryInfo();
    activityManager.getMemoryInfo(memoryInfo);
    beforeMemory = memoryInfo.availMem;
    List<ActivityManager.RunningAppProcessInfo> appProcessList
            = AndroidProcesses.getRunningAppProcessInfo(mContext);
    ApplicationInfo appInfo = null;
    for (ActivityManager.RunningAppProcessInfo info : appProcessList) {
        String packName = info.processName;
        try {
            packageManager.getApplicationInfo(info.processName, 0);
        } catch (PackageManager.NameNotFoundException e) {
            appInfo = getApplicationInfo(
                    info.processName.split(":")[0]);
            if (appInfo != null) {
                packName = info.processName.split(":")[0];
            }
        }
        List<Ignore> ignores = mFinalDb.findAllByWhere(Ignore.class,
                "packName='" + packName + "'");
        if (ignores.size() == 0) {
            L.e(info.processName);
            killBackgroundProcesses(info.processName);
        }
    }
    activityManager.getMemoryInfo(memoryInfo);
    endMemory = memoryInfo.availMem;
    return endMemory - beforeMemory;
}
 
Example #2
Source File: AndroidAppProcessLoader.java    From AndroidProcesses with Apache License 2.0 5 votes vote down vote up
@Override protected List<AndroidAppProcess> doInBackground(Void... params) {
  List<AndroidAppProcess> processes = AndroidProcesses.getRunningAppProcesses();

  // sort by app name
  Collections.sort(processes, new Comparator<AndroidAppProcess>() {

    @Override public int compare(AndroidAppProcess lhs, AndroidAppProcess rhs) {
      return Utils.getName(context, lhs).compareToIgnoreCase(Utils.getName(context, rhs));
    }
  });

  return processes;
}
 
Example #3
Source File: App.java    From AndroidProcesses with Apache License 2.0 5 votes vote down vote up
@Override public void onCreate() {
  super.onCreate();
  AndroidProcesses.setLoggingEnabled(true);
  Picasso.setSingletonInstance(new Picasso.Builder(this)
      .addRequestHandler(new AppIconRequestHandler(this))
      .build());
}
 
Example #4
Source File: ProcessManagerEngine.java    From MobileGuard with MIT License 4 votes vote down vote up
/**
 * get running processes info by proc
 * @param context
 * @return
 */
public static List<ProcessInfoBean> getRunningProcessesInfoByProc(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager pm = context.getPackageManager();
    // get running app processes info
    List<AndroidAppProcess> processes = AndroidProcesses.getRunningAppProcesses();
    // create list. Specific it init size
    List<ProcessInfoBean> infos = new ArrayList<>(processes.size());
    for (AndroidAppProcess process: processes) {
        // create bean
        ProcessInfoBean bean = new ProcessInfoBean();
        // get package name
        bean.setPackageName(process.getPackageName());
        // check empty
        if(TextUtils.isEmpty(bean.getPackageName())) {
            continue;
        }
        // get package info
        ApplicationInfo applicationInfo = null;
        try {
            applicationInfo = pm.getApplicationInfo(bean.getPackageName(), PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            // if package is empty, continue
            continue;
        }
        // set icon
        bean.setIcon(applicationInfo.loadIcon(pm));
        // app name
        bean.setAppName(applicationInfo.loadLabel(pm).toString());
        // system app
        if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            bean.setSystemApp(true);
        }// if not, need set false. Actually it was.
        // memory
        Debug.MemoryInfo[] processMemoryInfo = am.getProcessMemoryInfo(new int[]{process.pid});
        if (processMemoryInfo.length >= 1) {
            bean.setMemory(processMemoryInfo[0].getTotalPss() * 1024);
        }
        // add to list
        infos.add(bean);
    }
    return infos;
}
 
Example #5
Source File: TaskController.java    From batteryhub with Apache License 2.0 4 votes vote down vote up
private List<Task> getRunningTasksStandard() {
    List<Task> tasks = new ArrayList<>();
    List<AndroidAppProcess> list = AndroidProcesses.getRunningAppProcesses();

    if (list == null) return tasks;

    for (AndroidAppProcess process : list) {
        /* Exclude the app itself from the list */
        if (process.name.equals(BuildConfig.APPLICATION_ID)) continue;

        PackageInfo packageInfo = getPackageInfo(process, 0);

        if (packageInfo == null) continue;

        /* Remove system apps if necessary */
        if (isSystemApp(packageInfo) && SettingsUtils.isSystemAppsHidden(mContext)) {
            continue;
        }

        /* Remove apps without label */
        if (packageInfo.applicationInfo == null) continue;

        String appLabel = packageInfo.applicationInfo.loadLabel(mPackageManager).toString();

        if (appLabel.isEmpty()) continue;

        Task task = getTaskByUid(tasks, process.uid);

        if (task == null) {
            task = new Task(process.uid, process.name);
            task.setPackageInfo(packageInfo);
            task.setLabel(appLabel);
            task.setMemory(getMemoryFromProcess(process));
            task.setIsAutoStart(isAutoStartApp(process.getPackageName()));
            task.setHasBackgroundService(hasBackgroundServices(process.getPackageName()));
            task.getProcesses().add(process.pid);
            tasks.add(task);
        } else {
            task.getProcesses().add(process.pid);
            task.setMemory(task.getMemory() + getMemoryFromProcess(process));
        }
    }

    if (!tasks.isEmpty()) {
        // Dirty quick sorting
        Collections.sort(tasks, new Comparator<Task>() {
            @Override
            public int compare(Task t1, Task t2) {
                return t1.getLabel().compareTo(t2.getLabel());
            }
        });
    }

    return tasks;
}