Better network detection and invalidation

This commit is contained in:
topjohnwu 2022-06-10 04:25:34 -07:00
parent 515f81944c
commit 50edb8d072
2 changed files with 6 additions and 3 deletions

View File

@ -10,7 +10,6 @@ import com.topjohnwu.magisk.core.repository.NetworkService
import com.topjohnwu.magisk.core.utils.net.NetworkObserver
import com.topjohnwu.magisk.ktx.getProperty
import com.topjohnwu.superuser.ShellUtils.fastCmd
import com.topjohnwu.superuser.internal.UiThreadHandler
val isRunningAsStub get() = Info.stub != null
@ -47,7 +46,8 @@ object Info {
val isConnected: LiveData<Boolean> by lazy {
MutableLiveData(false).also { field ->
NetworkObserver.observe(AppContext) {
UiThreadHandler.run { field.value = it }
remote = EMPTY_REMOTE
field.postValue(it)
}
}
}

View File

@ -46,7 +46,10 @@ class NetworkService(
private inline fun <T> safe(factory: () -> T): T? {
return try {
factory()
if (Info.isConnected.value == true)
factory()
else
null
} catch (e: Exception) {
Timber.e(e)
null