minitouch

repository·master·Indexed 42 days ago

https://github.com/devicefarmer/minitouch

A tool providing a socket interface for triggering multitouch events and gestures on Android devices, used for automated testing and remote device control. It includes a protocol for scheduling touch down, move, and up events, and provides prebuilt binaries via @devicefarmer/minitouch-prebuilt version 1.3.2.

Tokens
1.3K
Snippets
5
Records
6
Agent score
4%

What's inside minitouch

  1. Build minitouch from source

    master

    To build minitouch, you need the Android NDK (Revision 10 or newer is recommended). Ensure you have initialized the libevdev Git submodule before building.

    1. Initialize submodules:
      git submodule init
      git submodule update
    2. Build using ndk-build:
      ndk-build

    The resulting binaries will be located in the ./libs directory.

    git submodule init
    git submodule update
    ndk-build
  2. Connect to the minitouch socket

    master

    Once minitouch is running on the device, it listens on an abstract unix domain socket. To interact with it from your host machine, you must create a local TCP forward using ADB.

    1. Forward the port:
      adb forward tcp:1111 localabstract:minitouch
    2. Connect via a socket client (e.g., nc) to localhost:1111.

    Warning: Only one connection at a time is supported. Multiple connections may cause the driver to freeze the device.

    adb forward tcp:1111 localabstract:minitouch
    nc localhost 1111
  3. Run minitouch on an Android device

    master

    To run minitouch, you must first push the correct binary for your device's architecture to /data/local/tmp/.

    Note for Android 10+: You must run the STFService and agent first to handle new security policies. If using standalone minitouch, follow the STFService instructions.

    Steps to run manually:

    1. Determine the device ABI:
      ABI=$(adb shell getprop ro.product.cpu.abi | tr -d '\r')
    2. Push the binary:
      adb push libs/$ABI/minitouch /data/local/tmp/
      Note: For SDK < 16, use the minitouch-nopie executable.
    3. Execute the binary:
      adb shell /data/local/tmp/minitouch

    If you have multiple devices connected, set the ANDROID_SERIAL environment variable to avoid specifying -s <serial> for every command.

    ABI=$(adb shell getprop ro.product.cpu.abi | tr -d '\r')
    adb push libs/$ABI/minitouch /data/local/tmp/
    adb shell /data/local/tmp/minitouch
  4. Minitouch Gesture Examples

    master

    The following are common gesture sequences using the minitouch protocol.

    Tap at (10, 10) with 50 pressure:

    d 0 10 10 50
    c
    u 0
    c

    Simultaneous tap at (10, 10) and (20, 20):

    d 0 10 10 50
    d 1 20 20 50
    c
    u 0
    u 1
    c

    Swipe from (0, 0) to (100, 0): (Note: You must implement delays between commits in your own code to control swipe speed.)

    d 0 0 0 50
    c
    m 0 20 0 50
    c
    m 0 40 0 50
    c
    m 0 60 0 50
    c
    m 0 80 0 50
    c
    m 0 100 0 50
    c
    u 0
    c

    Pinch gesture:

    d 0 0 100 50
    d 1 100 0 50
    c
    m 0 10 90 50
    m 1 90 10 50
    c
    m 0 20 80 50
    m 1 80 20 50
    c
    m 0 20 80 50
    m 1 80 20 50
    c
    m 0 30 70 50
    m 1 70 30 50
    c
    m 0 40 60 50
    m 1 60 40 50
    c
    m 0 50 50 50
    m 1 50 50 50
    c
    u 0
    u 1
    c
  5. Minitouch Protocol: Commands and Metadata

    master

    The minitouch protocol uses LF-separated lines. Each line starts with an ASCII character representing the command type.

    Metadata (Readable from socket)

    Upon connection, minitouch sends a header containing metadata. You must read these before sending commands.

    • v <version>: The protocol version (e.g., v 1).
    • ^ <max-contacts> <max-x> <max-y> <max-pressure>: The upper bounds for touch arguments. Using values larger than these may freeze the device.
    • $ <pid>: The process ID of the minitouch process.

    Commands (Writable to socket)

    • c: Commit. Plays out all currently scheduled touches. Nothing is visible on screen until a commit is sent.
    • r: Reset. Attempts to reset touches by creating u (up) events and committing. Use this if you suspect an invalid event sequence to prevent screen freezes.
    • d <contact> <x> <y> <pressure>: Down. Schedules a touch down for the specified <contact>.
    • m <contact> <x> <y> <pressure>: Move. Schedules a touch move for the specified <contact>.
    • u <contact>: Up. Schedules a touch up for the specified <contact>.
    • w <ms>: Wait. Immediately waits for <ms> milliseconds. Does not commit the queue.
  6. Minitouch CLI Reference

    master

    The minitouch binary accepts the following command-line flags:

    • -d <device>: Use the given touch device. Otherwise autodetect.
    • -n <name>: Change the name of the abstract unix domain socket. (default: minitouch)
    • -v: Verbose output.
    • -i: Uses STDIN and doesn't start socket.
    • -f <file>: Runs a file with a list of commands, doesn't start socket.
    • -h: Show help.
    Usage: /data/local/tmp/minitouch [-h] [-d <device>] [-n <name>] [-v] [-i] [-f <file>]
      -d <device>: Use the given touch device. Otherwise autodetect.
      -n <name>:   Change the name of of the abtract unix domain socket. (minitouch)
      -v:          Verbose output.
      -i:          Uses STDIN and doesn't start socket.
      -f <file>:   Runs a file with a list of commands, doesn't start socket.
      -h:          Show help.