Question : How to get element tree more faster than hierarchyviewer?

Showing 1-2 of 2 messages
Question : How to get element tree more faster than hierarchyviewer? Binhua Liu 9/21/12 11:34 PM
Hi All,

I am try write a open source tool which need get UI element tree out of the application, just like hierarchyviewer. but the problem is the way like hierarchyviewer is too slow, need about 3-5 seconds. 

I have read the code of ViewServer.java and WindowManagerService.java. In viewServerWindowCommand method of WindowManagerService.java, I see the request of dumping element tree at last is sent to IWindow object through binder.transact method. But I still have no idea why this way is slow and how can be more faster?  why the test framework -- Robotium can get UI elements so fast? I need get element tree in black box way.

this is our opensource projects: github.com/vowei

Thanks
Re: Question : How to get element tree more faster than hierarchyviewer? David Brainard 10/12/12 10:39 AM
The reason for the slowness is that android uses reflection to query the window elements to get the properties. Since reflection by itself is very performance intensive, it slows down the whole process. 

Android uses annotation to mark specific properties to be exported. So every field and method that is marked with the exportedproperty annotation is processed. 

You have to look into what happens after the the windowmanagerservice issues a binder call. The viewrootimpl which implements the Iwindowimpl interface gets invoked. This invokes the ViewDebug class which does the final processing. 

If you look into viewdebug class you might get a good idea of how everything works. 

~David