From fc67c0195f3d07f7be7ec62107f341b55f7dda3a Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 20 Jul 2020 22:22:57 -0700 Subject: [PATCH] Workaround bug in AOSP code Fix #2983, https://issuetracker.google.com/issues/36984866 --- .../com/topjohnwu/magisk/core/su/SuRequestHandler.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt b/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt index 731077351..3de65f036 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt @@ -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()