From 618360a6c9a0036479273bf785b3603c5ce741de Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 12 Aug 2020 10:37:03 -0400 Subject: [PATCH] More informative error message --- .../be/mygod/librootkotlinx/RootServer.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt index 002d28e8..dee418cc 100644 --- a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt +++ b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt @@ -145,18 +145,21 @@ class RootServer { } catch (e: Exception) { throw NoShellException(e) } - - val token2 = UUID.randomUUID().toString() - val persistence = File(context.codeCacheDir, ".librootkotlinx-uuid") - val uuid = context.packageName + '@' + if (persistence.canRead()) persistence.readText() else { - UUID.randomUUID().toString().also { persistence.writeText(it) } + try { + val token2 = UUID.randomUUID().toString() + val persistence = File(context.codeCacheDir, ".librootkotlinx-uuid") + val uuid = context.packageName + '@' + if (persistence.canRead()) persistence.readText() else { + UUID.randomUUID().toString().also { persistence.writeText(it) } + } + val (script, relocated) = AppProcess.relocateScript(uuid) + script.appendln(AppProcess.launchString(context.packageCodePath, RootServer::class.java.name, relocated, + niceName) + " $token2") + writer.writeBytes(script.toString()) + writer.flush() + reader.lookForToken(token2) // wait for ready signal + } catch (e: Exception) { + throw RuntimeException("Failed to launch root daemon", e) } - val (script, relocated) = AppProcess.relocateScript(uuid) - script.appendln(AppProcess.launchString(context.packageCodePath, RootServer::class.java.name, relocated, - niceName) + " $token2") - writer.writeBytes(script.toString()) - writer.flush() - reader.lookForToken(token2) // wait for ready signal output = writer require(!active) active = true