Fix VPN connections change handlers

This commit is contained in:
Mygod
2018-01-13 12:13:22 +08:00
parent 57b9463a6f
commit c25b7a3f0c
4 changed files with 7 additions and 6 deletions

View File

@@ -160,7 +160,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnListener.C
}
Status.ACTIVE -> {
val routing = routing
assert(!routing!!.started)
check(!routing!!.started)
initRouting(ifname, routing.downstream, routing.hostAddress)
}
else -> throw RuntimeException("RepeaterService is in unexpected state when receiving onAvailable")
@@ -248,13 +248,13 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnListener.C
})
}
private fun unregisterReceiver() {
VpnListener.unregisterCallback(this)
if (receiverRegistered) {
unregisterReceiver(receiver)
receiverRegistered = false
}
}
private fun clean() {
VpnListener.unregisterCallback(this)
unregisterReceiver()
if (routing?.stop() == false)
Toast.makeText(this, "Something went wrong, please check logcat.", Toast.LENGTH_SHORT).show()