Workaround bug in AOSP code

Fix #2983, https://issuetracker.google.com/issues/36984866
This commit is contained in:
topjohnwu 2020-07-20 22:22:57 -07:00
parent 2f02f9a580
commit fc67c0195f

View File

@ -68,8 +68,13 @@ abstract class SuRequestHandler(
private suspend fun init(name: String) = withContext(Dispatchers.IO) {
try {
if (Const.Version.atLeastCanary()) {
LocalServerSocket(name).use {
socket = async { it.accept() }.timedAwait() ?: throw SocketError()
val server = LocalServerSocket(name)
// Do NOT use Closable?.use(block) here as LocalServerSocket does
// not implement Closable on older Android platforms
try {
socket = async { server.accept() }.timedAwait() ?: throw SocketError()
} finally {
server.close()
}
} else {
socket = LocalSocket()