Support monitoring tethered interface

This would be useful to be used in together with Instant Tethering + Turn off hotspot automatically.

Refine #26, #53.
This commit is contained in:
Mygod
2019-02-06 01:26:06 +08:00
parent 6d6418b8e0
commit cbc65f989c
14 changed files with 174 additions and 61 deletions

View File

@@ -30,15 +30,21 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
}
}
var routing: Routing? = null
var started = false
private var routing: Routing? = null
init {
app.onPreCleanRoutings[this] = { routing?.stop() }
app.onRoutingsCleaned[this] = { initRouting() }
if (isWifi) WifiDoubleLock.acquire(this)
}
fun initRouting() = try {
fun start(): Boolean {
check(!started)
started = true
app.onPreCleanRoutings[this] = { routing?.stop() }
app.onRoutingsCleaned[this] = { initRouting() }
return initRouting()
}
private fun initRouting() = try {
routing = Routing(caller, downstream).apply {
try {
configure()
@@ -58,9 +64,15 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
protected abstract fun Routing.configure()
fun stop() {
if (!started) return
routing?.revert()
if (isWifi) WifiDoubleLock.release(this)
app.onPreCleanRoutings -= this
app.onRoutingsCleaned -= this
started = false
}
fun destroy() {
if (isWifi) WifiDoubleLock.release(this)
stop()
}
}