services/airpass_background_service library

Airpass Protocol — Background Service (Main Isolate Mesh)

Configures flutter_background_service to show a persistent notification, which keeps the Android process alive.

The actual mesh network logic now runs in the main UI isolate instead of a background isolate. This allows nearby_connections to access the Activity it requires. If the user explicitly swipes the app away from recent apps, the main isolate dies and the mesh stops.

Scanning Strategy: Exponential Backoff

To preserve battery while maintaining mesh participation, the service cycles between active scanning windows and sleep intervals:

[SCAN 10s] → sleep 5s → [SCAN 10s] → sleep 7.5s → [SCAN 10s] → sleep 11.25s → ...
                                                                        ↑
                                                          caps at 5 minutes

When a successful sync occurs, the backoff resets to the initial interval (aggressive scanning after productive encounters).

Functions

initializeAirpassBackgroundService() Future<void>
Initializes and configures the background service.
isAirpassServiceRunning() Future<bool>
Checks if the background service is currently running.
setAppForegroundState(bool isForeground) → void
Sets the foreground state of the app. When in the foreground, the mesh engine aggressively scans for peers.
startAirpassService() Future<void>
Starts the background service (e.g., triggered by a user toggle).
stopAirpassService() Future<void>
Stops the background service.
triggerImmediateSync() → void
Wakes up the scan loop immediately if it is currently sleeping, and resets the backoff interval. Useful when a new message is ready to send.
updateAdvertising({NodeRole? role, List<String>? groupIds}) Future<void>
Sends a role/group update command. Updates the singletons in the main isolate and restarts advertising.