Name threads for better debugging experience
Also removes an unnecessary thread.
This commit is contained in:
@@ -155,7 +155,7 @@ class AppManager : AppCompatActivity(), Toolbar.OnMenuItemClickListener {
|
||||
appListView.visibility = View.GONE
|
||||
fastScroller.visibility = View.GONE
|
||||
loadingView.visibility = View.VISIBLE
|
||||
thread {
|
||||
thread("AppManager-loader") {
|
||||
val adapter = appListView.adapter as AppsAdapter
|
||||
do {
|
||||
appsLoading.set(true)
|
||||
|
||||
@@ -266,18 +266,20 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, Drawe
|
||||
++testCount
|
||||
statusText.setText(R.string.connection_test_testing)
|
||||
val id = testCount // it would change by other code
|
||||
thread { testConnection(id) }
|
||||
thread("ConnectionTest") { testConnection(id) }
|
||||
}
|
||||
}
|
||||
|
||||
fab = findViewById(R.id.fab)
|
||||
fab.setOnClickListener {
|
||||
if (state == BaseService.CONNECTED) app.stopService() else thread {
|
||||
if (BaseService.usingVpnMode) {
|
||||
when {
|
||||
state == BaseService.CONNECTED -> app.stopService()
|
||||
BaseService.usingVpnMode -> {
|
||||
val intent = VpnService.prepare(this)
|
||||
if (intent != null) startActivityForResult(intent, REQUEST_CONNECT)
|
||||
else app.handler.post { onActivityResult(REQUEST_CONNECT, Activity.RESULT_OK, null) }
|
||||
} else app.startService()
|
||||
else onActivityResult(REQUEST_CONNECT, Activity.RESULT_OK, null)
|
||||
}
|
||||
else -> app.startService()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -341,7 +341,7 @@ object BaseService {
|
||||
|
||||
data.changeState(CONNECTING)
|
||||
|
||||
thread {
|
||||
thread("$tag-Connecting") {
|
||||
try {
|
||||
if (profile.host == "198.199.101.152") {
|
||||
val client = OkHttpClient.Builder()
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.github.shadowsocks.BuildConfig
|
||||
import com.github.shadowsocks.JniHelper
|
||||
import com.github.shadowsocks.utils.Commandline
|
||||
import com.github.shadowsocks.utils.thread
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.concurrent.Semaphore
|
||||
@@ -42,8 +43,9 @@ class GuardedProcess(private val cmd: List<String>) {
|
||||
private var isDestroyed = false
|
||||
@Volatile
|
||||
private lateinit var process: Process
|
||||
private val name = File(cmd.first()).nameWithoutExtension
|
||||
|
||||
private fun streamLogger(input: InputStream, logger: (String, String) -> Int) = thread {
|
||||
private fun streamLogger(input: InputStream, logger: (String, String) -> Int) = thread("StreamLogger-$name") {
|
||||
try {
|
||||
input.bufferedReader().useLines { it.forEach { logger(TAG, it) } }
|
||||
} catch (_: IOException) { } // ignore
|
||||
@@ -53,7 +55,7 @@ class GuardedProcess(private val cmd: List<String>) {
|
||||
val semaphore = Semaphore(1)
|
||||
semaphore.acquire()
|
||||
var ioException: IOException? = null
|
||||
guardThread = thread(name = "GuardThread-" + cmd.first()) {
|
||||
guardThread = thread("GuardThread-$name") {
|
||||
try {
|
||||
var callback: (() -> Unit)? = null
|
||||
while (!isDestroyed) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.github.shadowsocks.App.Companion.app
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
abstract class LocalSocketListener(protected val tag: String) : Thread() {
|
||||
abstract class LocalSocketListener(protected val tag: String) : Thread(tag) {
|
||||
init {
|
||||
setUncaughtExceptionHandler(app::track)
|
||||
}
|
||||
|
||||
@@ -52,5 +52,5 @@ object TcpFastOpen {
|
||||
"else",
|
||||
" echo Failed.",
|
||||
"fi"), null, true)?.joinToString("\n")
|
||||
fun enabledAsync(value: Boolean) = thread { enabled(value) }.join(1000)
|
||||
fun enabledAsync(value: Boolean) = thread("TcpFastOpen") { enabled(value) }.join(1000)
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ fun broadcastReceiver(callback: (Context, Intent) -> Unit): BroadcastReceiver =
|
||||
/**
|
||||
* Wrapper for kotlin.concurrent.thread that tracks uncaught exceptions.
|
||||
*/
|
||||
fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClassLoader: ClassLoader? = null,
|
||||
name: String? = null, priority: Int = -1, block: () -> Unit): Thread {
|
||||
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(app::track)
|
||||
if (start) thread.start()
|
||||
|
||||
Reference in New Issue
Block a user