[CrashFix]修正崩溃

java.lang.RuntimeException: android.os.DeadSystemException
This commit is contained in:
renwj
2022-09-06 11:00:57 +08:00
parent 4f9bccdd82
commit 52fa106101
2 changed files with 25 additions and 8 deletions

View File

@@ -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 {

View File

@@ -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() =