This module provides a high-level interface for controlling Android device UI through the AAI (Advanced Accessibility Interface),
allowing script-level automation of UI elements like buttons, text fields, checkboxes, sliders, and more.
It is designed to work with Total Control’s FindNode engine and integrates seamlessly with the UI Explorer tool.
Developers can locate and interact with UI components via selectors, perform input and gesture operations,
monitor screen states, and manage multi-device batch actions.
All functions are accessible via UiElement, UiElementArray, UiSelector, or directly from Device.sendAai(...).
Key Features
- UI Query & Selection: Use
UiSelectoror FindNode queries to locate UI elements on screen. - Element Interaction: Click, long-click, input text, get/set properties, take screenshots.
- Batch Control:
UiElementArrayenables simultaneous actions across devices or multiple UI nodes. - State Monitoring: Register listeners with
addQueryListener()to watch UI changes in real-time. - FindNode Integration: Supports advanced queries like
"T:Settings&&R:.settings"with rich filter support. - Custom Automation: Compatible with
TCThreadVirtual,DeviceArray, and async scripts for full test automation.
Supported Query Modes
- Selector strings:
T:Text,D:Description,R:Resource ID,C:Class Name - Chained selectors: via
UiSelector(e.g.,.text("OK").idEndsWith("btn")) - Raw Node IDs:
153b8(from UI Explorer) - Bounds-based: coordinates-based queries using
BI:[x,y]
Example
var { Device } = require("sigma/device");
var { UiElement, UiElementArray, UiSelector, addQueryListener } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Find and click a button by text
var el = UiElement.findObject(sigmaDevice, "T:Settings");
el.clickSync();
// Input text into multiple fields across devices
var el1 = UiElement.findObject(Device.getMain(), "T:Search");
var el2 = UiElement.findObject(Device.getMain(), "T:Input");
var arr = new UiElementArray();
arr.add(el1);
arr.add(el2);
arr.inputTextSync(0, "Hello AAI");
// Monitor screen for appearance of "Allow" button
addQueryListener("watchAllow", sigmaDevice, "T:Allow", function(name, dev, pkg, node) {
node.clickSync();
});
Notes
- All AAI operations are executed using
device.sendAai()behind the scenes. - For full selector reference, see the UI Explorer or FindNode documentation.
- Most actions require accessibility permissions granted to Total Control on the device.
inputTextSync()requires Sigma input method to be active on device.
Functions
Classes
(inner) addQueryListener(name, device, query, callback) → {string}
Registers a UI query listener on the specified device that continuously monitors for UI elements matching the given query condition.
When a match is found, the provided callback function is triggered.
Example
// Example: Add a listener to detect when the text "Total Control" appears
var { Device } = require("sigma/device");
var { addQueryListener } = require("sigma/aai");
var sigmaDevice = Device.getMain();
function callback(name, device, packageName, node) {
print("Trigger callback");
print(name);
print(device.getName());
print(packageName);
print(node.getText());
}
var name = "test";
var id = addQueryListener(name, sigmaDevice, "T:Total Control", callback);
print(id); // Outputs: listener ID
// Operation Result:
// If it executes successfully:
- Triggers the callback when the query condition is matched.
- Prints the assigned listener ID.
Parameters:
| string | name |
A unique identifier for this listener (can be used later for removal or management). |
| Device | device |
The target device object, typically obtained by |
| string | query |
A string that specifies the UI query condition (e.g. |
| function | callback |
A function executed when the query condition is matched. It receives four parameters:
|
Returns:
| string |
The ID of the registered listener. Can be used for later removal via |
| string | fn |
Function/command name. |
|
| * | args |
<repeatable> |
Positional arguments. |
Returns:
| string |
|
| string | text |
The visible text of the UI element to click, Total Control will first find the component with the text (pick "text" first then "description"). (e.g., |
Returns:
| boolean | null |
Returns:
|
| string | name |
Defined AAI event key |
Returns:
| Boolean |
Returns true if successful, false if it fails, and the specific error message is obtained by the lastError() function. |
| Device | device |
The target device. |
| string | Object | query |
A selector string (e.g. |
Returns:
| UiElement | null |
The matched UI element object, or |
| Device | Array.<Device> | deviceOrDevices |
A single |
| string | Object | query |
A selector string (e.g., |
Returns:
| UiElementArray |
An array-like object containing matched UI elements. |
| number | position |
Text field number:
|
| string | text |
The text string to input into the specified field. |
Returns:
| boolean |
Returns:
|
| string | device |
Singal device object |
Returns:
| Array |
Return the collection of all monitoring events registered for the current device in Array type |
| string | packageName |
The package name of the app to restart (e.g., |
|
| object | query |
<optional> |
The parameter is the query content (query can be obtained through sendAai()) |
Returns:
| boolean |
Returns:
|
| string | packageName |
The package name of the app to run (e.g., |
|
| object | query |
<optional> |
The parameter is the query content (query can be obtained through sendAai()) |
Returns:
| boolean |
Returns:
|
| object | string | params |
A JSON object or string describing the UI interaction to perform.
|
Returns:
| object | null |
If the execution succeeds, returns a result object; otherwise |