mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
fix(session): undo start-up work when a session is stopped while starting (#2840)
* fix(session): undo start-up work when a session is stopped while starting * style(session): drop the added comment --------- Co-authored-by: Tapuuk <177422350+Tapuuk@users.noreply.github.com> Co-authored-by: maxjivi05 <maxjividen@gmail.com>
This commit is contained in:
1 file changed
+49
-4
@@ -569,7 +569,15 @@ class SessionService : Service() {
|
||||
stopSession(-1, gen)
|
||||
return
|
||||
}
|
||||
if (!stillStarting()) {
|
||||
Log.i(TAG, "session stopped while its files were staging")
|
||||
return
|
||||
}
|
||||
SessionArtifacts.awaitCollections()
|
||||
if (!stillStarting()) {
|
||||
Log.i(TAG, "session stopped while earlier session logs were being collected")
|
||||
return
|
||||
}
|
||||
SessionArtifacts.finishAbandoned(this, beforeGuestStart = true)
|
||||
VacDiagnostics.arm(this)
|
||||
com.droiddeck.launcher.agent.AgentGuest.reset(this)
|
||||
@@ -582,6 +590,7 @@ class SessionService : Service() {
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "could not publish the game environment", e)
|
||||
stopSession(-1, gen)
|
||||
abandonStart(gen, sessionDir)
|
||||
return
|
||||
}
|
||||
val sessionLog = File(sessionDir, "session.log")
|
||||
@@ -610,6 +619,7 @@ class SessionService : Service() {
|
||||
Log.e(TAG, "Could not resolve the selected Linux Vulkan driver", e)
|
||||
failSession(gen, "VULKAN_DRIVER_UNAVAILABLE", e.message ?: "Selected Linux Vulkan driver is unavailable", -1)
|
||||
stopSession(-1, gen)
|
||||
abandonStart(gen, sessionDir)
|
||||
return
|
||||
}
|
||||
if (steamHere) guest.add("DD_EPIC_APP_ID=" + com.droiddeck.launcher.stores.epic.EpicClient.shortcutAppId)
|
||||
@@ -710,6 +720,7 @@ class SessionService : Service() {
|
||||
if (program.isNullOrEmpty()) {
|
||||
Log.e(TAG, "run mode without a program")
|
||||
stopSession(65, gen)
|
||||
abandonStart(gen, sessionDir)
|
||||
return
|
||||
}
|
||||
guest.add(program)
|
||||
@@ -805,15 +816,25 @@ class SessionService : Service() {
|
||||
components.add(deviceControls)
|
||||
if (gen != sessionGen || !SessionState.running) {
|
||||
Log.i(TAG, "session stopped while it was starting; not launching it")
|
||||
if (gen == sessionGen) components.clear()
|
||||
abandonStart(gen, sessionDir)
|
||||
return
|
||||
}
|
||||
val started = ArrayList<SessionPart>()
|
||||
try {
|
||||
components.forEach { it.start() }
|
||||
for (part in components.toList()) {
|
||||
if (!stillStarting()) {
|
||||
Log.i(TAG, "session stopped while its components were starting; stopping the ${started.size} already started")
|
||||
abandonStart(gen, sessionDir, started)
|
||||
return
|
||||
}
|
||||
started.add(part)
|
||||
part.start()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Could not start the session components", e)
|
||||
failSession(gen, "COMPONENT_START_FAILED", e.message ?: "Session component could not be started", -1)
|
||||
stopSession(-1, gen)
|
||||
abandonStart(gen, sessionDir, started)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -840,9 +861,8 @@ class SessionService : Service() {
|
||||
launchWatcher = null
|
||||
syncWatcher?.stopWatching()
|
||||
syncWatcher = null
|
||||
components.reversed().forEach { runCatching { it.stop() } }
|
||||
components.clear()
|
||||
}
|
||||
abandonStart(gen, sessionDir, started)
|
||||
if (pid > 1) Thread({ teardown(pid) }, "session-teardown").start()
|
||||
return
|
||||
}
|
||||
@@ -854,6 +874,7 @@ class SessionService : Service() {
|
||||
SessionEvents.record("guest.start_failed", mapOf("pid" to pid))
|
||||
failSession(gen, "GUEST_START_FAILED", "The guest process could not be started", pid)
|
||||
stopSession(-1, gen)
|
||||
abandonStart(gen, sessionDir, started)
|
||||
return
|
||||
}
|
||||
if (gen == sessionGen && SessionState.running) {
|
||||
@@ -908,6 +929,30 @@ class SessionService : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun abandonStart(gen: Int, sessionDir: File, started: List<SessionPart> = emptyList()) {
|
||||
val (ended, endedArch) = synchronized(stopLock) {
|
||||
if (gen != sessionGen || SessionState.running) return
|
||||
components.clear()
|
||||
GpuClockPin.stop(this)
|
||||
GameThreadHints.stop()
|
||||
com.droiddeck.launcher.stores.StoreLaunchRequests.stop()
|
||||
MemoryLog.stop()
|
||||
val ended = synchronized(SessionPaths) {
|
||||
if (SessionPaths.current() == sessionDir) SessionPaths.take() else null
|
||||
}
|
||||
if (ended != null) SessionArtifacts.collectionStarted(ended)
|
||||
ended to SessionState.steamClientArch
|
||||
}
|
||||
started.asReversed().forEach {
|
||||
try {
|
||||
it.stop()
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "stopping ${it.javaClass.simpleName}", e)
|
||||
}
|
||||
}
|
||||
if (ended != null) Thread({ collectSessionArtifacts(ended, endedArch) }, "session-collect").start()
|
||||
}
|
||||
|
||||
private fun openSessionFolder(): File {
|
||||
val sessionDir = SessionPaths.beginOrCurrent(this)
|
||||
val sessionLog = File(sessionDir, "session.log")
|
||||
|
||||
Reference in new issue
Block a user