Merge branch 'main' into feat/performance-fixes-2

This commit is contained in:
maxjivi05 committed 2026-10-01 16:40:42 -04:00
commit d09e7eaf32
11 files changed
+320 -15

No files matched your search

@@ -0,0 +1,94 @@
package com.droiddeck.launcher.session
import java.io.File
import java.nio.file.Files
import java.nio.file.LinkOption.NOFOLLOW_LINKS
import java.nio.file.StandardCopyOption.COPY_ATTRIBUTES
import java.security.MessageDigest
import java.util.Locale
/** Android shared storage cannot create the links in Wine prefixes or native Steam depots. */
object SecondaryLibrary {
private val bootstrapTools = linkedMapOf(
"4185400" to "SteamLinuxRuntime_4-arm64",
"4427310" to "Proton Experimental (ARM64)",
"4628740" to "Proton 11.0 (ARM64)",
)
fun privateRoot(files: File, library: File): File {
val digest = MessageDigest.getInstance("SHA-256").digest(library.canonicalPath.toByteArray())
.joinToString("") { "%02x".format(it.toInt() and 255) }
return File(files, "steam-libraries/$digest")
}
/** Parent binds come first; the more specific private directories override them in PRoot. */
fun binds(files: File, library: File): List<String> {
val private = privateRoot(files, library)
val apps = File(library, "steamapps")
val tools = LinkedHashMap(bootstrapTools)
// Include other installed Proton/runtime versions, without routing ordinary game depots.
apps.listFiles()?.filter { it.name.matches(Regex("appmanifest_\\d+\\.acf")) }?.forEach { manifest ->
val text = manifest.readText()
val id = Regex("\"appid\"\\s+\"(\\d+)\"").find(text)?.groupValues?.get(1)
val dir = Regex("\"installdir\"\\s+\"([^\"]+)\"").find(text)?.groupValues?.get(1)
if (id != null && dir != null && File(dir).name == dir &&
(dir.startsWith("Proton ") || dir.startsWith("SteamLinuxRuntime"))) tools[id] = dir
}
val overrides = ArrayList<Pair<File, String>>()
for (name in listOf("compatdata", "shadercache")) {
val target = File(private, "steamapps/$name")
migrate(File(apps, name), target)
overrides.add(target to "steamapps/$name")
}
for ((id, dir) in tools) {
for (relative in listOf("steamapps/common/$dir", "steamapps/downloading/$id")) {
val target = File(private, relative)
migrate(File(library, relative), target)
// FUSE discarded the executable bits. Steam will restore the depot's exact modes
// on verification; its launchers must already be executable when importing it.
target.walkTopDown().filter { it.isFile }.forEach { it.setExecutable(true, true) }
overrides.add(target to relative)
// Steam normalizes depot install directories to lowercase on Android's
// case-insensitive shared storage. PRoot binds are case-sensitive, so both
// spellings must reach the same private directory during the commit.
val lower = relative.lowercase(Locale.ROOT)
if (lower != relative) overrides.add(target to lower)
}
}
return listOf("/mnt/droiddeck-sd", "/mnt/bannerlator-sd").flatMap { guest ->
listOf("${library.path}:$guest") + overrides.map { (host, relative) -> "${host.path}:$guest/$relative" }
}
}
/** Copy once into a staging directory; retain the source and never merge over a live prefix. */
private fun migrate(source: File, target: File) {
val migrated = File(target.parentFile, ".${target.name}.migrated")
if (target.isDirectory) {
if (!migrated.isFile) migrated.writeText(source.canonicalPath)
return
}
check(target.parentFile!!.isDirectory || target.parentFile!!.mkdirs()) { "cannot create ${target.parent}" }
if (!source.isDirectory || migrated.isFile) {
check(target.mkdirs()) { "cannot create $target" }
if (!migrated.isFile) migrated.writeText(source.canonicalPath)
return
}
val stage = File(target.parentFile, "${target.name}.migrating")
check(!stage.exists() || stage.deleteRecursively()) { "cannot clear $stage" }
check(stage.mkdirs()) { "cannot create $stage" }
try {
Files.walk(source.toPath()).use { paths ->
paths.forEach { path ->
val destination = stage.toPath().resolve(source.toPath().relativize(path))
if (Files.isDirectory(path, NOFOLLOW_LINKS)) Files.createDirectories(destination)
else Files.copy(path, destination, NOFOLLOW_LINKS, COPY_ATTRIBUTES)
}
}
check(stage.renameTo(target)) { "cannot finish migration to $target" }
migrated.writeText(source.canonicalPath)
} catch (e: Exception) {
stage.deleteRecursively()
throw e
}
}
}
@@ -278,7 +278,7 @@ class SessionService : Service() {
// The desktop's Steam launchers start the client there (bannerlator-steam-launch), through the
// same set-up as a Steam session: it gets what the client and its games are started with.
val steamHere = SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP
addClientEnvironment(guest, runtimeDir, steamHere)
addClientEnvironment(guest, steamHere)
// Where the fast path's description of proot's view goes, once the binds are known.
val fastPathAt = guest.size
@@ -500,7 +500,7 @@ class SessionService : Service() {
}
/** The guest's base environment: paths, the display, the GL/Vulkan stack and the client's switches. */
private fun addClientEnvironment(guest: MutableList<String>, runtimeDir: File, steamHere: Boolean) {
private fun addClientEnvironment(guest: MutableList<String>, steamHere: Boolean) {
guest.add("/usr/bin/env")
guest.add("-i")
guest.add("HOME=/root")
@@ -511,7 +511,7 @@ class SessionService : Service() {
// Without this the session is UTC: the client's clock, its logs and every timestamp in a
// session bundle sit hours off the device's. Bannerlator carries the same line.
guest.add("TZ=" + java.util.TimeZone.getDefault().id)
guest.add("XDG_RUNTIME_DIR=" + runtimeDir.path)
guest.add("XDG_RUNTIME_DIR=" + LinuxRuntime.GUEST_RUNTIME_DIR)
guest.add("XDG_SESSION_TYPE=wayland")
guest.add("WAYLAND_DISPLAY=wayland-0")
guest.add("GAMESCOPE_FORCE_GENERAL_QUEUE=1")
@@ -757,11 +757,14 @@ class SessionService : Service() {
val problem = GameStorage.prepare(library.path)
if (problem == null) {
File(LinuxRuntime.rootDir(this), "mnt/droiddeck-sd").mkdirs()
binds.add("${library.path}:/mnt/droiddeck-sd")
// Links, prefixes and Steam entries made before the rename still name the old path.
File(LinuxRuntime.rootDir(this), "mnt/bannerlator-sd").mkdirs()
binds.add("${library.path}:/mnt/bannerlator-sd")
Log.i(TAG, "game storage: ${library.path} -> /mnt/droiddeck-sd (\"${library.label}\")")
try {
binds.addAll(SecondaryLibrary.binds(filesDir, File(library.path)))
Log.i(TAG, "game storage: ${library.path} -> /mnt/droiddeck-sd (\"${library.label}\"); prefixes and native tools private")
} catch (e: Exception) {
Log.w(TAG, "game storage: private directories could not be prepared; internal only this session", e)
}
} else {
Log.w(TAG, "game storage: $problem; internal only this session")
}