Skip to content

Commit

Permalink
fix: Add thread lock for RemoteRootService
Browse files Browse the repository at this point in the history
Change-Id: I7e2dce3118f8f06201f19e669a1079e8eb615c94
  • Loading branch information
XayahSuSuSu committed Sep 8, 2024
1 parent da97e47 commit b29b853
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import com.xayah.core.util.PathUtil
import com.xayah.core.util.model.ShellResult
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.decodeFromByteArray
import kotlinx.serialization.encodeToByteArray
Expand All @@ -39,6 +41,7 @@ import kotlin.coroutines.suspendCoroutine
class RemoteRootService(private val context: Context) {
private var mService: IRemoteRootService? = null
private var mConnection: ServiceConnection? = null
private var mutex = Mutex()
private var retries = 0
private val intent by lazy {
Intent().apply {
Expand Down Expand Up @@ -117,7 +120,7 @@ class RemoteRootService(private val context: Context) {
mService = null
}

private suspend fun getService(): IRemoteRootService {
private suspend fun getService(): IRemoteRootService = mutex.withLock {
return tryOnScope(
block = {
withMainContext {
Expand Down

0 comments on commit b29b853

Please sign in to comment.