Skip to content

BlueCodeSystems/openclaw-android-node

Repository files navigation

OpenClaw Android Node

An Android app that enables LLM control of Android devices through the OpenClaw gateway. This node connects to an OpenClaw gateway via WebSocket and exposes device capabilities like screen capture, UI interaction, and app launching.

Features

  • Accessibility Service: Read UI hierarchy and inject touch events
  • Screen Capture: Take screenshots using MediaProjection API
  • WebSocket Connection: Connect to OpenClaw gateway as a node
  • Device Control: Support for tap, swipe, type, press, and launch commands
  • Secure Authentication: RSA key-based device identity and signing

Supported Commands

Command Description Parameters
screenshot Capture screen as base64 PNG None
ui_tree Get accessibility node hierarchy None
tap(x, y) Perform tap at coordinates x, y (float)
swipe(x1, y1, x2, y2, duration) Perform swipe gesture x1, y1, x2, y2 (float), durationMs (long)
type(text) Type text into focused input text (string)
press(key) Press system keys key: "back", "home", "recents"
launch(package) Launch app by package name packageName (string)

Requirements

  • Android 8.0 (API level 26) or higher
  • OpenClaw Gateway running on accessible network
  • Device permissions for:
    • Accessibility Service (for UI control)
    • Screen Capture (for screenshots)
    • System Alert Window (for overlay permissions)

Setup Instructions

1. Build and Install

cd ~/projects/openclaw-android-node
./gradlew assembleDebug
adb install app/build/outputs/apk/debug/app-debug.apk

2. Configure Gateway Connection

  1. Open the OpenClaw Node app
  2. Enter your Gateway host (IP address)
  3. Enter Gateway port (default: 18789)
  4. Enter Gateway token if authentication is required
  5. Set a display name for this node
  6. Tap "Save Settings"

3. Grant Required Permissions

Accessibility Service

  1. Tap "Enable Accessibility Service"
  2. Find "OpenClaw Node" in the accessibility services list
  3. Enable the service
  4. Accept the permission dialog

Screen Capture

  1. Tap "Grant Screen Capture Permission"
  2. Accept the media projection permission dialog
  3. The screen capture service will start in the background

4. Connect to Gateway

  1. Tap "Connect" to establish WebSocket connection
  2. Wait for "Connected" status
  3. Check OpenClaw gateway logs for node pairing request
  4. Approve the node from gateway CLI: openclaw nodes approve <requestId>

5. Verify Connection

From your OpenClaw gateway, verify the node is connected:

openclaw nodes status
openclaw nodes describe --node "Android Node"

Development

Tech Stack

  • Kotlin - Primary language
  • Jetpack Compose - Modern UI toolkit
  • Ktor Client - WebSocket communication
  • Kotlinx Serialization - JSON parsing
  • BouncyCastle - Cryptographic operations
  • DataStore - Settings persistence

Project Structure

app/src/main/java/com/openclaw/node/
├── MainActivity.kt                 # Main UI activity
├── models/                         # Data models
│   └── Protocol.kt                 # OpenClaw protocol models
├── services/                       # Background services
│   ├── OpenClawAccessibilityService.kt  # UI interaction
│   ├── ScreenCaptureService.kt          # Screen capture
│   └── NodeConnectionService.kt         # WebSocket connection
├── ui/                            # UI components
│   ├── MainViewModel.kt           # UI state management
│   └── theme/                     # Material Design theme
└── utils/                         # Utility classes
    ├── PreferencesManager.kt      # Settings storage
    └── CryptoUtils.kt            # Device identity & signing

OpenClaw Protocol

The node implements the OpenClaw WebSocket protocol v3:

  1. Handshake: Connect with device identity and capabilities
  2. Authentication: RSA signature-based device verification
  3. Command Processing: Handle incoming RPC requests
  4. Response: Return command results or errors

Key Components

AccessibilityService

  • Reads UI hierarchy using Android accessibility APIs
  • Performs gestures via GestureDescription
  • Handles text input to focused elements
  • Manages system navigation (back, home, recents)

ScreenCaptureService

  • Uses MediaProjection for screen recording permission
  • Captures screenshots via ImageReader
  • Converts images to base64 PNG format
  • Runs as foreground service for continuous availability

NodeConnectionService

  • Maintains WebSocket connection to gateway
  • Handles OpenClaw protocol messages
  • Routes commands to appropriate handlers
  • Manages device pairing and authentication

Security

  • Device identity generated from stable hardware characteristics
  • RSA-2048 keypair for signing and verification
  • Private keys stored in encrypted SharedPreferences
  • Challenge-response authentication with gateway
  • No sensitive data in backups (excluded via backup rules)

Troubleshooting

Connection Issues

  1. WebSocket connection failed

    • Verify gateway host/port are correct
    • Check network connectivity
    • Ensure gateway is running and accessible
    • Check gateway logs for connection attempts
  2. Permission denied errors

    • Verify accessibility service is enabled
    • Check screen capture permission was granted
    • Ensure app has overlay permission if needed
  3. Commands not working

    • Check accessibility service is still enabled
    • Verify screen capture service is running
    • Review app logs for error messages
    • Test basic connectivity with gateway

Performance

  • Screen capture resolution can be adjusted for faster transmission
  • UI tree queries may be slow on complex layouts
  • WebSocket connection uses heartbeat to maintain connection
  • Services run in foreground to prevent battery optimization killing

Debugging

Enable debug logging and check Android Studio Logcat:

adb logcat | grep -E "(OpenClaw|NodeConnection|ScreenCapture|AccessibilityService)"

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test on real device
  5. Submit a pull request

License

This project is part of the OpenClaw ecosystem. See the main OpenClaw repository for licensing information.

About

Android node for OpenClaw - enables LLM control of Android devices

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages