Export to GitHub

android-developer-preview - issue #2347

ActivityManager getRunningAppProcesses not woking


Posted on Jun 9, 2015 by Happy Rhino

* Which version of the SDK are you using? - Android M(Preview)

* Which Android build are you using? (e.g. MPZ44Q) - MPZ44Q

* What device are you using? - Nexus 5

* What steps will reproduce the problem? (Please provide the minimal reproducible test case.) 1. new Thread Start in Button Click
2. this Thread 50 seconds loop on log print (activitymanager.getRunningAppProcesses) 3. Home Button Click and another application start 4. activitymanager.getRunningAppProcesses() get list size returned only one.

* What is the expected output? -> background, foreground process list.

* What do you see instead? -> only my package info.

* Relevant logcat output.

06-09 15:23:02.210: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.349: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.381: W/ActivityManager(610): getRunningAppProcesses: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.477: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.499: W/ActivityManager(610): getRunningAppProcesses: caller 10179 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.499: I/ingho(15171): Package Name : com.ingho.testapp 06-09 15:23:02.500: W/ActivityManager(610): getRunningAppProcesses: caller 10179 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.500: I/ingho(15171): size : 1 06-09 15:23:02.618: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.757: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.884: W/ActivityManager(610): getRunningAppProcesses: caller 10151 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.904: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:02.927: W/ActivityManager(610): getRunningAppProcesses: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.047: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.190: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.223: I/WifiHAL(610): Got a scan results event 06-09 15:23:03.223: I/WifiHAL(610): Scan complete: Received event type 1 06-09 15:23:03.223: D/wifi(610): onScanStatus called, vm = 0xb4fee000, obj = 0x1006b6, env = 0x9f9608a0 06-09 15:23:03.224: I/WifiNative-HAL(610): Got a scan status changed event, status = 1 06-09 15:23:03.340: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.497: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.519: W/ActivityManager(610): getRunningAppProcesses: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.537: W/ActivityManager(610): getRunningAppProcesses: caller 10179 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.540: I/ingho(15171): Package Name : com.ingho.testapp 06-09 15:23:03.542: W/ActivityManager(610): getRunningAppProcesses: caller 10179 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.544: I/ingho(15171): size : 1 06-09 15:23:03.640: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.774: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.933: W/ActivityManager(610): getTasks: caller 10177 does not hold REAL_GET_TASKS; limiting output 06-09 15:23:03.944: W/ActivityManager(610): getRunningAppProcesses: caller 10151 does not hold REAL_GET_TASKS; limiting output

* Optional: Link to any screenshot(s) that demonstrate the issue (shared privately in Drive.) * Optional: Link to captured Android bug report (shared privately in Drive.) * Optional: Link to your APK (either downloadable in Drive or in the Play Store.)

To avoid leaking private information, please share screenshots and downloads only in Google Drive. Share files with android-dev-preview- bugreport@google.com and include only links in your bug reports. Attachments can not be included directly in issue reports.

Comment #1

Posted on Jun 16, 2015 by Massive Elephant

Thank you for reporting this issue. We have passed this on to the development team and will update this issue with more information as it becomes available.

Comment #2

Posted on Jun 17, 2015 by Happy Rhino

Comment deleted

Comment #3

Posted on Jul 7, 2015 by Happy Monkey

I'm also running into this on build MPZ44Q, on a Nexus 6. Here's a little more information that might be helpful:

  • In my app manifest I have a 'uses-permission' section for android.permission.GET_TASKS (although this is marked as deprecated).

  • This is a behavior change between the latest official Lollipop version and the new preview. My code that appears broke on the M preview works fine on any Lollipop version.

  • In my Gradle build file I'm currently setting 'buildToolsVersion' to 22.0.1, and 'targetSdkVersion' to 22.

Comment #4

Posted on Jul 8, 2015 by Massive Elephant

Thank you for providing this feedback. We have taken a look at the issue. This is the intended behavior. Applications must now have ...permission.REAL_GET_TASKS to be able to get process information for all applications. Only the process information for the calling application will be returned if the app doesn't have the permission. Privileges apps will temporarily be able to get process information for all applications if they don't have the new permission, but have deprecated ...permission.GET_TASKS Also,only system apps can acquire the REAL_GET_TASKS permission.

Comment #5

Posted on Jul 8, 2015 by Happy Monkey

Thank you for the update. Is support being dropped for non-Google app access to this information or is there an equivalent API or permission that can be obtained (by 3rd party apps) that can be used still?

Comment #6

Posted on Jul 9, 2015 by Happy Rhino

Comment deleted

Comment #7

Posted on Jul 9, 2015 by Happy Rhino

i have not appRunningProcess need GET_TASKS permission in Lollipop(5.1.1).

If M version changed appRunningProcess, is appRunningProcess need to add REAL_GET_TASKS?

Comment #8

Posted on Jul 13, 2015 by Quick Elephant

@5 You can use UsageStatsManager (requires user confirmation) : http://stackoverflow.com/q/26431795/878126 This is from Lollipop.

Comment #9

Posted on Aug 13, 2015 by Grumpy Horse

Comment deleted

Comment #10

Posted on Aug 13, 2015 by Grumpy Camel

Please, give us workaround...

Comment #11

Posted on Aug 13, 2015 by Grumpy Camel

Our application just need to know top activity, to restart it automaticaly... What to do now?

UsageStatsManager is not user friendly solutution.

Comment #12

Posted on Aug 13, 2015 by Helpful Bear

Why comment# 2,6,9 is not shown?

Comment #13

Posted on Aug 13, 2015 by Happy Rhino

12 if delete a comment maybe skip number

Comment #14

Posted on Aug 19, 2015 by Massive Elephant

Issue 2984 has been merged into this issue.

Comment #15

Posted on Aug 20, 2015 by Grumpy Rhino

My app monitors what background processes are alive using this mechanism. Is there any alternative way of doing this or have I just been stuffed?

Comment #16

Posted on Aug 20, 2015 by Happy Giraffe

15 you can use the usagestatsmanager api instead.

Comment #17

Posted on Aug 20, 2015 by Grumpy Rhino

16 Thanks for the help, I'm not entirely sure how this works though. I'm playing with it and I can clearly see the app coming into the foreground and going into the background events but should I see a NONE event when the process is killed? I'm trying with the calculator, when I swipe it away from the recent app list or force stop I see no NONE event. Without this I have no way to know if the app is currently alive in the BG right now.

Comment #18

Posted on Aug 20, 2015 by Happy Giraffe

17 Well, I haven't tested it much, I only need it to get the current foreground app, to show or hide a floating icon. The lack of proper documentation does not help either... so you have to play with it more, that's all I can suggest :)

Comment #19

Posted on Aug 20, 2015 by Massive Elephant

(No comment was entered for this change.)

Comment #20

Posted on Aug 21, 2015 by Happy Wombat

It looks like this change was dropped into the latest Lollipop patch (for Stagefright I believe). I updated a NEXUS6 device and my code with that API is no longer working:

Nexus6 running 5.1.1: Build LMY47Z (pre-system-update-patch) – WORKS OK Nexus6 running 5.1.1: Build LMY48L (post-system-update-patch) – BROKEN

I find it hard to understand why a major API like that would get changed in a security patch? I would think lot of apps would unexpectedly break over this.

Comment #21

Posted on Aug 28, 2015 by Grumpy Bird

Also it isn't working in Spice Android One and Sony XPeria Z2 (both having Android 5.1).

Comment #22

Posted on Aug 31, 2015 by Quick Elephant

Is there any workaround for this? I keep getting only a single item...

Comment #23

Posted on Aug 31, 2015 by Happy Giraffe

22 You can use the new UsageStatsManager API instead.

Comment #24

Posted on Aug 31, 2015 by Quick Elephant

Comment deleted

Comment #25

Posted on Aug 31, 2015 by Quick Elephant

@23 That's what I'll do, but I wanted to have a fallback in case the user doesn't confirm this. Sadly, there are just too many confirmation dialogs starting with Android 5 and 6 , as permissions are required to have dialogs, and so does this API, and also allowing to access the storage... As both a user and developer, I find it all very annoying.

In any case, the "getRunningAppProcesses" is supposed to get you the currently running processes, but now you can't do it anymore. The UsageStatsManager doesn't provide the same functionality.

Comment #26

Posted on Sep 3, 2015 by Swift Kangaroo

It's big problem for us. Please, give us workaround.

Comment #27

Posted on Sep 3, 2015 by Quick Lion

Please provide us work around without user interaction..

Comment #28

Posted on Sep 8, 2015 by Massive Monkey

Google follows Ios. Soon we can't do anything on android....

Comment #29

Posted on Sep 9, 2015 by Grumpy Rabbit

I'm encountering this bug in 5.1.1 build number LMY48I. Adding the REAL_GET_TASKS permission obviously didn't solve the issue. Has anyone a workaround other then using Usage Stats?

Comment #30

Posted on Sep 9, 2015 by Quick Elephant

@29 Maybe it's possible on rooted devices, by using the "top" command ?

Comment #31

Posted on Sep 11, 2015 by Massive Ox

Comment deleted

Comment #32

Posted on Sep 11, 2015 by Quick Elephant

Comment deleted

Comment #33

Posted on Sep 11, 2015 by Massive Ox

Comment deleted

Comment #34

Posted on Sep 17, 2015 by Happy Giraffe

I would like to add that this kind of feature is mandatory to develop B2B app, where you need to know which application is being used by the user. It is really frustrating to face such a problem, Google should pay more attention before deprecate something without giving a work around. In our case, we have no clue how to solve this problem without hacking around (using usage status, etc). Please, give us a way to solve this problem.

Comment #35

Posted on Sep 18, 2015 by Massive Kangaroo

Please provide us finally a workaround! Why did google just make methods not working anymore, silently, while not updating the docs, while not giving a simple workaround. But anyway, why should an application not be able to see running processes? Getting real tired of this stuff.

Comment #36

Posted on Sep 23, 2015 by Swift Lion

Pretty unacceptable to just break the APIs with no notice and then have people say "Use this other API that doesn't do the same thing and also requires a system permission"

Comment #37

Posted on Sep 23, 2015 by Quick Elephant

@36 Sadly, this is about what's going on...

Comment #38

Posted on Sep 24, 2015 by Grumpy Rabbit

@36 @37 I'm using the solution proposed here: http://stackoverflow.com/a/32366476/2249774 it's not ideal... but at least it's working.

Comment #39

Posted on Sep 24, 2015 by Quick Elephant

@38 They are not ordered by which app started first or any similar order. They are ordered by id... :(

Comment #40

Posted on Oct 15, 2015 by Massive Elephant

As per the comment#4, This is working as intended

Comment #41

Posted on Oct 15, 2015 by Quick Elephant

@40 What should apps that need this do? REAL_GET_TASKS is only for system apps... What's the purpose of these restrictions anyway? Apps can alreay know which apps are installed, so it's not about privacy/security ...

Comment #42

Posted on Oct 15, 2015 by Massive Kangaroo

Comment deleted

Comment #43

Posted on Oct 15, 2015 by Massive Kangaroo

Well actually it is about "privacy/security". Think about the System_Alerts that an app could display if you open your Amazon app, to fish for passwords etc.. But nevertheless, please make it more clear next time and deprecate it more early OR well...update the docs at least.

I think this is a result of a lack in more intrusive permissions. Yes, to fetch the currently running applications might be a an app that tries to run malicious code. But there are still valid reasons for this functionallity. So instead of a restriction, maybe be more intrusive at some specific permission, at an install. I know that this is a throwback in usability - but ...don't be apple ;)

Comment #44

Posted on Oct 16, 2015 by Quick Elephant

@43 It can't be about it, because I can already know which apps are installed, and I don't even need a permission for that. What difference does it make to know about running apps vs non-running apps? How would you get passwords from other apps? They are on the foreground, not your app. You can't even know what's shown on those apps, and even if you could, you'd see "*" instead of real characters (unless you talk about the keyboard, which you actually can know which one is the default one). In order to see what other apps show, Android already asks the user if it's ok to record/monitor the screen, and it also shows an icon for this on the status bar.

Comment #45

Posted on Oct 21, 2015 by Massive Kangaroo

Example: Amazon starts -> I start a Dialog, which looks like one from Amazon and asking for logging in. The Window for the Dialog has the FLAG System_Alert and the user thinks it is really amazon. Now I have the password and buy myself pizza.

Comment #46

Posted on Oct 21, 2015 by Quick Elephant

@45 But you would have to also know when to show it. Just seeing which app is recently launched doesn't mean its current screen is about to ask the user for information.

Also, making your app fake a dialog of another app is always possible anyway. You can do it even without this permission. Just make a notification that look like the one of Amazon, asking the user to give new credentials, and you show your dialog when the user clicks on it.

Comment #47

Posted on Oct 21, 2015 by Massive Ox

You can still get a list of running processes on Android 5.1.1+. Here is a small library I wrote: https://github.com/jaredrummler/AndroidProcesses Some system applications may not show up in the list if SELinux is enforcing.

Comment #48

Posted on Oct 21, 2015 by Massive Kangaroo

@46 I think your arguements are valid, but I assume that this is nevertheless the reason from the google devs for the restriction.

@47 Wow thanks for sharing your libary with us! How up-to-date is the list of running processes of your implementation? I mean, how fast if an application process gets started, it is available through your libary?

Comment #49

Posted on Oct 21, 2015 by Quick Elephant

@48 The library looks a lot like the stackOverflow post: http://stackoverflow.com/a/32366476/2249774

Does it provide more info? For example, which process is newer or on top?

Comment #50

Posted on Oct 21, 2015 by Massive Kangaroo

@49 The reason for that is, that @47 is the author of the stackoverflow post and the libary, too. As he stated out in the post on sof: "It is ordered by pid. It is basically the same as top. I used ps because I know it has been apart of /system/bin/toolbox for along time. I believe both ps and top get info from /proc/[pid]/stat"

Comment #51

Posted on Oct 21, 2015 by Quick Elephant

@50 Question is if they are the same or the library has more to offer. Also, I think ordering by pid doesn't mean which process is on top or anything else.

getRunningAppProcesses gives you more info.

Status: WontFix

Labels:
Type-Defect Release-M Defect-21863800