feat: implement Android connectivity detection#14
Conversation
1e3963b to
c949c09
Compare
| use crate::error::Result; | ||
| use crate::types::{ConnectionStatus, ConnectionType}; | ||
|
|
||
| const DBUS_TIMEOUT: Duration = Duration::from_secs(2); |
There was a problem hiding this comment.
DBUS_TIMEOUT is applied as a per-method timeout, and a single connection_status() makes several sequential D-Bus calls (NameHasOwner, Connectivity, [State], PrimaryConnection, Devices, per-device DeviceType/Metered, and for a modem the ModemManager Udi/RegistrationState). In the worst case (NM/MM present but wedged) those 2s timeouts stack to ~15-20s with no overall deadline, and since the desktop path runs on the bounded spawn_blocking pool, a few concurrent calls could starve other blocking work app-wide. Two cheap options: wrap the whole operation in an aggregate budget (falling back to fallback_connection_status() on expiry), and/or lower the per-call timeout since these are local-bus reads that should return in ms. Optionally, a fresh blocking Connection (own executor + socket) is built on every call — caching one in plugin state via OnceLock would avoid that per-call setup if this ever gets polled. Not blocking, but worth considering for robustness.
Comment added by AI model Claude
There was a problem hiding this comment.
Deferred. Unrelated to this PR.
There was a problem hiding this comment.
Good point. I agree this is a valid Linux robustness concern: the timeout is per D-Bus method call, so several slow calls could stack up during one connection_status() request, and those run through spawn_blocking.
I think this is worth considering as a Linux follow-up, especially around either lowering the per-call timeout or adding an aggregate budget for the whole Linux query. I’d probably avoid caching the D-Bus connection unless we see polling or connection setup overhead become a real issue. Since this is Linux-specific and not part of the Android implementation, I think we can keep it out of this PR
|
@gabref @velocitysystems Claude added a few comments for consideration. |
c949c09 to
382ba7a
Compare
velocitysystems
left a comment
There was a problem hiding this comment.
Since this PR implements Android support, should the README support matrix be updated from "Planned"?
382ba7a to
78e28b5
Compare
78e28b5 to
6903143
Compare
Closes #10.
Adds Android support for
connection_status()using Tauri's mobile plugin bridge and Android'sConnectivityManager/NetworkCapabilitiesAPIs.Changes
android/src/main/.src/mobile.rs.ConnectionStatusfields:connected: active network withNET_CAPABILITY_INTERNETandNET_CAPABILITY_VALIDATEDmetered: absence ofNET_CAPABILITY_NOT_METERED, withNET_CAPABILITY_TEMPORARILY_NOT_METEREDtreated as unmetered while presentconstrained: Data Saver /RESTRICT_BACKGROUND_STATUS_ENABLEDconnectionType: Wi-Fi, Ethernet, Cellular, or Unknownandroid.permission.ACCESS_NETWORK_STATEto the Android manifest.src/platform.rsand added a separate mobile bridge path for Android and future mobile platforms.adbcommands and tested scenarios.Testing
Automated:
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningsnpm testnpm run eslintnpm run type-checknpm run markdownlintCOMMITLINT_FROM=HEAD~1 COMMITLINT_TO=HEAD npm run commitlint:tauri-plugin-connectivity:testDebugUnitTestManual Android testing with the example app:
Android debug build was also verified with: