dadb icon indicating copy to clipboard operation
dadb copied to clipboard

Discover and create are hanging endlessly

Open sharpordie opened this issue 2 years ago • 3 comments

The discover and create functions are hanging as long as the allow button has not been clicked. Internally this is the open function that blocks endlessly. Is this the desired behavior? If so, why?

val dadb = Dadb.discover("192.168.1.62")

screen

It would be great to throw timeout exception after x seconds. Or throwing something like AuthorizationRequiredException or FailedAuthenticationException would be even better.

It's trivial with the official binary, you just have to check the connect output.

adb connect 192.168.1.62
* daemon not running; starting now at tcp:5037
* daemon started successfully
failed to authenticate to 192.168.1.62:5555

sharpordie avatar Jun 29 '22 05:06 sharpordie

I have edited the first post hoping to be more explicit about the problem and/or the possibility of improvement.

sharpordie avatar Jul 05 '22 12:07 sharpordie

You can defer the discover call, wait a little bit and throw exception if it's still null.

var dadb: Dadb? = null
val running = async { dadb = Dadb.discover("192.168.1.62") }
Thread.sleep(5000L)
running.cancel()
if (dadb == null) throw AuthorizationRequiredException()

lanzorg avatar Jul 07 '22 17:07 lanzorg

@lanzorg a coroutine might not be the best choice in this case as canceling it won't interrupt underlying operations in Dadb (it is not cooperative). Starting a thread {} and then calling thread.interrupt() would be a better option.

Either way, I will discuss it with the team and see if this is something that should be a part of the library itself

dmitry-zaitsev avatar Jul 14 '22 16:07 dmitry-zaitsev