coroutines: convert low-hanging fruits

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2020-09-14 14:40:10 +02:00
parent dd0ff8fe60
commit 2fc0bb1a03
5 changed files with 106 additions and 73 deletions
@@ -19,6 +19,10 @@ import com.wireguard.android.R
import com.wireguard.android.backend.WgQuickBackend
import com.wireguard.android.util.AdminKnobs
import com.wireguard.android.util.ModuleLoader
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.ArrayList
import java.util.Arrays
@@ -117,11 +121,13 @@ class SettingsActivity : ThemeChangeAwareActivity() {
moduleInstaller?.parent?.removePreference(moduleInstaller)
} else {
kernelModuleDisabler?.parent?.removePreference(kernelModuleDisabler)
Application.getAsyncWorker().runAsync(Application.getRootShell()::start).whenComplete { _, e ->
if (e == null)
CoroutineScope(Dispatchers.Main).launch {
try {
withContext(Dispatchers.IO) { Application.getRootShell().start() }
moduleInstaller?.isVisible = true
else
} catch (_: Exception) {
moduleInstaller?.parent?.removePreference(moduleInstaller)
}
}
}
}