Wait for app to be idle from Activity Manager

524 views
Skip to first unread message

R V

unread,
Jun 29, 2011, 1:59:54 PM6/29/11
to android-...@googlegroups.com
I need to wait for an application to be idle from outside the app's process. This is similar to android.app.Instrumentation.waitForIdleSync(). Activity Manager may be the right place for implementing this. How do I implement this? Or, is there already something similar that I can use?

Dianne Hackborn

unread,
Jun 29, 2011, 7:49:53 PM6/29/11
to android-...@googlegroups.com
Why?

On Wed, Jun 29, 2011 at 10:59 AM, R V <rv00...@gmail.com> wrote:
I need to wait for an application to be idle from outside the app's process. This is similar to android.app.Instrumentation.waitForIdleSync(). Activity Manager may be the right place for implementing this. How do I implement this? Or, is there already something similar that I can use?

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.



--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

R V

unread,
Jun 30, 2011, 9:56:04 AM6/30/11
to android-...@googlegroups.com
Thanks Dianne.

I am writing a custom framework for monitoring and controlling arbitrary applications for testing purposes. The stock solution in Android is limited to one target app only. Moreover, if possible, I do not want to modify the instrumentation's target package each time I go about testing a new set of apps.

R V

unread,
Jun 30, 2011, 10:06:28 AM6/30/11
to android-...@googlegroups.com
I am able to get most of the functionality I need without using the instrumentation api but waiting for idle is turning out to be difficult.

Dianne Hackborn

unread,
Jun 30, 2011, 12:30:55 PM6/30/11
to android-...@googlegroups.com
Waiting for idle is only needed to be able to wait until an app has settled down before you start poking at its internal state.  If you are driving an app outside of your process, I don't see why you would need it...?

R V

unread,
Jun 30, 2011, 1:01:19 PM6/30/11
to android-...@googlegroups.com
Thanks for clarifying. May be I have misunderstood the whole thing.

What I need to do is that once I have given an input, I need to wait till the app has actually finished processing it, changed its internal state, with possibly the GUI that is visible. I was thinking waiting for idle may solve at least part of my job before I start poking into the app for the view hierarchy, etc.

I think wait for idle may possibly return before the GUI is completely ready but then I will be able to see some circular progress bars. Using this I can check if the GUI is ready.

What is it that will actually help me in this situation?

Dianne Hackborn

unread,
Jun 30, 2011, 3:21:14 PM6/30/11
to android-...@googlegroups.com
If you are sending events the same way that monkey does, you can send them synchronously so you block until the event has been delivered.

R V

unread,
Jun 30, 2011, 5:08:19 PM6/30/11
to android-...@googlegroups.com
Thanks Dianne for showing this direction.

I need some further clarification. I need to wait until the application is ready before I try to retrieve the UI info from it and decide the next input event. For example, a new window may be launched as a result of injecting an event and then this new window should become ready before retrieving the UI. From the code in WindowManagerService.java, it seems sync'ed delivery of events may be taking care of this but I could not be sure.

Dianne Hackborn

unread,
Jun 30, 2011, 6:59:42 PM6/30/11
to android-...@googlegroups.com
Well this is why instrumentation works the way it does.  What "ready" means can dependent heavily on the application; instrumentation is able to work with the application to do whatever it needs to determine this.

The platform definitely doesn't know when an application is actually "ready."

R V

unread,
Jul 1, 2011, 1:07:52 PM7/1/11
to android-...@googlegroups.com
So, I would want to define "ready" as when the application's main thread is idle. This is definitely something objective and an application developer may have his own definition of "ready" beyond this one but we will not be concerned with this one for now.

Now for my definition of "ready", one solution I am thinking is to extend one of the app's binder interfaces used by the ActivityManager or the WindowManager and run Instrumentation.waitForIdleSync() on a binder thread. But I would somehow need to get an instance of Intrumentation for the app, or an easier thing might be to get the ActivityThread using ActivityThread.currentActivityThread() and then replicate the functionality of waitForIdleSync().

Could you please tell me if this is possible or what else may be done?
Reply all
Reply to author
Forward
0 new messages