This module provides system-level device control functionalities for Total Control environments.
It enables interaction with Android devices via JavaScript, offering APIs for device status querying, system configuration, screen control, and command execution.
Key Features:
- Retrieve device properties: name, battery, screen orientation, IP, clipboard, brightness, volume, etc.
- Modify device settings: clipboard content, brightness, input method, volume levels, and Wi-Fi state.
- Control screen behavior: lock, unlock, sleep, wakeup.
- Execute shell and ADB commands on connected devices.
- Support for both single device and multiple device operations (
DeviceandDeviceArray). - Utility functions for getting cursor coordinates, SD card path, temp path, and display mode.
ADB Integration:
- Automatically detects and executes ADB commands via configured path.
- Supports SN-based device targeting and command chaining.
Basic Usage:
- Import the module via
require("sigma/system"). - Get a device object using
Device.getMain()orDevice.searchObject(). - Use methods like
get(),set(),exec(),adb()directly on the device instance.
Example APIs:
device.get("text:clipboard"): Read clipboard contentdevice.set("wifi:enable", true): Enable Wi-Fidevice.exec("ls /sdcard"): Execute a shell commanddevice.adb("shell pm list packages"): Run an ADB commanddevice.sleep(),device.unlock(),device.wakeup(): Manage device screen state
This module attaches methods to Device.prototype and DeviceArray.prototype,
and exposes ADB functions separately.
Functions
(inner) adb(adbCommand) → {string|null}
Executes an ADB command on the current device.
Example
// Example: List all installed package names on the device
var { Device } = require("sigma/device");
var system = require("sigma/system");
// Get the current master device object
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
var ret = sigmaDevice.adb("shell pm list packages");
if (ret != null) {
print("Congratulations, this API executes successfully.\nReturn value: " + ret);
} else {
print("Sorry! " + lastError() + "\nReturn value: " + ret);
}
} else {
print("Failed to get the master device object");
}
// Operation Result:
// If it executes successfully, it will return:
Congratulations, this API executes successfully.
Return value:
package:com.huawei.camera
package:com.huawei.android.launcher
package:com.android.mediacenter
...
Parameters:
| string | adbCommand |
The adb shell command to be executed (e.g., |
Returns:
| string | null |
Successfully returns the result of executing the adb command; if the execution fails, you can get the specific error information through the lastError() function. |
| number | null |
Returns 1 or 2 on success:
|
| string | command |
The command that needs to be executed. (e.g., |
|
| number | timeout |
<optional> |
Timeout (milliseconds). |
Returns:
| string | null |
Successfully returns the result of executing the command; if the execution fails, you can get the specific error information through the lastError() function. |
| string | type |
The key specifying what value to get. |
Returns:
| * |
The queried value. Type depends on the query: |
| number |
Successfully returns the rendering mode(0,1,2) of the device:
|
| number | type |
The coordinate type constant. Acceptable values:
|
Returns:
| Object | null |
If it succeeds, it returns the coordinate object. You can use [coordinate object.x] and [coordinate object.y] to get the coordinate value of the mouse. If it fails, it returns NULL, you can get the specific error information through the lastError() function. |
| string | null |
The device name if successful, or |
| number |
In the multi-control center (MDCC), return the device serial number, such as 1, 2, 3; Not in the multi-control center, always returns 0. |
| number |
The direction of rotation of the device's screen. |
| number |
Device power (percentage). |
| string | null |
The path name of the sdcard. |
| string | type |
The type of setting to retrieve. For example:
|
Returns:
| Object | string | null |
Returns the setting value.
Returns |
| string | null |
Returns the absolute path to the temporary directory on the device (e.g., |
| number | null |
Returns the screen width in pixels (e.g., |
| number | timeout |
Duration to lock the device in milliseconds. For example, |
Returns:
| number | null |
Returns |
| string | type |
The target setting to modify. Supported formats include:
|
| * | value |
The value to set. Its type depends on the
|
Returns:
| boolean | null |
Returns:
|
| string | name |
The new name to assign to the device (e.g. "mobile2"). |
Returns:
| number |
Returns:
|
| number |
Returns:
|
| number |
Returns:
|
| number |
Returns:
|