Skip to content

Commit 04b8e11

Browse files
committed
fix(android): deliver default-interface updates synchronously
checkDefaultInterfaceUpdate dispatched each updateDefaultInterface call to GlobalScope.launch(Dispatchers.IO), so successive default-network changes could be applied out of order, pinning a stale interface index (Go side is last-writer-wins). The golang/go#68760 stack workaround that the launch was duplicating is already handled on the Go side (libbox SetupOptions.FixAndroidStack, enabled by radiance), so delivering synchronously preserves the network-change ordering that DefaultNetworkListener already guarantees. Remove the now-unused Bugs.fixAndroidStack helper.
1 parent 3a26323 commit 04b8e11

2 files changed

Lines changed: 7 additions & 32 deletions

File tree

android/app/src/main/kotlin/org/getlantern/lantern/service/DefaultNetworkMonitor.kt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import android.net.Network
44
import android.os.Build
55
import android.system.Os
66

7-
import kotlinx.coroutines.Dispatchers
8-
import kotlinx.coroutines.GlobalScope
9-
import kotlinx.coroutines.launch
107
import lantern.io.libbox.InterfaceUpdateListener
118
import org.getlantern.lantern.LanternApp
12-
import org.getlantern.lantern.utils.Bugs
139
import java.net.NetworkInterface
1410

1511
object DefaultNetworkMonitor {
12+
private const val NO_INTERFACE_NAME = ""
13+
private const val NO_INTERFACE_INDEX = -1
1614

1715
var defaultNetwork: Network? = null
1816
private var listener: InterfaceUpdateListener? = null
@@ -84,24 +82,14 @@ object DefaultNetworkMonitor {
8482
Thread.sleep(100)
8583
continue
8684
}
87-
if (Bugs.fixAndroidStack) {
88-
GlobalScope.launch(Dispatchers.IO) {
89-
listener.updateDefaultInterface(interfaceName, interfaceIndex, false, false)
90-
}
91-
} else {
92-
listener.updateDefaultInterface(interfaceName, interfaceIndex, false, false)
93-
}
85+
// Delivered synchronously so updates apply in network-change order.
86+
// The golang/go#68760 stack workaround is handled on the Go side
87+
listener.updateDefaultInterface(interfaceName, interfaceIndex, false, false)
9488
return // successfully notified, don't retry
9589
}
9690
} else {
97-
if (Bugs.fixAndroidStack) {
98-
GlobalScope.launch(Dispatchers.IO) {
99-
listener.updateDefaultInterface("", -1, false, false)
100-
}
101-
} else {
102-
listener.updateDefaultInterface("", -1, false, false)
103-
}
91+
listener.updateDefaultInterface(NO_INTERFACE_NAME, NO_INTERFACE_INDEX, false, false)
10492
}
10593
}
10694

107-
}
95+
}

android/app/src/main/kotlin/org/getlantern/lantern/utils/Bugs.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)