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()

View File

@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.net.wifi.WpsInfo
import android.net.wifi.p2p.WifiP2pGroup
import android.net.wifi.p2p.WifiP2pManager
import android.os.Build
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.util.callSuper
import kotlinx.coroutines.CompletableDeferred
@@ -27,9 +26,6 @@ object WifiP2pManagerHelper {
}
const val UNSUPPORTED = -2
val ACTION_WIFI_P2P_PERSISTENT_GROUPS_CHANGED = if (Build.VERSION.SDK_INT >= 30) {
"android.net.wifi.p2p.action.WIFI_P2P_PERSISTENT_GROUPS_CHANGED"
} else "android.net.wifi.p2p.PERSISTENT_GROUPS_CHANGED"
/**
* Available since Android 4.4.