Smart Locations, Ping and Speedtest: integration checklist for apps
The SDK measures from the device's real network. Every rule below protects one of two things: the cache those measurements are stored in, or the guarantee that a measurement never runs through the VPN tunnel.
Must
-
1. Never wipe the Smart Location cache. Do not delete the
smart_location_resultsstorage key: not on sign-out, not on app update, not on "reset". The cache is keyed by network (country, ISP, ASN, SSID, BSSID), not by account, and the SDK expires entries itself. A wiped cache means the next connect has to measure first. -
2. Never run two measurements at the same time. Ping (
pingLocations), Smart Locations (createSmartLocationMeasurements) and Speedtest share one slot. A second call while any of the three is running throwsInstanceDiscoveryProcessAlreadyRunning(process: …). This includes a Smart Locations call withrefresh=falsethat misses the cache. Keep one in-flight task per process and let other callers await its result instead of starting their own. -
3. Cancel any running measurement before starting a VPN connection. Call
instanceDiscovery.cancelOngoingOperation()(Ping, Smart Locations) and the Speedtest object'scancelOngoingOperation(), await both, then start the tunnel. The SDK checks the connection state only once, when a measurement starts. If the tunnel comes up mid-run, the remaining probes travel through the VPN, the run takes its full budget (30 s), and the wrong results are cached as if they were measured off-VPN. -
4. Tell the SDK about every network change:
sdkManager.networkChanged(). A network change is: Wi-Fi ↔ cellular, a different Wi-Fi, and every VPN state change (connected, disconnected, location switched). The call drops the cached geolocation, which is what the SDK uses to decide whether it is connected and which cache entry applies.- After a disconnect, call it before requesting a new measurement.
- Calls within 5 seconds of the previous one are ignored. If two changes happen back to back, call it again once the state has settled.
-
5. Never start a measurement while the VPN is connected or connecting. The SDK refuses to refresh when it knows it is connected, but it only knows what rule 4 told it. While connected, read the cached list (
refresh=false). -
6. Never connect to an arbitrary location when Smart Locations fails. If a call fails, use the cached list, or the last list you showed. Do not fall back to the first entry of the location catalog.
Should
-
7. Use fast mode on the connect path.
fast_mode=trueanswers in about 1–2 seconds (latency only, one good location is enough). A full run takes up to 30 seconds. Run the full measurement in the background while disconnected, never between the user's tap and the connection. -
8. Treat expected errors as expected.
OperationRunnerProcessAborted: you cancelled it (rule 3). Not an error.InstanceDiscoveryProcessAlreadyRunning: await the running call (rule 2).NotAllowedWhileConnected: the VPN is up (rule 5).- Do not call measurement APIs during or after sign-out.
Optional
-
9. Set SSID and BSSID so results are stored per network.
configuration.setCurrentNetworkName(ssid)andconfiguration.setCurrentNetworkId(bssid). These are two different setters. With them the SDK keeps separate results per Wi-Fi network and separates Wi-Fi from cellular. Without them, all networks of the same ISP share one entry. If you use them, you must keep them current:- update both on every network change, before calling
networkChanged(); - set both to an empty string on cellular or when the SSID is unknown.
A stale SSID is worse than none: cellular results are then stored as that Wi-Fi's results.
- update both on every network change, before calling
Order of operations
User taps Connect
- Cancel running measurements and await (rule 3).
- Pick the location from the cached list, or a fast-mode run if there is none.
- Start the tunnel.
- Once connected:
networkChanged().
VPN disconnects
networkChanged().- Only then request a refresh, if one is due.
Network changes while disconnected
- Update SSID/BSSID (if used).
networkChanged().- Request Smart Locations with
refresh=false; the SDK measures if this network has no entry yet.