@@ -17,8 +17,6 @@ import kotlinx.coroutines.channels.trySendBlocking
1717import kotlinx.coroutines.flow.MutableStateFlow
1818import kotlinx.coroutines.flow.first
1919import kotlinx.coroutines.flow.update
20- import kotlinx.coroutines.sync.Mutex
21- import kotlinx.coroutines.sync.withLock
2220import kotlinx.coroutines.withContext
2321import kotlinx.coroutines.withTimeout
2422import timber.log.Timber
@@ -40,8 +38,6 @@ internal class AdbMdns(ctx: Context, private val serviceType: AdbServiceType) {
4038 private var serviceResolvedChannel: Channel <NsdServiceInfo ?>? = null
4139
4240 private val isDiscovering: MutableStateFlow <Boolean > = MutableStateFlow (false )
43- private val discoveredPort: MutableStateFlow <Int ?> = MutableStateFlow (null )
44- private val discoverMutex: Mutex = Mutex ()
4541
4642 private val resolveListener: NsdManager .ResolveListener = object : NsdManager .ResolveListener {
4743 override fun onResolveFailed (nsdServiceInfo : NsdServiceInfo , i : Int ) {
@@ -106,19 +102,10 @@ internal class AdbMdns(ctx: Context, private val serviceType: AdbServiceType) {
106102
107103 @OptIn(ExperimentalCoroutinesApi ::class )
108104 suspend fun discoverPort (): Int? {
109- discoverMutex.withLock {
110- val currentPort = discoveredPort.value
111-
112- if (currentPort == null || ! isPortAvailable(currentPort)) {
113- val port = withContext(Dispatchers .IO ) {
114- discoverPortInternal()
115- }
116- discoveredPort.value = port
117- return port
118- } else {
119- return currentPort
120- }
105+ val port = withContext(Dispatchers .IO ) {
106+ discoverPortInternal()
121107 }
108+ return port
122109 }
123110
124111 @OptIn(ExperimentalCoroutinesApi ::class )
0 commit comments