Class Client

Constructors

Properties

Methods

  • Parameters

    • serial: string

    Returns Promise<void>

  • Retrieves current battery status. Analogous to adb -s <serial> shell dumpsys battery .

    Parameters

    • serial: string

    Returns Promise<PropertyMap>

  • Deletes all data associated with a package from the device. Analogous to adb shell pm clear <pkg>.

    Parameters

    • serial: string
    • pkg: string

    Returns Promise<void>

  • Connects to device over local network.

    Parameters

    • host: string

    Returns Promise<string>

    Example

    adb.map(async (device) => {
    await device.tcpip();
    const [ip] = await device.getIpAddress();
    await adb.connect(ip);
    });
  • Parameters

    • host: string
    • port: number

    Returns Promise<string>

  • Copies data with srcPath to destPath parameter. Analogous to adb shell cp <src> <dest>.

    Parameters

    • serial: string
    • srcPath: string
    • destPath: string

    Returns Promise<void>

  • Parameters

    • serial: string
    • srcPath: string
    • destPath: string
    • options: CpOptions

    Returns Promise<void>

  • Enables to execute any custom command.

    Type Parameters

    • T
    • P extends unknown[] = unknown[]

    Parameters

    Returns Promise<T>

    Example

    class MyCommand extends Command<number> {
    protected autoEnd = true;
    private arg: string;
    constructor(connection: Connection, arg: string) {
    super(connection);
    this.arg = arg;
    }
    async execute(): Promise<number> {
    const reply = await this.initExecute(this.arg);
    switch (reply) {
    case Reply.OKAY:
    const value = await this.parser.readValue();
    return parseInt(value.toString(), 10);
    case Reply.FAIL:
    throw await this.parser.readError();
    default:
    return parseInt(reply, 10);
    }
    }
    }
  • Enables to execute any custom transport command.

    Type Parameters

    • T
    • P extends unknown[] = unknown[]

    Parameters

    Returns Promise<T>

    Example

    class MyCommand extends TransportCommand<null> {
    protected keepAlive = false;
    private arg: string;
    constructor(connection: Connection, serial: string, arg: string) {
    super(connection, serial);
    this.arg = arg;
    }
    protected get Cmd() {
    return 'test '.concat(this.arg);
    }
    protected postExecute(): null {
    return null;
    }
    }
  • Parameters

    • serial: string
    • pathToApk: string

    Returns Promise<void>

  • Disconnects from the given device.

    Parameters

    • host: string

    Returns Promise<string>

  • Parameters

    • host: string
    • port: number

    Returns Promise<string>

  • Sends draganddrop input command to the device shell. Analogous to adb shell input touchscreen draganddrop x1 y1 x2 y2. Default input source is touchscreen.

    Parameters

    • serial: string
    • x1: number

      Horizontal starting coordinate.

    • y1: number

      Vertical starting coordinate.

    • x2: number

      Horizontal ending coordinate.

    • y2: number

      Vertical ending coordinate.

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Executes a given command on specific device via adb console interface. Analogous to adb -s <serial> <command>. If cmd contains arguments, they need to be passed as and string[], not string.

    Parameters

    • serial: string
    • cmd: string | string[]

    Returns Promise<string>

  • Executes a given command on specific device shell via adb console interface. Analogous to adb -s <serial> shell <command> .

    Parameters

    • serial: string
    • cmd: string | string[]

    Returns Promise<string>

  • Parameters

    • args: readonly string[]

    Returns Promise<string>

  • Gets file stats for specified path. Analogous to adb stat <filepath>.

    Parameters

    • serial: string
    • path: string

    Returns Promise<FileStat>

  • Forwards socket connections from the ADB server host (local) to the device (remote). Analogous to adb forward <local> <remote>.

    Parameters

    • serial: string
    • local: string
    • remote: string

    Returns Promise<void>

    Example

    adb.forward('serial', 'tcp:9222', 'localabstract:chrome_devtools_remote')
    
  • Gets the device path of the device identified by the device.

    Parameters

    • serial: string

    Returns Promise<string>

  • Gets the ipv4 addresses of default wlan interface.

    Parameters

    • serial: string

    Returns Promise<string[]>

  • Gets the serial number of the device. Meant for getting serial number of local devices. Analogous to adb shell getprop ro.serialno.

    Parameters

    • serial: string

    Returns Promise<string>

  • Installs an apk to the device. Analogous to adb install <pkg>.

    Parameters

    • serial: string
    • apk: string | Readable

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Parameters

    • serial: string
    • apk: string | Readable
    • options: InstallOptions
    • args: string

      Extra arguments. E.g. --fastdeploy flag.

    Returns Promise<void>

  • Parameters

    • serial: string
    • apk: string
    • options: undefined | InstallOptions
    • args: undefined | string

    Returns Promise<void>

  • Parameters

    Returns Promise<string>

  • Tells if a package is installed or not.

    Parameters

    • serial: string
    • pkg: string

    Returns Promise<boolean>

  • Kills the adb server.

    Returns Promise<void>

  • Force stops given package. Analogous to adb shell am force-stop <package>.

    Parameters

    • serial: string
    • pkg: string

    Returns Promise<void>

  • Lists installed packages. Analogous to adb shell pm list packages.

    Parameters

    • serial: string

    Returns Promise<string[]>

  • Maps through all connected devices.

    Type Parameters

    • T

    Parameters

    • mapper: ((device) => T | Promise<T>)
        • (device): T | Promise<T>
        • Parameters

          Returns T | Promise<T>

    Returns Promise<T[]>

  • Creates directory specified by path parameter. Analogous to adb shell mkdir <path>.

    Parameters

    • serial: string
    • path: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Moves data with srcPath to destPath parameter. Analogous to adb shell mv <src> <dest>.

    Parameters

    • serial: string
    • srcPath: string
    • destPath: string

    Returns Promise<void>

  • Parameters

    • serial: string
    • srcPath: string
    • destPath: string
    • options: MvOptions

    Returns Promise<void>

  • Opens logcat. Analogous to adb logcat.

    Parameters

    • serial: string

    Returns Promise<LogcatReader>

    See

    LogcatReader and LogcatOptions for more details.

    Example

    import { Client, Priority } from 'adb-ts';
    const adb = new Client();
    const logcat = await adb.openLogcat('serial', {
    filter: (entry) => entry.priority > Priority.INFO
    });
    logcat.on('entry', (entry) => {
    console.log(entry);
    });
  • Parameters

    Returns Promise<LogcatReader>

  • Establishes a new monkey connection on port 1080.

    Parameters

    • serial: string

    Returns Promise<Monkey>

  • Opens a direct TCP connection to specified port on the device. Analogous to adb tcp <port>:<host>.

    Parameters

    • serial: string
    • port: number

    Returns Promise<Connection>

    Example

    const socket = await adb.openTcp('serial', 5555);
    // socket.write(...)
  • Parameters

    • serial: string
    • port: number
    • host: string

    Returns Promise<Connection>

  • Sends roll input command to the device shell. Analogous to adb shell input trackball press. Default input source is trackball.

    Parameters

    • serial: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Gets a PullTransfer instance.

    Parameters

    • serial: string
    • path: string

    Returns Promise<PullTransfer>

    See

    PullTransfer

    Example

    let data = '';
    const transfer = await adb.pull('serial', '/path')
    transfer.on('data', (chunk) => {
    data += chunk.toString();
    });
    transfer.on('end', () => {
    console.log(data);
    });
  • Wraps pull method, reads the file content and resolves with the output.

    Parameters

    • serial: string
    • srcPath: string

    Returns Promise<Buffer>

  • Wraps pull method, reads the content of file on the device and write it to a file on the machine.

    Parameters

    • serial: string
    • srcPath: string
    • destPath: string

    Returns Promise<void>

  • Gets a PushTransfer instance.

    Parameters

    • serial: string
    • srcPath: string | Readable
    • destPath: string

    Returns Promise<PushTransfer>

    See

    PushTransfer

    Example

    const transfer = await adb.push('serial', '/path-src', '/path-dest')
    transfer.on('end', () => { });
  • Parameters

    • serial: string
    • srcPath: string | Readable
    • destPath: string
    • mode: SyncMode

    Returns Promise<PushTransfer>

  • Wraps push method, provides API for quick data writing.

    Parameters

    • serial: string
    • data: string | Buffer | Readable
    • destPath: string

    Returns Promise<void>

  • Wraps push method, reads the content of file on the host to a file on the device.

    Parameters

    • serial: string
    • srcPath: string
    • destPath: string

    Returns Promise<void>

  • Parameters

    • serial: string
    • data: string | Readable
    • dest: string

    Returns Promise<void>

  • Puts setting on the device. Analogues to adb shell settings put <mode> <name> <value>.

    Parameters

    Returns Promise<void>

  • Reads given directory. The path should start with /.

    Parameters

    • serial: string
    • path: string

    Returns Promise<SyncEntry[]>

  • Reboots the device. Analogous to adb reboot.

    Parameters

    • serial: string

    Returns Promise<void>

  • Attempts to remount the /system partition in read-write mode. Can be done on a rooted device. Analogous to adb remount. Analogous to adb remount

    Parameters

    • serial: string

    Returns Promise<void>

  • Reverses socket connections from the device (remote) to the ADB server host (local). Analogous to adb reverse <remote> <local>.

    Parameters

    • serial: string
    • local: string
    • remote: string

    Returns Promise<void>

    Example

    adb.reverse('serial', 'localabstract:chrome_devtools_remote', 'tcp:9222')
    
  • Removes file/folder specified by path parameter. Analogous to adb shell rm <path>.

    Parameters

    • serial: string
    • path: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Sends roll input command to the device shell. Analogous to adb shell input trackball roll <x> <y>. Default input source is trackball.

    Parameters

    • serial: string
    • x: number

      Horizontal coordinate.

    • y: number

      Vertical coordinate.

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Attempts to which the device to the root mode. Analogous to adb root.

    Parameters

    • serial: string

    Returns Promise<void>

  • Takes a screenshot on the specified device. Analogous to adb shell screencap -p.

    Parameters

    • serial: string

    Returns Promise<Buffer>

  • Sets property on the device. Analogues to adb shell setprop <prop> <value>.

    Parameters

    Returns Promise<void>

  • Executes a given shell command via adb console interface. Analogous to adb -s <serial> shell <command>.

    Parameters

    • serial: string
    • command: string

    Returns Promise<string>

  • Shuts the device down. Analogous to adb reboot -p.

    Parameters

    • serial: string

    Returns Promise<void>

  • Starts a new activity with options. Analogous to adb shell am start <pkg./activity>.

    Parameters

    • serial: string
    • pkg: string
    • activity: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Starts adb server if not running.

    Returns Promise<void>

  • Starts a new service with options. Analogous to adb shell am startservice <pkg> <service>.

    Parameters

    • serial: string
    • pkg: string
    • service: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Sends swipe input command to the device shell. Analogous to adb shell input touchscreen swipe x1 y1 x2 y2. Default input source is touchscreen.

    Parameters

    • serial: string
    • x1: number

      Horizontal starting coordinate.

    • y1: number

      Vertical starting coordinate.

    • x2: number

      Horizontal ending coordinate.

    • y2: number

      Vertical ending coordinate.

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Sends tap input command to the device shell. Analogous to adb shell input touchscreen tap <x> <y>. Default input source is touchscreen.

    Parameters

    • serial: string
    • x: number

      Horizontal coordinate.

    • y: number

      Vertical coordinate.

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Puts the device ADB daemon into tcp mode. Afterwards it is possible to use connect method. Analogous to adb tcpip 5555.

    Parameters

    • serial: string

    Returns Promise<void>

  • Parameters

    • serial: string
    • port: number

    Returns Promise<void>

  • Sends text input command to the device shell. Analogous to adb shell input touchscreen text '<text>'. Default input source is touchscreen.

    Parameters

    • serial: string
    • text: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Updates access and modification times of file specified by path parameter, or creates a new file. Analogous to adb shell touch <filename>.

    Parameters

    • serial: string
    • path: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Uninstalls a package from the device. Analogous to adb uninstall.

    Parameters

    • serial: string
    • pkg: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Sets the device transport back to usb.

    Parameters

    • serial: string

    Returns Promise<void>

  • Gets the adb server version.

    Returns Promise<number>

  • Waits until the device has finished booting.

    Parameters

    • serial: string

    Returns Promise<void>

  • Waits until the device is in the given state. Analogous to adb wait-for-<transport>-<state>.

    Parameters

    Returns Promise<void>