Deprecate thread helper
This commit is contained in:
@@ -5,7 +5,6 @@ import android.system.OsConstants
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.DebugHelper
|
||||
import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.util.thread
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import timber.log.Timber
|
||||
import java.io.IOException
|
||||
@@ -13,6 +12,7 @@ import java.io.InterruptedIOException
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ScheduledExecutorService
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
abstract class IpMonitor : Runnable {
|
||||
companion object {
|
||||
@@ -41,7 +41,7 @@ abstract class IpMonitor : Runnable {
|
||||
return
|
||||
}
|
||||
monitor = process
|
||||
val err = thread("${javaClass.simpleName}-error") {
|
||||
val err = thread(name = "${javaClass.simpleName}-error") {
|
||||
try {
|
||||
process.errorStream.bufferedReader().forEachLine { Timber.e(it) }
|
||||
} catch (_: InterruptedIOException) { } catch (e: IOException) {
|
||||
@@ -65,7 +65,7 @@ abstract class IpMonitor : Runnable {
|
||||
}
|
||||
|
||||
init {
|
||||
thread("${javaClass.simpleName}-input") {
|
||||
thread(name = "${javaClass.simpleName}-input") {
|
||||
val mode = Mode.valueOf(app.pref.getString(KEY, Mode.Poll.toString()) ?: "")
|
||||
if (mode != Mode.Poll) {
|
||||
if (mode != Mode.MonitorRoot) {
|
||||
@@ -83,14 +83,14 @@ abstract class IpMonitor : Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
fun flush() = thread("${javaClass.simpleName}-flush") { run() }
|
||||
fun flush() = thread(name = "${javaClass.simpleName}-flush") { run() }
|
||||
|
||||
override fun run() {
|
||||
val process = ProcessBuilder("ip", monitoredObject)
|
||||
.redirectErrorStream(true)
|
||||
.start()
|
||||
process.waitFor()
|
||||
thread("${javaClass.simpleName}-flush-error") {
|
||||
thread(name = "${javaClass.simpleName}-flush-error") {
|
||||
val err = process.errorStream.bufferedReader().readText()
|
||||
if (err.isNotBlank()) {
|
||||
Timber.e(err)
|
||||
|
||||
@@ -7,9 +7,6 @@ import android.widget.ImageView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.BindingAdapter
|
||||
import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import timber.log.Timber
|
||||
import java.net.InetAddress
|
||||
import java.net.NetworkInterface
|
||||
import java.net.SocketException
|
||||
@@ -62,20 +59,6 @@ private val parseNumericAddress by lazy {
|
||||
}
|
||||
fun parseNumericAddress(address: String) = parseNumericAddress.invoke(null, address) as InetAddress
|
||||
|
||||
/**
|
||||
* Wrapper for kotlin.concurrent.thread that silences uncaught exceptions.
|
||||
*/
|
||||
fun thread(name: String? = null, start: Boolean = true, isDaemon: Boolean = false,
|
||||
contextClassLoader: ClassLoader? = null, priority: Int = -1, block: () -> Unit): Thread {
|
||||
val thread = kotlin.concurrent.thread(false, isDaemon, contextClassLoader, name, priority, block)
|
||||
thread.setUncaughtExceptionHandler { _, e ->
|
||||
SmartSnackbar.make(R.string.noisy_su_failure).show()
|
||||
Timber.w(e)
|
||||
}
|
||||
if (start) thread.start()
|
||||
return thread
|
||||
}
|
||||
|
||||
fun Context.stopAndUnbind(connection: ServiceConnection) {
|
||||
connection.onServiceDisconnected(null)
|
||||
unbindService(connection)
|
||||
|
||||
Reference in New Issue
Block a user