Fix persistent group on Android 11

Also only request persistent group when necessary.
This commit is contained in:
Mygod
2020-07-02 06:26:55 +08:00
parent a5adff4b65
commit d462b3ac07
6 changed files with 67 additions and 87 deletions

View File

@@ -28,8 +28,7 @@ import java.net.SocketException
*
* Once revert is called, this object no longer serves any purpose.
*/
class Routing(private val caller: Any, private val downstream: String,
ifaceHandler: (NetworkInterface) -> Unit) : IpNeighbourMonitor.Callback {
class Routing(private val caller: Any, private val downstream: String) : IpNeighbourMonitor.Callback {
companion object {
/**
* Since Android 5.0, RULE_PRIORITY_TETHERING = 18000.
@@ -130,7 +129,6 @@ class Routing(private val caller: Any, private val downstream: String,
private val hostAddress = try {
val iface = NetworkInterface.getByName(downstream) ?: error("iface not found")
ifaceHandler(iface)
val addresses = iface.interfaceAddresses!!.filter { it.address is Inet4Address }
if (addresses.size > 1) error("More than one addresses was found: $addresses")
addresses.first()