[CrashFix]修正崩溃
java.lang.RuntimeException: android.os.DeadSystemException
This commit is contained in:
@@ -35,15 +35,23 @@ internal class GpsImpl(ctx: Context): IFlow<GpsStatus>(ctx) {
|
||||
}
|
||||
|
||||
private val onClose = {
|
||||
send(false, PermissionUtils.isGranted(Manifest.permission.ACCESS_FINE_LOCATION))
|
||||
send(false, isGrandFineLocation())
|
||||
}
|
||||
|
||||
private val onOpen = {
|
||||
send(true, PermissionUtils.isGranted(Manifest.permission.ACCESS_FINE_LOCATION))
|
||||
send(true, isGrandFineLocation())
|
||||
}
|
||||
|
||||
private fun isGrandFineLocation(): Boolean = try {
|
||||
PermissionUtils.isGranted(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
override fun onCreate() {
|
||||
val isGranted = PermissionUtils.isGranted(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
val isGranted = isGrandFineLocation()
|
||||
send(isLocationEnabled(), isGranted)
|
||||
if (!isGranted) {
|
||||
PermissionUtils.requestAccessFineLocation(object : SimpleCallback {
|
||||
|
||||
@@ -78,12 +78,21 @@ internal class NetsImpl(ctx: Context): IFlow<NetStatus>(ctx) {
|
||||
private var loopCheckAndSendJob: Job? = null
|
||||
|
||||
private fun checkAndSend() {
|
||||
val connectionInfo = wifiMgr.connectionInfo
|
||||
val enabled = isNetConnected()
|
||||
val name = if (isLocationEnabled()) connectionInfo.ssid?.replace(Regex("[\\W]"), "") else "WI-FI"
|
||||
loopCheckAndSendJob?.safeCancel()
|
||||
launch(Dispatchers.Default) { delay(1000); checkAndSend() }.also { loopCheckAndSendJob = it }
|
||||
send(enabled, name)
|
||||
launch(Dispatchers.Default) {
|
||||
val connectionInfo = wifiMgr.connectionInfo
|
||||
val enabled = isNetConnected()
|
||||
val name =
|
||||
try {
|
||||
if (isLocationEnabled()) connectionInfo.ssid?.replace(Regex("[\\W]"), "") else "WI-FI"
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
"WI-FI"
|
||||
}
|
||||
send(enabled, name)
|
||||
delay(1000);
|
||||
checkAndSend()
|
||||
}.also { loopCheckAndSendJob = it }
|
||||
}
|
||||
|
||||
private fun isLocationEnabled() =
|
||||
|
||||
Reference in New Issue
Block a user