Crate rustvncserver_android

Crate rustvncserver_android 

Source
Expand description

Generic Android JNI bindings for rustvncserver.

This crate provides a ready-to-use VNC server for Android apps. Simply add it as a dependency and configure your Java class names via system properties at runtime.

§Quick Start

  1. Add to your Cargo.toml:
[dependencies]
rustvncserver-android = { version = "1.0", features = ["turbojpeg"] }
  1. In your Java code, set system properties BEFORE loading the library:
public class MainService extends Service {
    static {
        // Configure class names (use / instead of . in package path)
        System.setProperty("rustvnc.main_service_class", "com/mycompany/vnc/MainService");
        System.setProperty("rustvnc.input_service_class", "com/mycompany/vnc/InputService");
        System.setProperty("rustvnc.log_tag", "MyApp-VNC");  // Optional

        // Load the library - JNI_OnLoad will register natives automatically
        System.loadLibrary("rustvncserver_android");
    }
}

§System Properties

  • rustvnc.main_service_class - Full class path for MainService (required)
  • rustvnc.input_service_class - Full class path for InputService (required)
  • rustvnc.log_tag - Android log tag (default: "RustVNC")

§Alternative: Manual Registration

If you prefer to register natives manually (e.g., from a wrapper crate), don’t set the system properties and call register_vnc_natives from your own JNI_OnLoad:

use rustvncserver_android::register_vnc_natives;

#[no_mangle]
pub extern "system" fn JNI_OnLoad(vm: JavaVM, _: *mut c_void) -> jint {
    let mut env = vm.get_env().unwrap();
    register_vnc_natives(
        &mut env,
        "com/mycompany/vnc/MainService",
        "com/mycompany/vnc/InputService",
    ).expect("Failed to register VNC natives");
    JNI_VERSION_1_6
}

§Java Side Requirements

Your Java classes need these native method declarations and callbacks:

public class MainService {
    static { System.loadLibrary("droidvnc_ng"); }  // or your lib name

    // Native methods (registered at runtime via JNI_OnLoad)
    public static native void vncInit();
    public static native boolean vncStartServer(int w, int h, int port, String name, String pw, String httpDir);
    public static native boolean vncStopServer();
    public static native boolean vncIsActive();
    public static native boolean vncUpdateFramebuffer(ByteBuffer buffer);
    public static native boolean vncNewFramebuffer(int width, int height);
    public static native long vncConnectRepeater(String host, int port, String id, String requestId);
    // ... see full list in source

    // Callbacks (called from Rust)
    public static void onClientConnected(long clientId) { }
    public static void onClientDisconnected(long clientId) { }
    public static void notifyRfbMessageSent(String requestId, boolean success) { }
    public static void notifyHandshakeComplete(String requestId, boolean success) { }
}

public class InputService {
    public static void onKeyEvent(int down, long keysym, long clientId) { }
    public static void onPointerEvent(int buttonMask, int x, int y, long clientId) { }
    public static void onCutText(String text, long clientId) { }
}

Functions§

JNI_OnLoad
JNI_OnLoad entry point - called when the library is loaded.
register_vnc_natives
Registers VNC native methods with the specified Java classes.