Fix crash reported from rageshake
This commit is contained in:
parent
e1ea742023
commit
4280bc0780
|
@ -22,6 +22,7 @@ import android.content.IntentFilter
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.Network
|
import android.net.Network
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface NetworkCallbackStrategy {
|
internal interface NetworkCallbackStrategy {
|
||||||
|
@ -70,7 +71,16 @@ internal class PreferredNetworkCallbackStrategy @Inject constructor(context: Con
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unregister() {
|
override fun unregister() {
|
||||||
|
// It can crash after an application update, if not registered
|
||||||
|
val doUnregister = hasChangedCallback != null
|
||||||
hasChangedCallback = null
|
hasChangedCallback = null
|
||||||
|
if (doUnregister) {
|
||||||
|
// Add a try catch for safety
|
||||||
|
try {
|
||||||
conn.unregisterNetworkCallback(networkCallback)
|
conn.unregisterNetworkCallback(networkCallback)
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
Timber.e(t, "Unable to unregister network callback")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue