Skip to main content

Network · SetOffline · ShapeNetwork · ResetNetwork

This tool on every surface: CLI · MCP · Python · JavaScript · Go · Java · .NET

Read or set the device's network conditions: offline, latency and bandwidth. These call app_network.

Network​

func (d *Device) Network(ctx context.Context) (NetworkStatus, error)

Network reads the device's network conditions. Android only.

SetOffline​

func (d *Device) SetOffline(ctx context.Context, offline bool) (NetworkStatus, error)

SetOffline turns airplane mode on or off and waits for the network to follow — on an emulator or a real Android phone.

ShapeNetwork​

func (d *Device) ShapeNetwork(ctx context.Context, latencyMs, downloadKbps, uploadKbps int) (NetworkStatus, error)

ShapeNetwork sets the latency added to each round trip and the download and upload limits in kbit/s, replacing any set before; zero is none. It needs root, so an emulator.

ResetNetwork​

func (d *Device) ResetNetwork(ctx context.Context) (NetworkStatus, error)

ResetNetwork removes the shaping and turns airplane mode off.

Examples​

Go offline​

status, err := dev.SetOffline(ctx, true)
if err != nil {
return err
}
fmt.Println("online:", status.Online)

The same call from the command line, mobium network --offline, printed on an Android 15 emulator:

offline (airplane mode)
BeforeAfter
Before: mobium network --offline on an Android 15 emulatorAfter: mobium network --offline on an Android 15 emulator

mobium network --offline on an Android 15 emulator

A slow connection, on an emulator​

// Latency in ms, download and upload in kbit/s; 0 is no limit.
if _, err := dev.ShapeNetwork(ctx, 300, 500, 0); err != nil {
return err
}

The same call from the command line, mobium network --latency 300 --download 500, printed on an Android 15 emulator:

online; 300ms added to each round trip, download 500 kbit/s

More examples​

Read the network conditions​

status, err := dev.Network(ctx)
if err != nil {
return err
}
fmt.Println(status.Online, status.Airplane, status.LatencyMs)

Go offline, then back​

if _, err := dev.SetOffline(ctx, true); err != nil {
return err
}
defer dev.SetOffline(ctx, false)

A slow connection on an emulator, then no shaping​

if _, err := dev.ShapeNetwork(ctx, 300, 500, 100); err != nil {
return err
}
defer dev.ResetNetwork(ctx)