Handle unexpected death

This commit is contained in:
Mygod
2021-05-09 10:23:21 -04:00
parent 9752b328fb
commit a344398624
2 changed files with 6 additions and 6 deletions

View File

@@ -88,6 +88,8 @@ class RootServer {
} }
} }
class UnexpectedExitException : RemoteException("Root process exited unexpectedly")
private lateinit var process: Process private lateinit var process: Process
/** /**
* Thread safety: needs to be protected by mutex. * Thread safety: needs to be protected by mutex.
@@ -206,7 +208,7 @@ class RootServer {
} }
try { try {
callbackSpin() callbackSpin()
if (active) throw RemoteException("Root process exited unexpectedly") if (active) throw UnexpectedExitException()
} catch (e: Throwable) { } catch (e: Throwable) {
process.destroy() process.destroy()
throw e throw e
@@ -317,6 +319,8 @@ class RootServer {
} catch (e: TimeoutCancellationException) { } catch (e: TimeoutCancellationException) {
Logger.me.w("Closing the instance has timed out", e) Logger.me.w("Closing the instance has timed out", e)
if (Build.VERSION.SDK_INT < 26) process.destroy() else if (process.isAlive) process.destroyForcibly() if (Build.VERSION.SDK_INT < 26) process.destroy() else if (process.isAlive) process.destroyForcibly()
} catch (e: UnexpectedExitException) {
Logger.me.w(e.message)
} }
} }

View File

@@ -58,11 +58,7 @@ abstract class RootSession {
mutex.withLock { mutex.withLock {
check(usersCount == 0L) check(usersCount == 0L)
timeoutJob = null timeoutJob = null
try {
closeLocked() closeLocked()
} catch (e: Exception) {
Logger.me.e("Closing RootServer on timeout failed", e)
}
} }
} }
} }