Allow user to turn off safe mode on Android 10 (Mar 2020 or newer)

Fixes #153.

Basically, this "forward"-ports a workaround for Android 9- thanks to Jimmy Chen.
As a consequence, #31 might reoccur if you turn off safe mode.
This commit is contained in:
Mygod
2020-04-22 12:21:14 +08:00
parent 0dbf4b3b64
commit 3ba9a322c2
12 changed files with 121 additions and 88 deletions

View File

@@ -7,6 +7,7 @@ import be.mygod.vpnhotspot.net.Routing
import be.mygod.vpnhotspot.net.wifi.WifiDoubleLock
import be.mygod.vpnhotspot.widget.SmartSnackbar
import timber.log.Timber
import java.net.NetworkInterface
abstract class RoutingManager(private val caller: Any, val downstream: String, private val isWifi: Boolean) {
companion object {
@@ -42,7 +43,7 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
/**
* Both repeater and local-only hotspot are Wi-Fi based.
*/
class LocalOnly(caller: Any, downstream: String) : RoutingManager(caller, downstream, true) {
open class LocalOnly(caller: Any, downstream: String) : RoutingManager(caller, downstream, true) {
override fun Routing.configure() {
ipForward() // local only interfaces need to enable ip_forward
forward()
@@ -63,8 +64,10 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
else -> error("Double routing detected for $downstream from $caller != ${other.caller}")
}
open fun ifaceHandler(iface: NetworkInterface) { }
private fun initRouting() = try {
routing = Routing(caller, downstream).apply {
routing = Routing(caller, downstream, this::ifaceHandler).apply {
try {
configure()
} catch (e: Exception) {