Fix onServiceDisconnected not called
This commit is contained in:
@@ -137,11 +137,10 @@ class RepeaterFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClickL
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
if (name == ComponentName(requireContext(), ClientMonitorService::class.java)) {
|
||||
val clients = clients ?: return
|
||||
val clients = clients
|
||||
if (clients != null) {
|
||||
this.clients = null
|
||||
clients.clientsChanged -= this
|
||||
return
|
||||
}
|
||||
val binder = binder ?: return
|
||||
this.binder = null
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.service.quicksettings.Tile
|
||||
import android.service.quicksettings.TileService
|
||||
import android.support.annotation.RequiresApi
|
||||
import android.support.v4.content.ContextCompat
|
||||
import be.mygod.vpnhotspot.util.stopAndUnbind
|
||||
|
||||
@RequiresApi(24)
|
||||
class RepeaterTileService : TileService(), ServiceConnection {
|
||||
@@ -26,7 +27,7 @@ class RepeaterTileService : TileService(), ServiceConnection {
|
||||
|
||||
override fun onStopListening() {
|
||||
super.onStopListening()
|
||||
unbindService(this)
|
||||
stopAndUnbind(this)
|
||||
}
|
||||
|
||||
override fun onClick() {
|
||||
|
||||
@@ -370,17 +370,10 @@ class TetheringFragment : Fragment(), ServiceConnection {
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
val context = requireContext()
|
||||
when (name) {
|
||||
ComponentName(context, TetheringService::class.java) -> {
|
||||
tetheringBinder?.fragment = null
|
||||
tetheringBinder = null
|
||||
context.unregisterReceiver(receiver)
|
||||
}
|
||||
ComponentName(context, LocalOnlyHotspotService::class.java) -> {
|
||||
hotspotBinder?.fragment = null
|
||||
hotspotBinder = null
|
||||
}
|
||||
else -> throw IllegalArgumentException("name")
|
||||
}
|
||||
tetheringBinder?.fragment = null
|
||||
tetheringBinder = null
|
||||
context.unregisterReceiver(receiver)
|
||||
hotspotBinder?.fragment = null
|
||||
hotspotBinder = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,4 +42,4 @@ abstract class Client {
|
||||
return true
|
||||
}
|
||||
override fun hashCode() = Objects.hash(iface, mac, ip)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import be.mygod.vpnhotspot.net.IpNeighbourMonitor
|
||||
import be.mygod.vpnhotspot.net.TetheringManager
|
||||
import be.mygod.vpnhotspot.util.StickyEvent1
|
||||
import be.mygod.vpnhotspot.util.broadcastReceiver
|
||||
import be.mygod.vpnhotspot.util.stopAndUnbind
|
||||
|
||||
class ClientMonitorService : Service(), ServiceConnection, IpNeighbourMonitor.Callback {
|
||||
inner class Binder : android.os.Binder() {
|
||||
@@ -70,7 +71,7 @@ class ClientMonitorService : Service(), ServiceConnection, IpNeighbourMonitor.Ca
|
||||
override fun onDestroy() {
|
||||
unregisterReceiver(receiver)
|
||||
IpNeighbourMonitor.unregisterCallback(this)
|
||||
unbindService(this)
|
||||
stopAndUnbind(this)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
|
||||
@@ -30,5 +30,5 @@ class ServiceForegroundConnector(private val host: ServiceConnection, private va
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||
fun onStop() = context.unbindService(host)
|
||||
fun onStop() = context.stopAndUnbind(host)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package be.mygod.vpnhotspot.util
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.*
|
||||
import android.databinding.BindingAdapter
|
||||
import android.support.annotation.DrawableRes
|
||||
import android.util.Log
|
||||
@@ -53,3 +50,8 @@ fun thread(name: String? = null, start: Boolean = true, isDaemon: Boolean = fals
|
||||
if (start) thread.start()
|
||||
return thread
|
||||
}
|
||||
|
||||
fun Context.stopAndUnbind(connection: ServiceConnection) {
|
||||
connection.onServiceDisconnected(null)
|
||||
unbindService(connection)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user