Network Failover Between Ethernet, Wi-Fi, and Cellular on Android

Engineering guidance for Android network failover, connection recovery, retry policy, and transaction consistency.

Network Failover Between Ethernet, Wi-Fi, and Cellular on Android

An Android gateway can have Ethernet, Wi-Fi, and cellular connected and still lose transactions when the preferred link fails. The operating system may select a new network, but existing sockets, DNS state, authentication, and application retries do not automatically become correct.

Design failover as a state machine with explicit health criteria, retry limits, data ownership, and recovery behavior. A cable being plugged in is only one signal.

Ethernet link indicates a physical connection. A valid IP configuration indicates local network setup. Internet validation and a successful request to the required service provide different evidence.

A site router can keep Ethernet up while its upstream connection fails. Wi-Fi can associate with a captive portal. Cellular can register while data service is unavailable or restricted.

Use separate states so the application can explain what failed and choose a useful action.

StateEvidencePossible problem
Physical linkEthernet carrier or Wi-Fi associationNo address or route
IP configurationAddress, gateway, DNSUpstream unavailable
Validated connectivityPlatform capability resultRequired service still blocked
Service reachabilityBounded request to owned endpointAuthentication or server failure
Business readinessSuccessful authorized operationData conflict or application error

Do not reboot the device simply because a remote service is down. A local restart rarely repairs an upstream outage and can erase useful evidence.

Define the network preference policy

Specify preferred transport, allowed fallback, metered-data limits, roaming behavior, and when to return to the primary link. Some installations permit cellular for alerts but prohibit large media downloads.

Distinguish product policy from what an ordinary application can control. System-level transport preference and routing may require BSP or device-management integration. An app should not assume it can globally reorder Android networks.

Keep the policy visible to support. A unit that intentionally refuses an expensive link should report that decision rather than appear broken.

Decide whether failover is immediate or requires a sustained failure threshold. A single packet timeout is weak evidence; waiting several minutes may be unacceptable for a kiosk.

Use Android callbacks correctly

Android connectivity callbacks report network availability and changes in capabilities and link properties. Listen to those changes rather than polling a single connected flag.

Default-network callbacks describe the network selected for ordinary traffic. A network can lose default status while still existing. Interpret events according to the callback type.

Keep callback processing short and move longer work to a worker. Use callback-provided information and avoid race-prone synchronous queries inside callbacks.

When an application explicitly binds a socket or process to a network, it takes on additional lifecycle responsibilities. Review why binding is needed and ensure the binding is removed or replaced when that network is no longer appropriate.

Rebuild sessions deliberately

A socket opened over the old network may fail after the default route changes. Recreate connections with bounded timeouts and refresh any network-specific resolution state.

TLS and authentication add their own failure modes. Incorrect device time, expired credentials, or a server rejection should not be classified as a transport failure that triggers endless link switching.

Use backoff and jitter to prevent a fleet from reconnecting simultaneously after a site outage. Bound total retry time for an interactive operation and move durable work into a queue when the product permits it.

The offline-first guide explains the queue and reconciliation side of this design.

Prevent duplicate transactions

A request can reach the server even when the response is lost. Retrying it over cellular can duplicate an operation unless the protocol supports stable request identifiers and deduplication.

Assign an idempotency identifier before the first attempt and retain it across network changes and process restarts. The server must apply a defined duplicate policy.

Track pending, sent, acknowledged, and rejected states explicitly. A timeout means the outcome may be unknown; it does not prove the server did nothing.

For actions with physical consequences, such as dispensing or access control, define reconciliation and operator escalation before enabling automatic retries.

Use hysteresis for failback

If Ethernet briefly returns and disappears, immediate failback can cause repeated session churn. Require a stable healthy period before switching back, unless the product requirement demands otherwise.

Measure success against the required service and use separate entry and exit thresholds where appropriate. Record the reason for each transition.

TransitionCandidate triggerGuardrail
Ethernet to cellularSustained service failure on wired pathConfirm cellular policy and budget
Wi-Fi to EthernetWired path stable and usableAvoid interrupting critical operation
Cellular to primaryPrimary healthy for defined intervalHysteresis and queued-transfer policy
All links unavailableNo permitted usable pathOffline UI and bounded queue
Service outage on all linksSame server error everywhereStop transport thrashing

Keep bulk transfers separate from urgent messages. A link suitable for a small alarm may be unsuitable for an OTA package.

Test failures beyond unplugging cables

Unplugging Ethernet tests one clean failure. More difficult cases leave the link up while dropping upstream traffic, DNS, or selected ports.

Use a controlled test network to introduce latency, loss, captive portals, DNS failure, expired DHCP leases, and server errors. Test transitions while transactions and updates are active.

Run with realistic signal strength and the final antenna arrangement. The metal-enclosure antenna guide helps avoid blaming software for a marginal RF path.

Measure outage duration from the user’s perspective: last successful operation to first successful operation after recovery. A routing change timestamp is not the full recovery time.

Keep fleet evidence bounded

Log old and new transport, transition reason, capabilities, signal summary, retry count, service result, and elapsed recovery time. Avoid storing credentials or full sensitive request bodies.

Aggregate frequent failovers by site and hardware revision. A pattern may reveal bad cabling, weak antennas, modem resets, or an overly aggressive policy.

Cap diagnostic storage and upload it when appropriate. A network outage must not fill the data partition with repeated error messages.

The watchdog recovery guide explains how to distinguish a local unresponsive service from ordinary external unavailability.

Validate startup and maintenance

The first available network during boot may not be the final preferred network. Ensure enrollment, time synchronization, and application startup can tolerate that transition.

Test firmware updates, app replacement, suspend/resume, and modem reset. Confirm that network requests and callbacks are registered once and cleaned up correctly.

Document a service mode that reveals transport and business state without exposing unrestricted system settings. Support needs evidence, not a hidden sequence of manual route changes.

Frequently asked questions

Does Android automatically preserve connections during failover?

Applications should expect existing connections to fail and recreate them. A new default network does not guarantee an old session survives.

Should cellular always remain active?

That depends on recovery-time requirements, power, data cost, modem behavior, and platform policy. Measure both standby and activation strategies.

Use explicit health criteria, bounded retries, hysteresis, and a stable failback interval. Separate remote service failure from local transport failure.

Acceptance criteria

Approve failover when required operations resume within the allowed outage, uncertain transactions reconcile correctly, metered traffic follows policy, and repeated transitions remain stable. Keep the state model and test conditions with the released image.