com.jaredrummler.android.processes.models.AndroidAppProcess Java Examples
The following examples show how to use
com.jaredrummler.android.processes.models.AndroidAppProcess.
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: ProcessListAdapter.java From AndroidProcesses with Apache License 2.0 | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { convertView = inflater.inflate(R.layout.list_item_process, parent, false); holder = new ViewHolder(convertView); } else { holder = (ViewHolder) convertView.getTag(); } AndroidAppProcess process = getItem(position); ImageView imageView = holder.find(R.id.imageView); TextView textView = holder.find(R.id.textView); picasso.load(Uri.parse(SCHEME_PNAME + ":" + process.getPackageName())) .placeholder(android.R.drawable.sym_def_app_icon) .resize(iconSize, iconSize) .centerInside() .into(imageView); textView.setText(Utils.getName(context, process)); return convertView; }
Example #2
Source File: AndroidProcesses.java From AndroidProcesses with Apache License 2.0 | 5 votes |
/** * @return {@code true} if this process is in the foreground. */ public static boolean isMyProcessInTheForeground() { try { return new AndroidAppProcess(android.os.Process.myPid()).foreground; } catch (Exception e) { log(e, "Error finding our own process"); } return false; }
Example #3
Source File: ProcessListAdapter.java From AndroidProcesses with Apache License 2.0 | 5 votes |
public ProcessListAdapter(Context context, List<AndroidAppProcess> processes) { this.context = context.getApplicationContext(); this.inflater = LayoutInflater.from(context); this.iconSize = Utils.toPx(context, 46); this.picasso = Picasso.with(context); this.processes = processes; }
Example #4
Source File: TaskController.java From batteryhub with Apache License 2.0 | 5 votes |
private double getMemoryFromProcess(AndroidAppProcess process) { double memory = 0; try { Statm statm = process.statm(); if (statm != null) { // Memory in MB memory = statm.getResidentSetSize() / 1024.0 / 1024.0; } } catch (IOException e) { e.printStackTrace(); } return Math.round(memory * 100.0) / 100.0; }
Example #5
Source File: TaskController.java From batteryhub with Apache License 2.0 | 5 votes |
private PackageInfo getPackageInfo(AndroidAppProcess process, int flags) { PackageInfo packageInfo; try { packageInfo = process.getPackageInfo(mContext, flags); } catch (final PackageManager.NameNotFoundException e) { packageInfo = null; } return packageInfo; }
Example #6
Source File: ProcessInfoDialog.java From AndroidProcesses with Apache License 2.0 | 5 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AndroidAppProcess process = getArguments().getParcelable("process"); return new AlertDialog.Builder(getActivity()) .setTitle(Utils.getName(getActivity(), process)) .setMessage(getProcessInfo(process)) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .create(); }
Example #7
Source File: ProcessListFragment.java From AndroidProcesses with Apache License 2.0 | 5 votes |
@Override public void onListItemClick(ListView l, View v, int position, long id) { AndroidAppProcess process = (AndroidAppProcess) getListAdapter().getItem(position); ProcessInfoDialog dialog = new ProcessInfoDialog(); Bundle args = new Bundle(); args.putParcelable("process", process); dialog.setArguments(args); dialog.show(getActivity().getFragmentManager(), "ProcessInfoDialog"); }
Example #8
Source File: AndroidAppProcessLoader.java From AndroidProcesses with Apache License 2.0 | 5 votes |
@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 #9
Source File: Utils.java From AndroidProcesses with Apache License 2.0 | 5 votes |
public static String getName(Context context, AndroidAppProcess process) { try { PackageManager pm = context.getPackageManager(); PackageInfo packageInfo = process.getPackageInfo(context, 0); return AppNames.getLabel(pm, packageInfo); } catch (PackageManager.NameNotFoundException e) { return process.name; } }
Example #10
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 4 votes |
private void includeAppFromProcess(MatrixCursor result, String docId, AndroidAppProcess processInfo, String query ) { String process = processInfo.name; final String packageName = processInfo.getPackageName(); process = process.substring(process.lastIndexOf(".") + 1, process.length()); String summary = ""; String displayName = ""; ApplicationInfo appInfo = null; try { appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo; displayName = process ; } catch (Exception e) { } if (TextUtils.isEmpty(displayName)) { displayName = process; } if (null != query && !displayName.toLowerCase().contains(query)) { return; } final String path = null != appInfo ? appInfo.sourceDir : ""; final String mimeType = Document.MIME_TYPE_APK; int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL; if(isTelevision()) { flags |= Document.FLAG_DIR_PREFERS_GRID; } int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND; summary = processTypeCache.get(importance); final long size = getProcessSize(processInfo.pid); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName)); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); //row.add(Document.COLUMN_LAST_MODIFIED, lastModified); row.add(Document.COLUMN_PATH, path); row.add(Document.COLUMN_FLAGS, flags); }
Example #11
Source File: ProcessListAdapter.java From AndroidProcesses with Apache License 2.0 | 4 votes |
@Override public AndroidAppProcess getItem(int position) { return processes.get(position); }
Example #12
Source File: AndroidAppProcessLoader.java From AndroidProcesses with Apache License 2.0 | 4 votes |
@Override protected void onPostExecute(List<AndroidAppProcess> androidAppProcesses) { listener.onComplete(androidAppProcesses); }
Example #13
Source File: ProcessListFragment.java From AndroidProcesses with Apache License 2.0 | 4 votes |
@Override public void onComplete(List<AndroidAppProcess> processes) { setListAdapter(new ProcessListAdapter(getActivity(), processes)); }
Example #14
Source File: TaskController.java From batteryhub with Apache License 2.0 | 4 votes |
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; }
Example #15
Source File: ProcessManagerEngine.java From MobileGuard with MIT License | 4 votes |
/** * 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 #16
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 4 votes |
private void includeAppFromProcess(MatrixCursor result, String docId, AndroidAppProcess processInfo, String query ) { String process = processInfo.name; final String packageName = processInfo.getPackageName(); process = process.substring(process.lastIndexOf(".") + 1, process.length()); String summary = ""; String displayName = ""; ApplicationInfo appInfo = null; try { appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo; displayName = process ; } catch (Exception e) { } if (TextUtils.isEmpty(displayName)) { displayName = process; } if (null != query && !displayName.toLowerCase().contains(query)) { return; } final String path = null != appInfo ? appInfo.sourceDir : ""; final String mimeType = Document.MIME_TYPE_APK; int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL; if(isTelevision()) { flags |= Document.FLAG_DIR_PREFERS_GRID; } int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND; summary = processTypeCache.get(importance); final long size = getProcessSize(processInfo.pid); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName)); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); //row.add(Document.COLUMN_LAST_MODIFIED, lastModified); row.add(Document.COLUMN_PATH, path); row.add(Document.COLUMN_FLAGS, flags); }
Example #17
Source File: AppsProvider.java From FireFiles with Apache License 2.0 | 4 votes |
private void includeAppFromProcess(MatrixCursor result, String docId, AndroidAppProcess processInfo, String query ) { String process = processInfo.name; final String packageName = processInfo.getPackageName(); process = process.substring(process.lastIndexOf(".") + 1, process.length()); String summary = ""; String displayName = ""; ApplicationInfo appInfo = null; try { appInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).applicationInfo; displayName = process ; } catch (Exception e) { } if (TextUtils.isEmpty(displayName)) { displayName = process; } if (null != query && !displayName.toLowerCase().contains(query)) { return; } final String path = null != appInfo ? appInfo.sourceDir : ""; final String mimeType = Document.MIME_TYPE_APK; int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_THUMBNAIL; if(isTelevision()) { flags |= Document.FLAG_DIR_PREFERS_GRID; } int importance = processInfo.foreground ? RunningAppProcessInfo.IMPORTANCE_FOREGROUND : RunningAppProcessInfo.IMPORTANCE_BACKGROUND; summary = processTypeCache.get(importance); final long size = getProcessSize(processInfo.pid); final RowBuilder row = result.newRow(); row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForApp(docId, packageName)); row.add(Document.COLUMN_DISPLAY_NAME, displayName); row.add(Document.COLUMN_SUMMARY, summary); row.add(Document.COLUMN_SIZE, size); row.add(Document.COLUMN_MIME_TYPE, mimeType); //row.add(Document.COLUMN_LAST_MODIFIED, lastModified); row.add(Document.COLUMN_PATH, path); row.add(Document.COLUMN_FLAGS, flags); }
Example #18
Source File: AndroidProcesses.java From AndroidProcesses with Apache License 2.0 | 3 votes |
/** * Returns a list of application processes that are running on the device. * * <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 context * 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 context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { List<AndroidAppProcess> runningAppProcesses = AndroidProcesses.getRunningAppProcesses(); List<RunningAppProcessInfo> appProcessInfos = new ArrayList<>(); for (AndroidAppProcess process : runningAppProcesses) { RunningAppProcessInfo info = new RunningAppProcessInfo(process.name, process.pid, null); info.uid = process.uid; appProcessInfos.add(info); } return appProcessInfos; } ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); return am.getRunningAppProcesses(); }
Example #19
Source File: AndroidAppProcessLoader.java From AndroidProcesses with Apache License 2.0 | votes |
void onComplete(List<AndroidAppProcess> processes);