From 973c947d4acd02dd9ab762d7a44723a5357ba135 Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 4 Nov 2020 07:27:24 +0800 Subject: [PATCH] Shutdown RootServer forcibly if timeout --- .../src/main/java/be/mygod/librootkotlinx/RootServer.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt index 12ef9e17..9b8e5a68 100644 --- a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt +++ b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt @@ -1,6 +1,7 @@ package be.mygod.librootkotlinx import android.content.Context +import android.os.Build import android.os.Looper import android.os.Parcelable import android.os.RemoteException @@ -314,7 +315,12 @@ class RootServer { */ suspend fun close() { closeInternal() - callbackListenerExit.await() + try { + withTimeout(10000) { callbackListenerExit.await() } + } catch (e: TimeoutCancellationException) { + Logger.me.w("Closing the instance has timed out", e) + if (Build.VERSION.SDK_INT < 26) process.destroy() else if (process.isAlive) process.destroyForcibly() + } } companion object {