public final class UiWindow implements Searchable


Represents a UI window on the screen and provides methods to access its properties and perform actions.

Similar to UiObject2 that wraps AccessibilityNodeInfo, a UiWindow wraps an AccessibilityWindowInfo. This represents a UI window displayed on the screen for accessibility purposes, including interactive windows like dialogs or popup windows. It is important to note that a UiWindow instance caches a snapshot of a window state. If the underlying window closes or changes and it becomes stale, UiWindow will automatically check and refresh its state internally before executing any methods.

Requires API level 24 or higher for multi-window mode.

Summary

Public methods

boolean
equals(Object object)
UiObject2

Searches all elements in the window root and returns the first one to match the selector, or null if no matching objects are found in this window.

@NonNull List<UiObject2>

Searches all elements under in the window root and returns those that match the selector.

int

Gets the ID of the display containing this window.

int

Returns the ID of this window.

int

Returns the layer (Z-order) of the window.

@Nullable String

Returns the name of the package that this window belongs to.

@Nullable UiObject2

Gets the root node in the window as a UiObject2.

@Nullable String

Returns the title of the window as a String.

int

Returns the type of the window (e.g., TYPE_APPLICATION).

@NonNull Rect

Returns this window's visible bounds clipped to the size of the display.

boolean

Returns true if there is an element in the window which matches the selector.

int
boolean

Returns if this window is active (the one the user is currently interacting with).

boolean

Returns if this window has input focus.

boolean

Returns if the window is in picture-in-picture mode.

@NonNull String

Public methods

equals

public boolean equals(Object object)

findObject

public UiObject2 findObject(@NonNull BySelector selector)

Searches all elements in the window root and returns the first one to match the selector, or null if no matching objects are found in this window.

findObjects

public @NonNull List<UiObject2findObjects(@NonNull BySelector selector)

Searches all elements under in the window root and returns those that match the selector.

getDisplayId

Added in 2.4.0-alpha06
public int getDisplayId()

Gets the ID of the display containing this window.

Returns
int

The current display ID, or DEFAULT_DISPLAY if the API level is <30.

See also
getDisplayId

getId

Added in 2.4.0-alpha06
public int getId()

Returns the ID of this window.

getLayer

Added in 2.4.0-alpha06
public int getLayer()

Returns the layer (Z-order) of the window. Higher layers are drawn on top of lower layers.

Returns
int

The layer rank.

See also
getLayer

getPackageName

Added in 2.4.0-alpha06
public @Nullable String getPackageName()

Returns the name of the package that this window belongs to.

Returns
@Nullable String

The name of the package, or null if the root object is not available.

getRootObject

Added in 2.4.0-alpha06
public @Nullable UiObject2 getRootObject()

Gets the root node in the window as a UiObject2.

Returns
@Nullable UiObject2

The root UiObject2, or null if the root node is not available or cannot be wrapped. The returned UiObject2 should be recycled by the caller if it holds onto the reference.

See also
getRoot

getTitle

Added in 2.4.0-alpha06
public @Nullable String getTitle()

Returns the title of the window as a String.

Returns
@Nullable String

The title as a String, or null if the window has no title, or if API level <24.

See also
getTitle

getType

Added in 2.4.0-alpha06
public int getType()

Returns the type of the window (e.g., TYPE_APPLICATION).

Returns
int

The type.

See also
getType

getVisibleBounds

Added in 2.4.0-alpha06
public @NonNull Rect getVisibleBounds()

Returns this window's visible bounds clipped to the size of the display.

hasObject

public boolean hasObject(@NonNull BySelector selector)

Returns true if there is an element in the window which matches the selector.

hashCode

public int hashCode()

isActive

Added in 2.4.0-alpha06
public boolean isActive()

Returns if this window is active (the one the user is currently interacting with).

Returns
boolean

true if the window is active.

See also
isActive

isFocused

Added in 2.4.0-alpha06
public boolean isFocused()

Returns if this window has input focus.

Returns
boolean

true if this window has input focus.

See also
isFocused

isInPictureInPictureMode

Added in 2.4.0-alpha06
public boolean isInPictureInPictureMode()

Returns if the window is in picture-in-picture mode.

Returns
boolean

true if the window is in picture-in-picture mode, false otherwise or if API level is <26.

toString

public @NonNull String toString()