Fix crashes

This commit is contained in:
Mygod
2020-07-03 10:55:21 +08:00
parent 4b1101f41e
commit 05c4ba5b81
10 changed files with 37 additions and 28 deletions

View File

@@ -193,13 +193,14 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U
}
try {
callbackSpin()
if (active) throw RemoteException("Root process exited unexpectedly")
} catch (e: Throwable) {
process.destroy()
throw e
} finally {
if (DEBUG) Log.d(TAG, "Waiting for exit")
process.waitFor()
closeInternal(true)
withContext(NonCancellable) { closeInternal(true) }
}
check(process.errorStream.available() == 0) // stderr should not be used
}
@@ -280,7 +281,7 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U
private suspend fun closeInternal(fromWorker: Boolean = false) = mutex.withLock {
if (active) {
active = false
if (DEBUG) Log.d(TAG, "Shutting down from client")
if (DEBUG) Log.d(TAG, if (fromWorker) "Shutting down from worker" else "Shutting down from client")
try {
sendLocked(Shutdown())
output.close()

View File

@@ -42,8 +42,9 @@ abstract class RootSession {
}
private suspend fun closeLocked() {
val server = server
this.server = null
server?.close()
server = null
}
private fun startTimeoutLocked() {
check(timeoutJob == null)
@@ -51,8 +52,8 @@ abstract class RootSession {
delay(timeout)
mutex.withLock {
check(usersCount == 0L)
closeLocked()
timeoutJob = null
closeLocked()
}
}
}
@@ -75,14 +76,14 @@ abstract class RootSession {
when {
!server.active -> {
usersCount = 0
closeLocked()
closePending = false
closeLocked()
return@withLock
}
--usersCount > 0L -> return@withLock
closePending -> {
closeLocked()
closePending = false
closeLocked()
}
else -> startTimeoutLocked()
}

View File

@@ -39,7 +39,7 @@ interface RootCommandChannel<T : Parcelable?> : Parcelable {
}
@Parcelize
internal class CancelCommand(val index: Long) : RootCommandOneWay {
internal data class CancelCommand(val index: Long) : RootCommandOneWay {
override suspend fun execute() = error("Internal implementation")
}