2nd attempt to fix double unregistering receivers
This commit is contained in:
@@ -401,7 +401,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
|
|||||||
}
|
}
|
||||||
private fun cleanLocked() {
|
private fun cleanLocked() {
|
||||||
if (receiverRegistered) {
|
if (receiverRegistered) {
|
||||||
unregisterReceiver(receiver)
|
ensureReceiverUnregistered(receiver)
|
||||||
receiverRegistered = false
|
receiverRegistered = false
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= 28) {
|
if (Build.VERSION.SDK_INT >= 28) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import be.mygod.vpnhotspot.net.TetheringManager.tetheredIfaces
|
|||||||
import be.mygod.vpnhotspot.net.monitor.IpNeighbourMonitor
|
import be.mygod.vpnhotspot.net.monitor.IpNeighbourMonitor
|
||||||
import be.mygod.vpnhotspot.util.Event0
|
import be.mygod.vpnhotspot.util.Event0
|
||||||
import be.mygod.vpnhotspot.util.broadcastReceiver
|
import be.mygod.vpnhotspot.util.broadcastReceiver
|
||||||
|
import be.mygod.vpnhotspot.util.ensureReceiverUnregistered
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
@@ -117,7 +118,7 @@ class TetheringService : IpNeighbourMonitoringService(), CoroutineScope {
|
|||||||
|
|
||||||
private fun unregisterReceiver() {
|
private fun unregisterReceiver() {
|
||||||
if (receiverRegistered) {
|
if (receiverRegistered) {
|
||||||
unregisterReceiver(receiver)
|
ensureReceiverUnregistered(receiver)
|
||||||
IpNeighbourMonitor.unregisterCallback(this)
|
IpNeighbourMonitor.unregisterCallback(this)
|
||||||
receiverRegistered = false
|
receiverRegistered = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ fun Long.toPluralInt(): Int {
|
|||||||
return (this % 1000000000).toInt() + 1000000000
|
return (this % 1000000000).toInt() + 1000000000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.ensureReceiverUnregistered(receiver: BroadcastReceiver) {
|
||||||
|
try {
|
||||||
|
unregisterReceiver(receiver)
|
||||||
|
} catch (_: IllegalArgumentException) { }
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("Recycle")
|
@SuppressLint("Recycle")
|
||||||
fun <T> useParcel(block: (Parcel) -> T) = Parcel.obtain().run {
|
fun <T> useParcel(block: (Parcel) -> T) = Parcel.obtain().run {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user