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

@@ -5,6 +5,7 @@ import com.droiddeck.launcher.R
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.session.SecondaryLibrary
import java.io.File
/**
@@ -84,7 +85,11 @@ object Library {
/** Proton keeps each game's prefix below compatdata/<appid>/pfx in a Steam library. */
fun protonPrefix(context: Context, appId: Long, preferredLibrary: File? = null): File? {
val ids = listOf(appId.toString(), java.lang.Integer.toString(appId.toInt())).distinct()
val roots = (listOfNotNull(preferredLibrary) + steamLibraries(context).map { it.first })
val secondary = GameStorage.effective(context)?.let { File(it.path) }
fun prefixRoot(root: File): File = if (secondary != null && root.canonicalPath == secondary.canonicalPath)
SecondaryLibrary.privateRoot(context.filesDir, root).takeIf { File(it, "steamapps/compatdata").isDirectory } ?: root
else root
val roots = (listOfNotNull(preferredLibrary) + steamLibraries(context).map { it.first }).map(::prefixRoot)
.distinctBy { runCatching { it.canonicalPath }.getOrDefault(it.absolutePath) }
return roots.asSequence()
.flatMap { root -> ids.asSequence().map { id -> File(root, "steamapps/compatdata/$id/pfx") } }
@@ -47,7 +47,7 @@ object GuestCommand {
.forEach { cmd.add("-b"); cmd.add(it) }
cmd += listOf(
"/usr/bin/env", "-i", "HOME=/root", "USER=root", "LANG=C.UTF-8",
"PATH=/usr/local/bin:/usr/bin:/bin", "XDG_RUNTIME_DIR=${runtimeDir.path}",
"PATH=/usr/local/bin:/usr/bin:/bin", "XDG_RUNTIME_DIR=${LinuxRuntime.GUEST_RUNTIME_DIR}",
"XDG_DATA_HOME=/root/.local/share", "FLATPAK_BWRAP=${FlatpakManager.BWRAP}",
"XDG_DATA_DIRS=/root/.local/share/flatpak/exports/share:/usr/local/share:/usr/share",
)
@@ -34,6 +34,14 @@ public final class LinuxRuntime {
/** Shortcut extra naming which of the modes above a Linux entry launches. */
public static final String EXTRA_LINUX_MODE = "linux_mode";
private static final String KGSL_DEVICE = "/dev/kgsl-3d0";
/**
* Where the guest sees a command's XDG_RUNTIME_DIR. A Unix socket's path must fit in 108 bytes,
* and libwayland checks the guest's path before proot ever sees it: with the app on an SD card
* adopted as internal storage the files directory is /mnt/expand/<uuid>/user/0/<package>/files,
* and gamescope-0 under it is one byte over, so gamescope could not open its socket and the
* session ended at once. A long host path behind it is proot's to shorten.
*/
public static final String GUEST_RUNTIME_DIR = "/run/droiddeck";
/** Where every Linux session's debug log lands: public, so a user can just hand the folder over. */
public static final String DEBUG_LOG_DIR = "DroidDeck";
@@ -185,7 +193,10 @@ public final class LinuxRuntime {
bind(cmd, new File(root, "etc/bannerlator/empty").getPath() + ":/sys/fs/selinux");
bind(cmd, context.getFilesDir().getPath());
bind(cmd, context.getCacheDir().getPath());
if (runtimeDir != null) bind(cmd, runtimeDir.getPath());
if (runtimeDir != null) {
bind(cmd, runtimeDir.getPath());
bind(cmd, runtimeDir.getPath() + ":" + GUEST_RUNTIME_DIR);
}
if (sessionRoot != null) bind(cmd, sessionRoot.getPath());
if (externalStorage != null && externalStorage.isDirectory()) {
bind(cmd, externalStorage.getPath());
@@ -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")
}