How can some applications still get current application processes and kill them?

Background

In the past, I found the following method of killing application background processes, given its package name:

public static boolean killApp(final Context context, final String packageName) { final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); final List<ActivityManager.RunningAppProcessInfo> pids = am.getRunningAppProcesses(); for (int i = 0; i < pids.size(); i++) { final ActivityManager.RunningAppProcessInfo info = pids.get(i); if (info.processName.equals(packageName)) { android.os.Process.killProcess(info.pid); if (new File("/system/bin/kill").exists()) { InputStream inputStream = null; try { inputStream = Runtime.getRuntime().exec("kill -9 " + info.pid).getInputStream(); final byte[] buffer = new byte[100]; inputStream.read(buffer); } catch (final IOException e) { } StreamsUtil.closeStream(inputStream); } am.killBackgroundProcesses(packageName); return true; } } am.killBackgroundProcesses(packageName); return false; } 

Problem

Since a certain version of Android (5.1), the function for obtaining a list of running processes returns only current application processes, so it is completely useless to use it.

What i found

  • Most applications on the Play Store do not really display a list of processes, but instead show only the current application process or list of services at best.

  • It seems that some applications still manage to show the background processes of the applications and even be able to kill them. As an example, I found an AVG app capable of doing this here .

    Before they can do this, they tell the user to enable usage statistics for the application, which, as I recall, are used to check general information about the time the applications started.

  • Another application that has managed to kill background processes, but without any user confirmation, is the " fast task killer ." It also shows a toast of all processes to be killed. I could be wrong, but it seems that there are always as many tasks.

  • I also think that there is a relatively simple way to get a list of processes using the ps function, but only if the device is deployed (otherwise it will return only the current application processes).

  • There was a workaround with the library found here (published here ), but this does not seem to work on Android 7.1.2 and most likely in previous versions.

Question

How do applications get a list of applications with background processes and how do they kill them?

Can this be done without using the UsageStatsManager class?

+5
source share

Source: https://habr.com/ru/post/1265781/


All Articles