I'm trying to list all UI elements being displayed on an Android device. I'm doing this by running "dumpsys window windows | grep "Window #" in an adb shell. This gives me a list of windows from window n to 0.
I'd like to know how the output order is determined. Is window n on top and window 0 at the bottom of the stack? Also, what do the fields mean? For example, the first line shown as as follows
Window #64 Window{793212d u0 NavigationBar}:
What do the values 793212d and u0 indicate?
Regarding the output order:
Regarding the fields:
The
793212d
is the (unique) ID of the window, obtained with System#identityHashCode.The
u0
refers to the user ID to which the window belongs. The user id is not the same as the Unix UID, it is a more high-level concept. Android groups several Unix UIDs to belong to one user ID, i.e. the first 100.000 Unix UIDs belong to user ID 0 and so on (reference). To determine the user ID of the window, Android would look up the Unix UID of the window (with each app having its own Unix UID), and then map the Unix UID to the user ID.The
NavigationBar
is the title of the window.Technical details: When calling
dumpsys window windows
, this will trigger a dump request at theWindowManagerService
(link). This class has a membermRoot
of typeRootWindowContainer
, to which the dump request will be forwarded (link). The relevant code is:The
w
is of typeWindowState
, which overridestoString
to obtain theString
representation you see in thedumpsys
output (link). The relevant code is:The
RootWindowContainer#forAllWindows
method traverses themChildren
list, which is specified to be in z-order (link, link):