aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-17 13:29:48 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-17 13:29:48 +0200
commit0030b5ce5a11ec564a9e3b3fc1f7f4342996bad3 (patch)
tree085d6934a74cec0ebfd13ba6015022412362271c /packages
parent165847da1ca3c3be627b5968bc77e9a11b3385cb (diff)
downloadmeshbay-0030b5ce5a11ec564a9e3b3fc1f7f4342996bad3.tar.gz
feat(android): tell the page when the phone changes network
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages')
-rw-r--r--packages/meshbay-android/app/src/main/kotlin/org/meshbay/client/MainActivity.kt14
-rw-r--r--packages/meshbay-hub/tests/test_android_shell.py12
2 files changed, 26 insertions, 0 deletions
diff --git a/packages/meshbay-android/app/src/main/kotlin/org/meshbay/client/MainActivity.kt b/packages/meshbay-android/app/src/main/kotlin/org/meshbay/client/MainActivity.kt
index 7ec81693..75ac0156 100644
--- a/packages/meshbay-android/app/src/main/kotlin/org/meshbay/client/MainActivity.kt
+++ b/packages/meshbay-android/app/src/main/kotlin/org/meshbay/client/MainActivity.kt
@@ -353,11 +353,25 @@ class MainActivity : Activity() {
* Tells the page when the network becomes unmetered or stops being: a
* backup waiting for Wi-Fi starts, one running on it stops. An event on the
* window, carrying the one boolean and nothing about the network.
+ *
+ * And when the phone moves to another network altogether, mobile data to
+ * Wi-Fi or back: a connection to a node may be running over the one just
+ * left, and the page checks it (transport.js onNetworkChange). Nothing
+ * about either network goes with it.
*/
private fun watchNetwork() {
val cm = getSystemService(android.net.ConnectivityManager::class.java)
var last: Boolean? = null
+ var current: android.net.Network? = null
val callback = object : android.net.ConnectivityManager.NetworkCallback() {
+ override fun onAvailable(n: android.net.Network) {
+ val moved = current != null && current != n
+ current = n
+ if (moved) runOnUiThread {
+ if (::web.isInitialized) web.evaluateJavascript(
+ "window.dispatchEvent(new Event('meshbay-default-network'));", null)
+ }
+ }
override fun onCapabilitiesChanged(n: android.net.Network, caps: android.net.NetworkCapabilities) = tell()
override fun onLost(n: android.net.Network) = tell()
private fun tell() {
diff --git a/packages/meshbay-hub/tests/test_android_shell.py b/packages/meshbay-hub/tests/test_android_shell.py
index cba4b320..eedc1988 100644
--- a/packages/meshbay-hub/tests/test_android_shell.py
+++ b/packages/meshbay-hub/tests/test_android_shell.py
@@ -263,6 +263,18 @@ def test_the_local_network_is_asked_for_when_a_group_opens():
assert "lanAsked = true" in asked[1][:200]
+def test_the_page_hears_when_the_phone_changes_network():
+ """A connection to the node may run over the network the phone just left,
+ and the page checks it then (transport.js onNetworkChange). Said by an
+ event that carries nothing about either network."""
+ activity = _read(SRC / "MainActivity.kt")
+ watch = activity.split("private fun watchNetwork()", 1)[1].split("\n override fun ", 1)[0]
+ assert "override fun onAvailable" in watch
+ assert "new Event('meshbay-default-network')" in watch
+ from spa_source import transport_source
+ assert "'meshbay-default-network'" in transport_source()
+
+
def test_no_backup_carries_the_keys_away():
manifest = _read(APP / "src" / "main" / "AndroidManifest.xml")
assert 'android:allowBackup="false"' in manifest