diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 265b1faee6..146e7fe3bf 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -403,6 +403,7 @@ jobs:
- uses: gradle/actions/setup-gradle@v4
with:
+ cache-read-only: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
cache-cleanup: on-success
- name: Resolve the pinned Android NDK
@@ -484,6 +485,12 @@ jobs:
name: xbox-arm64
path: app/src/main/assets/linuxfs/usr/local/lib/droiddeck-xbox
+ - name: Cache checksum-pinned pack inputs
+ uses: actions/cache@v4
+ with:
+ path: ~/.cache/droiddeck-pack-inputs
+ key: pack-inputs-v1-${{ hashFiles('tools/packs/build.sh', 'tools/packs/fetch-verified.sh', 'tools/packs/tracking/release.env') }}
+ restore-keys: pack-inputs-v1-
- name: Build the add-on packs
run: bash tools/packs/build.sh app/build/packs
@@ -526,6 +533,9 @@ jobs:
- name: Unit tests
id: unit-tests
+ env:
+ DROIDDECK_BUILD_LABEL: ${{ steps.build-label.outputs.label }}
+ SGDB_API_KEY: ${{ secrets.SGDB_API_KEY }}
run: |
set -o pipefail
mkdir -p app/build
diff --git a/README.md b/README.md
index 7fd8cfbdbd..7d90815935 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,16 @@ DroidDeck brings the SteamOS experience to Android: Valve's Steam client in Big

+
+
+
+
+
+
+
+
+
+

> Note: DroidDeck does not have a stand-alone website. Do not click on any download links from websites claiming to be the DroidDeck team.
diff --git a/app/build.gradle b/app/build.gradle
index e81b92711c..1b1eb5ae7c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -80,7 +80,7 @@ def sourceCommit = providers.environmentVariable('DROIDDECK_SOURCE_COMMIT').getO
def prNumber = (providers.environmentVariable('DROIDDECK_PR_NUMBER').getOrNull() ?: '0').with { it.isInteger() ? it : '0' }
def ciBuild = providers.environmentVariable('GITHUB_ACTIONS').getOrNull() == 'true'
def releaseSigner = rootProject.file('keystore/release-signer.sha256').text.trim()
-def commitTime = (gitValue(['show', '-s', '--format=%ct', 'HEAD']) ?: '0').with { it.isLong() ? it : '0' }
+def commitTime = (gitValue(['show', '-s', '--format=%ct', '--end-of-options', sourceCommit]) ?: '0').with { it.isLong() ? it : '0' }
def desktopKde = rootProject.file('tools/desktop-kde/release.env').readLines()
.findAll { it.contains('=') && !it.startsWith('#') }
.collectEntries { def kv = it.split('=', 2); [(kv[0].trim()): kv[1].trim()] }
@@ -220,6 +220,10 @@ android {
unitTests.returnDefaultValues = true
unitTests.includeAndroidResources = true
unitTests.all {
+ if (ciBuild) {
+ outputs.upToDateWhen { false }
+ outputs.doNotCacheIf('CI executes the test suite on every run') { true }
+ }
// Robolectric keeps a sandbox per SDK level the tests ask for; seven no longer fit in Gradle's default 512 MB.
maxHeapSize = '2g'
def logTarget = providers.systemProperty('robolectric.logging').orNull
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index fcd9b2e11b..286a9ee8ad 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -34,6 +34,7 @@
android:localeConfig="@xml/locales_config"
android:networkSecurityConfig="@xml/network_security_config"
android:allowBackup="false"
+ android:allowAudioPlaybackCapture="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
diff --git a/app/src/main/cpp/waylandcomp/CMakeLists.txt b/app/src/main/cpp/waylandcomp/CMakeLists.txt
index 33585818ba..f8eb312910 100644
--- a/app/src/main/cpp/waylandcomp/CMakeLists.txt
+++ b/app/src/main/cpp/waylandcomp/CMakeLists.txt
@@ -8,6 +8,7 @@ add_library(droiddeckwayland SHARED
src/sc_layer.c
src/ahb_swapchain.c
src/waylandcomp_jni.c
+ src/gpu_clock_pin.c
src/droiddeck_ext.c
src/wl_dmabuf.c
src/wl_clipboard.c
diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c
index 95a8bf83a6..1be637a7bb 100644
--- a/app/src/main/cpp/waylandcomp/src/compositor.c
+++ b/app/src/main/cpp/waylandcomp/src/compositor.c
@@ -808,10 +808,14 @@ static uint32_t nominal_refresh_ns(void) {
}
static int64_t presented_ns(int64_t render_ns) {
- if (!g_tick_vsync_ns || render_ns - g_last_vsync_ns > (int64_t)nominal_refresh_ns() ||
- render_ns < g_tick_vsync_ns)
+ int64_t tick = g_tick_vsync_ns;
+ int64_t refresh = (int64_t)nominal_refresh_ns();
+ if (!tick || render_ns - g_last_vsync_ns > refresh)
return render_ns;
- return g_tick_vsync_ns;
+ int64_t delta = render_ns - tick;
+ if (delta > refresh || -delta > refresh)
+ return render_ns;
+ return tick;
}
static void feedback_present_all(struct wl_list *list, int64_t t) {
diff --git a/app/src/main/cpp/waylandcomp/src/gpu_clock_pin.c b/app/src/main/cpp/waylandcomp/src/gpu_clock_pin.c
new file mode 100644
index 0000000000..0f8e1f61bf
--- /dev/null
+++ b/app/src/main/cpp/waylandcomp/src/gpu_clock_pin.c
@@ -0,0 +1,170 @@
+#include "gpu_clock_pin.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "../../adrenotools/src/hook/kgsl.h"
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_t worker;
+static bool joinable;
+static atomic_bool running;
+
+struct pin {
+ int fd;
+ unsigned int context;
+ unsigned int memory;
+ unsigned int timestamp;
+ unsigned long gpuaddr;
+ uint32_t nop;
+ void *commands;
+ size_t size;
+};
+
+static struct pin pin = { .fd = -1 };
+
+static void release_pin(void) {
+ if (pin.context) {
+ struct kgsl_drawctxt_destroy destroy = { .drawctxt_id = pin.context };
+ ioctl(pin.fd, IOCTL_KGSL_DRAWCTXT_DESTROY, &destroy);
+ }
+ if (pin.commands) munmap(pin.commands, pin.size);
+ if (pin.memory) {
+ struct kgsl_gpumem_free_id free_memory = { .id = pin.memory };
+ ioctl(pin.fd, IOCTL_KGSL_GPUMEM_FREE_ID, &free_memory);
+ }
+ if (pin.fd >= 0) close(pin.fd);
+ pin = (struct pin) { .fd = -1 };
+}
+
+static bool submit_pin(void) {
+ struct kgsl_command_object object = {
+ .gpuaddr = pin.gpuaddr,
+ .size = 2 * sizeof(uint32_t),
+ .flags = KGSL_CMDLIST_IB,
+ .id = pin.memory,
+ };
+ struct kgsl_gpu_command command = {
+ .flags = KGSL_CMDBATCH_PWR_CONSTRAINT,
+ .cmdlist = (uintptr_t)&object,
+ .cmdsize = sizeof(object),
+ .numcmds = 1,
+ .context_id = pin.context,
+ };
+ if (ioctl(pin.fd, IOCTL_KGSL_GPU_COMMAND, &command) < 0) return false;
+ pin.timestamp = command.timestamp;
+ return true;
+}
+
+static bool prepare_pin(void) {
+ pin.fd = open("/dev/kgsl-3d0", O_RDWR | O_CLOEXEC);
+ if (pin.fd < 0) return false;
+ struct kgsl_devinfo info = {0};
+ struct kgsl_device_getproperty device_info = {
+ .type = KGSL_PROP_DEVICE_INFO, .value = &info, .sizebytes = sizeof(info),
+ };
+ if (ioctl(pin.fd, IOCTL_KGSL_DEVICE_GETPROPERTY, &device_info) < 0) return false;
+ unsigned int core = info.chip_id >> 24;
+ if (!core) core = info.gpu_id / 100;
+ if (core < 3) { errno = ENODEV; return false; }
+ pin.nop = core >= 5 ? 0x70100001 : 0xc0001000;
+ struct kgsl_drawctxt_create context = {
+ .flags = KGSL_CONTEXT_NO_GMEM_ALLOC | KGSL_CONTEXT_PREAMBLE | KGSL_CONTEXT_PWR_CONSTRAINT,
+ };
+ if (ioctl(pin.fd, IOCTL_KGSL_DRAWCTXT_CREATE, &context) < 0) return false;
+ pin.context = context.drawctxt_id;
+ struct kgsl_device_constraint_pwrlevel level = { .level = KGSL_CONSTRAINT_PWR_MAX };
+ struct kgsl_device_constraint constraint = {
+ .type = KGSL_CONSTRAINT_PWRLEVEL,
+ .context_id = pin.context,
+ .data = &level,
+ .size = sizeof(level),
+ };
+ struct kgsl_device_getproperty property = {
+ .type = KGSL_PROP_PWR_CONSTRAINT,
+ .value = &constraint,
+ .sizebytes = sizeof(constraint),
+ };
+ if (ioctl(pin.fd, IOCTL_KGSL_SETPROPERTY, &property) < 0) return false;
+ struct kgsl_gpumem_alloc_id memory = { .size = 4096 };
+ if (ioctl(pin.fd, IOCTL_KGSL_GPUMEM_ALLOC_ID, &memory) < 0) return false;
+ pin.memory = memory.id;
+ pin.gpuaddr = memory.gpuaddr;
+ pin.size = memory.mmapsize;
+ void *commands = mmap(NULL, pin.size, PROT_READ | PROT_WRITE, MAP_SHARED, pin.fd,
+ (off_t)pin.memory << 12);
+ if (commands == MAP_FAILED) return false;
+ pin.commands = commands;
+ // A3xx/A4xx use type-3 CP_NOP; newer cores use type-7 with zero odd-parity bits.
+ uint32_t *words = commands;
+ words[0] = pin.nop;
+ words[1] = 0;
+ struct kgsl_gpumem_sync_cache sync = { .id = pin.memory, .op = KGSL_GPUMEM_CACHE_CLEAN };
+ if (ioctl(pin.fd, IOCTL_KGSL_GPUMEM_SYNC_CACHE, &sync) < 0) return false;
+ return submit_pin();
+}
+
+static void *hold_pin(void *unused) {
+ (void)unused;
+ while (atomic_load(&running)) {
+ struct kgsl_device_waittimestamp_ctxtid wait = {
+ .context_id = pin.context,
+ .timestamp = pin.timestamp,
+ .timeout = 100,
+ };
+ if (ioctl(pin.fd, IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID, &wait) < 0) {
+ if (errno == EINTR || errno == ETIMEDOUT) continue;
+ break;
+ }
+ // Constraints expire after idle_timer (normally 80 ms); renew with a NOP, keeping devfreq alive.
+ usleep(25000);
+ if (atomic_load(&running) && !submit_pin()) break;
+ }
+ if (atomic_exchange(&running, false))
+ __android_log_print(ANDROID_LOG_WARN, "GpuClockPin", "constraint stopped: %s", strerror(errno));
+ release_pin();
+ return NULL;
+}
+
+bool gpu_clock_pin_set(bool on) {
+ pthread_mutex_lock(&lock);
+ if (joinable) {
+ if (on && atomic_load(&running)) {
+ pthread_mutex_unlock(&lock);
+ return true;
+ }
+ atomic_store(&running, false);
+ pthread_join(worker, NULL);
+ joinable = false;
+ }
+ bool ok = true;
+ if (on) {
+ ok = prepare_pin();
+ if (ok) {
+ atomic_store(&running, true);
+ int error = pthread_create(&worker, NULL, hold_pin, NULL);
+ if (error) {
+ atomic_store(&running, false);
+ errno = error;
+ ok = false;
+ } else {
+ joinable = true;
+ }
+ }
+ if (!ok) {
+ int error = errno;
+ release_pin();
+ errno = error;
+ }
+ }
+ pthread_mutex_unlock(&lock);
+ return ok;
+}
diff --git a/app/src/main/cpp/waylandcomp/src/gpu_clock_pin.h b/app/src/main/cpp/waylandcomp/src/gpu_clock_pin.h
new file mode 100644
index 0000000000..5fe17d102e
--- /dev/null
+++ b/app/src/main/cpp/waylandcomp/src/gpu_clock_pin.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#include
+
+bool gpu_clock_pin_set(bool on);
diff --git a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c
index 6a407088bb..bc349cdf6c 100644
--- a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c
+++ b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c
@@ -16,6 +16,7 @@
#include "effects_chain.h"
#include "cardboard.h"
#include "droiddeck_color.h"
+#include "gpu_clock_pin.h"
extern int droiddeck_wayland_run(void);
extern void droiddeck_wayland_set_scale_mode(int mode, int alignment);
@@ -634,8 +635,14 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeTextInputDelete(JNIE
extern void adrenotools_set_turbo(bool turbo);
JNIEXPORT void JNICALL
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetGpuTurbo(JNIEnv *env, jclass clazz, jboolean on) {
- (void)env; (void)clazz;
- adrenotools_set_turbo(on == JNI_TRUE);
+ (void)clazz;
+ if (!gpu_clock_pin_set(on == JNI_TRUE)) {
+ int saved_errno = errno;
+ jclass error = (*env)->FindClass(env, "java/lang/IllegalStateException");
+ if (error) (*env)->ThrowNew(env, error, strerror(saved_errno));
+ }
+ // Clear a legacy global pin when recovering its marker after an app upgrade or crash.
+ if (on != JNI_TRUE) adrenotools_set_turbo(false);
}
JNIEXPORT jint JNICALL
diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt
index 52aed25cbc..943b07be83 100644
--- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt
+++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt
@@ -163,7 +163,7 @@ class FrontEndActivity : ComponentActivity() {
private var directAudio by mutableStateOf(false)
private var picturePosition by mutableStateOf("center")
private var stretch16x9 by mutableStateOf(false)
- private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
+ private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
private var launcherFullscreen by mutableStateOf(true)
private var downloadSource by mutableStateOf(DownloadSource.MODE_AUTO)
private var downloadMirror by mutableStateOf("")
@@ -544,12 +544,12 @@ class FrontEndActivity : ComponentActivity() {
}
startActivity(Intent(this, SessionActivity::class.java).setAction(SessionService.ACTION_RESUME)
.putExtra(SessionActivity.EXTRA_STEAMVR, steamVr)
- .putExtra(SessionActivity.EXTRA_RETURN_HOME, returnHome)
+ .returnTo(returnHome)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP))
return true
}
return startSession(Intent(this, SessionActivity::class.java)
- .putExtra(SessionActivity.EXTRA_RETURN_HOME, returnHome)
+ .returnTo(returnHome)
.apply {
if (game.gameIdString == com.droiddeck.launcher.gpu.SteamVr.APP_ID) {
putExtra(SessionActivity.EXTRA_STEAMVR, true)
@@ -560,6 +560,12 @@ class FrontEndActivity : ComponentActivity() {
}, steamSession = true)
}
+ private fun Intent.returnTo(returnHome: Boolean): Intent {
+ val task = taskId
+ return putExtra(SessionActivity.EXTRA_RETURN_HOME, returnHome)
+ .apply { if (returnHome) putExtra(SessionActivity.EXTRA_LINK_TASK, task) }
+ }
+
private fun launchWithoutSteam(game: Library.SteamGame, returnHome: Boolean): Boolean {
val app = applicationContext
Thread({
@@ -573,7 +579,7 @@ class FrontEndActivity : ComponentActivity() {
}
com.droiddeck.launcher.session.NoSteamLaunch.remember(command)
val next = Intent(this, SessionActivity::class.java)
- .putExtra(SessionActivity.EXTRA_RETURN_HOME, returnHome)
+ .returnTo(returnHome)
.putExtra(SessionService.EXTRA_MODE, SessionService.MODE_RUN)
.putExtra(SessionService.EXTRA_PROGRAM, command.program)
.putExtra(SessionService.EXTRA_PROGRAM_ARGS, command.args.toTypedArray())
@@ -582,7 +588,7 @@ class FrontEndActivity : ComponentActivity() {
SessionState.stopRequested -> android.widget.Toast.makeText(this, R.string.game_link_session_busy, android.widget.Toast.LENGTH_LONG).show()
SessionState.mode == SessionService.MODE_RUN && SessionState.program == command.program && SessionState.programArgs == command.args ->
startActivity(Intent(this, SessionActivity::class.java).setAction(SessionService.ACTION_RESUME)
- .putExtra(SessionActivity.EXTRA_RETURN_HOME, returnHome)
+ .returnTo(returnHome)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP))
else -> pendingSwitch = next
}
diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt
index 4f159908bf..0d87bc1f10 100644
--- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt
+++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt
@@ -1926,6 +1926,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
SessionState.relaunch?.let { next ->
SessionState.relaunch = null
next.putExtra(EXTRA_RETURN_HOME, intent.getBooleanExtra(EXTRA_RETURN_HOME, false))
+ next.putExtra(EXTRA_LINK_TASK, intent.getIntExtra(EXTRA_LINK_TASK, -1))
setIntent(next)
recreate()
return@runOnUiThread
@@ -3027,6 +3028,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
return
}
if (this.intent.getBooleanExtra(EXTRA_RETURN_HOME, false)) intent.putExtra(EXTRA_RETURN_HOME, true)
+ if (!intent.hasExtra(EXTRA_LINK_TASK)) intent.putExtra(EXTRA_LINK_TASK, this.intent.getIntExtra(EXTRA_LINK_TASK, -1))
setIntent(intent)
if (intent.getBooleanExtra(EXTRA_STEAMVR, false) && SessionState.mode == SessionService.MODE_STEAM) {
SessionState.steamVr = true
@@ -3549,17 +3551,33 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
return
}
- super.finish()
if (!closeAtOnce && intent.getBooleanExtra(EXTRA_RETURN_HOME, false)) {
com.droiddeck.launcher.ui.QuitFlood.take()
com.droiddeck.launcher.ui.LaunchOrigin.flooding = null
- startActivity(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
- }
+ closeLinkTasks()
+ if (!isTaskRoot) moveTaskToBack(true)
+ super.finishAndRemoveTask()
+ } else super.finish()
if (quitFlooded) overridePendingTransition(0, 0)
else overridePendingTransition(R.anim.session_hold, R.anim.session_sink)
}
+ private fun closeLinkTasks() {
+ val linkTask = intent.getIntExtra(EXTRA_LINK_TASK, -1)
+ if (linkTask == -1) return
+ val tasks = runCatching { getSystemService(android.app.ActivityManager::class.java)?.appTasks }.getOrNull().orEmpty()
+ for (task in tasks) {
+ runCatching {
+ val info = task.taskInfo
+ @Suppress("DEPRECATION")
+ val id = if (android.os.Build.VERSION.SDK_INT >= 29) info.taskId else info.persistentId
+ val base = info.baseIntent
+ if (id == linkTask && base.component?.className == FrontEndActivity::class.java.name &&
+ com.droiddeck.launcher.frontend.GameLaunchIntent.accepts(base.action)) task.finishAndRemoveTask()
+ }
+ }
+ }
+
private fun completeLeave() {
if (isFinishing) return
val signal = com.droiddeck.launcher.ui.Themes.current(this).signal
@@ -3571,6 +3589,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
companion object {
const val EXTRA_RETURN_HOME = "returnHome"
+ const val EXTRA_LINK_TASK = "linkTask"
const val EXTRA_STEAMVR = "steamVr"
const val EXTRA_REPAIR_RUNTIME = "repairRuntime"
private const val LEAVE_TIMEOUT_MS = 1_500L
diff --git a/app/src/main/java/com/droiddeck/launcher/core/CpuAllocationDefaults.kt b/app/src/main/java/com/droiddeck/launcher/core/CpuAllocationDefaults.kt
deleted file mode 100644
index adaa106a02..0000000000
--- a/app/src/main/java/com/droiddeck/launcher/core/CpuAllocationDefaults.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.droiddeck.launcher.core
-
-import com.droiddeck.launcher.gpu.GpuInfo
-import com.droiddeck.launcher.gpu.SocNames
-
-object CpuAllocationDefaults {
- data class Allocation(val client: String, val game: String)
-
- val device: Allocation? by lazy {
- forDevice(SocNames.model(), GpuInfo.systemProperty("ro.board.platform"),
- CpuCores.all.associateWith(CpuCores::maxGhz))
- }
-
- fun forDevice(model: String, platform: String, frequencies: Map): Allocation? {
- val chip = model.trim().uppercase().substringBefore('-')
- val gen2 = chip in setOf("SM8550", "QCS8550") ||
- (chip.isEmpty() && platform.trim().equals("kalama", ignoreCase = true))
- if (!gen2 || frequencies.size != 8 || frequencies.keys.any { it < 0 } ||
- frequencies.values.any { it == null || !it.isFinite() || it <= 0.0 }) return null
- val clusters = frequencies.entries.groupBy { it.value }.toSortedMap(compareBy { it ?: 0.0 }).values.toList()
- if (clusters.map { it.size } != listOf(3, 4, 1)) return null
- return Allocation(
- client = CpuCores.format(clusters[2].map { it.key }.toSet()),
- game = CpuCores.format(clusters[1].map { it.key }.toSet()),
- )
- }
-}
diff --git a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt
index 1e59fb577e..058b07dd5d 100644
--- a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt
+++ b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt
@@ -152,13 +152,17 @@ object DeviceReport {
k("RAM total", FileUtils.sizeToString(mi.totalMem))
k("RAM available", FileUtils.sizeToString(mi.availMem))
}
- runCatching {
- val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) k("Thermal status", thermalStatusName(pm.currentThermalStatus))
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
- k("Thermal headroom (10 s)", pm.getThermalHeadroom(10).let { if (it.isNaN()) "not reported" else String.format(Locale.US, "%.2f", it) })
+ val pm = runCatching { context.getSystemService(Context.POWER_SERVICE) as? PowerManager }.getOrNull()
+ if (pm != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ k("Thermal status", runCatching { thermalStatusName(pm.currentThermalStatus) }.getOrNull())
}
- k("Power saver", pm.isPowerSaveMode)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ k("Thermal headroom (10 s)", runCatching {
+ pm.getThermalHeadroom(10).let { if (it.isNaN()) "not reported" else String.format(Locale.US, "%.2f", it) }
+ }.getOrNull())
+ }
+ k("Power saver", runCatching { pm.isPowerSaveMode }.getOrNull())
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val rate = runCatching { context.getSystemService(PerformanceHintManager::class.java)?.preferredUpdateRateNanos }.getOrNull()
diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt
index 2a83d57e5b..340bc83ce0 100644
--- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt
+++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt
@@ -387,11 +387,17 @@ object AddedGames {
}
}
+ private class LoginUser(val id: String, val mostRecent: Boolean, val autoLogin: Boolean, val timestamp: Long)
+
internal fun accountConfig(root: File): File? {
val users = runCatching { File(root, "config/loginusers.vdf").readText() }.getOrDefault("")
- val recent = Regex(""""(\d{5,})"\s*\{([^}]*)\}""").findAll(users)
- .lastOrNull { Regex(""""MostRecent"\s*"1"""").containsMatchIn(it.groupValues[2]) }
- val account = recent?.groupValues?.get(1)?.toLongOrNull()?.let { (it - 76561197960265728L).toString() }
+ val recent = Regex(""""(\d{5,})"\s*\{([^}]*)\}""").findAll(users).map {
+ val body = it.groupValues[2]
+ LoginUser(it.groupValues[1], Regex(""""MostRecent"\s*"1"""").containsMatchIn(body), Regex(""""AutoLogin"\s*"1"""").containsMatchIn(body),
+ Regex(""""timestamp"\s*"(\d+)"""").find(body)?.groupValues?.get(1)?.toLongOrNull() ?: 0L)
+ }.filter { it.mostRecent || it.autoLogin || it.timestamp > 0 }.toList().asReversed()
+ .maxWithOrNull(compareBy({ it.mostRecent }, { it.autoLogin }, { it.timestamp }))
+ val account = recent?.id?.toLongOrNull()?.let { (it - 76561197960265728L).toString() }
?: File(root, "userdata").list()?.filter { it.isNotEmpty() && it.all(Char::isDigit) && it != "0" }?.singleOrNull()
return account?.let { File(root, "userdata/$it/config") }
}
diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt
index 91691cb1e7..e3fa25ac59 100644
--- a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt
+++ b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt
@@ -46,12 +46,14 @@ object Library {
1054830,
1070560,
1113280,
+ 1161040,
1245040,
1391110,
1420170,
1493710,
1580130,
1628350,
+ 1826330,
1887720,
2180100,
228980,
diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt
index ac87bd0aa5..45f07471bc 100644
--- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt
+++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxNetworkLinkComponent.kt
@@ -301,15 +301,18 @@ class LinuxNetworkLinkComponent(
}
}
- private fun seededMac(): String {
- val id = Settings.Secure.getString(appContext.contentResolver, Settings.Secure.ANDROID_ID) ?: "bannerlator"
- val bytes = java.security.MessageDigest.getInstance("SHA-1").digest(id.toByteArray())
- val b0 = (bytes[0].toInt() and 0xfc) or 0x02
- return listOf(b0, bytes[1].toInt(), bytes[2].toInt(), bytes[3].toInt(), bytes[4].toInt(), bytes[5].toInt())
- .joinToString(":") { "%02x".format(it and 0xff) }
- }
+ private fun seededMac(): String =
+ seededMac { Settings.Secure.getString(appContext.contentResolver, Settings.Secure.ANDROID_ID) }
companion object {
+ internal fun seededMac(readId: () -> String?): String {
+ val id = runCatching(readId).getOrNull() ?: "bannerlator"
+ val bytes = java.security.MessageDigest.getInstance("SHA-1").digest(id.toByteArray())
+ val b0 = (bytes[0].toInt() and 0xfc) or 0x02
+ return listOf(b0, bytes[1].toInt(), bytes[2].toInt(), bytes[3].toInt(), bytes[4].toInt(), bytes[5].toInt())
+ .joinToString(":") { "%02x".format(it and 0xff) }
+ }
+
private const val TAG = "LinuxNetworkLink"
private const val LINK_FILE = "etc/droiddeck-net"
private const val LINK_INDEX = 2
diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java
index 11be5bf9b4..6d17f2d75a 100644
--- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java
+++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java
@@ -110,6 +110,11 @@ public final class LinuxRuntime {
File root = rootDir(context);
List binds = binds(context, sessionRoot, runtimeDir, externalStorage, extraBinds);
if (sessionRoot != null) lastBinds = binds;
+ return commandWithBinds(context, root, binds, guestCommand);
+ }
+
+ public static List commandWithBinds(Context context, File root, List binds,
+ List guestCommand) {
List cmd = prootPrefix(context, root, "/root");
for (String spec : binds) bind(cmd, spec);
cmd.addAll(guestCommand);
diff --git a/app/src/main/java/com/droiddeck/launcher/session/BootMovie.kt b/app/src/main/java/com/droiddeck/launcher/session/BootMovie.kt
index 8267edd57a..953196900c 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/BootMovie.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/BootMovie.kt
@@ -51,7 +51,7 @@ object BootMovie {
SessionPrefs.setBootMovieApplyNext(context, true)
BootMovieReport.note(context, "picked $id here; Steam names ${SessionFiles.startupMoviePath(BootMovieLibrary.steamConfig(context))}")
// Whatever Steam names right now is about to be replaced, so it is not a pick to adopt later.
- SessionFiles.startupMoviePath(BootMovieLibrary.steamConfig(context))?.let { SessionPrefs.setBootMovieSteamSeen(context, it) }
+ SessionFiles.startupMovieLocalPath(BootMovieLibrary.steamConfig(context))?.let { SessionPrefs.setBootMovieSteamSeen(context, it) }
}
fun customName(context: Context): String? =
@@ -167,10 +167,12 @@ object BootMovie {
* that movie becomes the choice here. Steam already plays it, so nothing is staged over it. True when the choice changed.
*/
fun syncFromSteam(context: Context): Boolean {
- val path = SessionFiles.startupMoviePath(BootMovieLibrary.steamConfig(context)) ?: return false
- if (path == SessionPrefs.bootMovieSteamSeen(context)) return false
- SessionPrefs.setBootMovieSteamSeen(context, path)
- if (path == SessionFiles.BOOT_MOVIE_PATH) return false
+ val named = SessionFiles.startupMovieLocalPath(BootMovieLibrary.steamConfig(context)) ?: return false
+ val seen = SessionPrefs.bootMovieSteamSeen(context)
+ if (named == seen) return false
+ SessionPrefs.setBootMovieSteamSeen(context, named)
+ if (named == SessionFiles.BOOT_MOVIE_PATH || (named.isEmpty() && seen == null)) return false
+ val path = named.ifEmpty { "/movies/steam_os_startup.webm" }
val prefix = "/uioverrides/movies/"
// The list names a bought movie from the Steam folder (/config/communityitemscache/...), Steam's config from its config folder.
val id = if (path.startsWith(prefix)) BootMovieLibrary.idOf(path.removePrefix(prefix)) else {
diff --git a/app/src/main/java/com/droiddeck/launcher/session/BootMovieLibrary.kt b/app/src/main/java/com/droiddeck/launcher/session/BootMovieLibrary.kt
index 7c125e8196..0dd7a0fadf 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/BootMovieLibrary.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/BootMovieLibrary.kt
@@ -79,8 +79,9 @@ object BootMovieLibrary {
return customMovieDirs(context).map { File(it, name) }.firstOrNull { it.isFile && it.length() > 0L }
}
- private fun isMovie(file: File) = file.isFile && file.length() > 0L && file.name.endsWith(".webm", ignoreCase = true) &&
- file.name !in STAGED && !file.name.startsWith(".")
+ private fun isMovie(file: File) = isWebm(file) && file.name !in STAGED
+
+ private fun isWebm(file: File) = file.isFile && file.length() > 0L && file.name.endsWith(".webm", ignoreCase = true) && !file.name.startsWith(".")
private fun readMeta(context: Context): JSONObject =
runCatching { JSONObject(metaFile(context).readText()) }.getOrDefault(JSONObject())
@@ -136,7 +137,7 @@ object BootMovieLibrary {
}
val bought = HashMap()
for (root in steamRoots(context)) {
- File(root, "steamui/movies").listFiles { f -> isMovie(f) && f.nameWithoutExtension.lowercase() in NATIVE }.orEmpty()
+ File(root, "steamui/movies").listFiles { f -> isWebm(f) && f.nameWithoutExtension.lowercase() in NATIVE }.orEmpty()
.sortedBy { it.name.lowercase() }.forEach { steam.putIfAbsent(STEAM_PREFIX + "/movies/" + it.name, it) }
val scan = pointShopMovies(root)
bought.putAll(scan.titles)
@@ -144,8 +145,8 @@ object BootMovieLibrary {
}
val seen = HashSet()
for ((id, file) in steam) {
- if (file.name in STAGED || !seen.add(file.canonicalPath)) continue
val native = file.nameWithoutExtension.lowercase() in NATIVE
+ if ((file.name in STAGED && !native) || !seen.add(file.canonicalPath)) continue
// Steam names a bought movie by an item number and a hash; the points shop's own title is shown when Steam has it.
val title = if (native) NATIVE[file.nameWithoutExtension.lowercase()] ?: file.nameWithoutExtension else bought[file.path] ?: boughtId(file)?.let { "#$it" } ?: file.nameWithoutExtension
out.add(Entry(id, title, if (native) SOURCE_STEAM else SOURCE_POINTSHOP, file, removable = false))
@@ -153,8 +154,11 @@ object BootMovieLibrary {
return out
}
- /** The three startup movies Steam ships with; Steam's movies folder holds many more videos that are not startup movies. */
- private val NATIVE = mapOf("deck_startup" to "Deck startup", "oled_startup" to "Oled startup", "startup_machine" to "Machine startup")
+ /** The four startup movies Steam ships with; Steam's movies folder holds many more videos that are not startup movies. */
+ private val NATIVE = mapOf(
+ "deck_startup" to "Deck startup", "oled_startup" to "Oled startup", "startup_machine" to "Machine startup",
+ "steam_os_startup" to "SteamOS startup",
+ )
private val skippedFolders = setOf("uioverrides", "steamapps", "librarycache", "httpcache", "logs", "compatdata", "shadercache")
diff --git a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt
index d1aae9d720..776a9f7a0f 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt
@@ -721,13 +721,19 @@ object ComponentsManager {
class StoredOriginal(val protonId: String, val protonName: String?, val comp: String, val protonVersion: String, val size: Long, val kept: Boolean)
class Stored(val packages: List, val originals: List)
- private fun packagesInUse(state: JSONObject): Set {
+ internal fun liveSelection(key: String, entry: JSONObject, proton: Proton?): Boolean =
+ proton != null && (key == "queued" || entry.optString("protonVersion") == proton.version)
+
+ private fun packagesInUse(state: JSONObject, installed: Map): Set {
val names = HashSet()
for (key in listOf("active", "queued")) {
val byProton = state.optJSONObject(key) ?: continue
for (pid in byProton.keys()) {
val comps = byProton.optJSONObject(pid) ?: continue
- for (comp in comps.keys()) comps.optJSONObject(comp)?.optString("file")?.takeIf { it.isNotEmpty() }?.let(names::add)
+ for (comp in comps.keys()) {
+ val entry = comps.optJSONObject(comp) ?: continue
+ if (liveSelection(key, entry, installed[pid])) entry.optString("file").takeIf { it.isNotEmpty() }?.let(names::add)
+ }
}
}
val profiles = state.optJSONObject("profiles")
@@ -747,8 +753,8 @@ object ComponentsManager {
fun stored(context: Context): Stored = synchronized(lock) {
val state = loadState(context)
- val used = packagesInUse(state)
- val installed = protons(context).associateBy { it.id }
+ val installed = protons(context).distinctBy { it.id }.associateBy { it.id }
+ val used = packagesInUse(state, installed)
val originals = originalsDir(context).listFiles()?.filter { it.isDirectory }?.flatMap { proton ->
proton.listFiles()?.filter { it.isDirectory }?.flatMap { version ->
COMPONENTS.mapNotNull { comp ->
@@ -777,24 +783,36 @@ object ComponentsManager {
fun deletePackage(context: Context, file: String): String = synchronized(lock) {
val name = safeName(file)
val state = loadState(context)
- val queued = state.sub("queued")
- for (pid in queued.keys()) {
- val comps = queued.optJSONObject(pid) ?: continue
- for (comp in comps.keys()) check(comps.optJSONObject(comp)?.optString("file") != name) { context.getString(R.string.cmgr_package_in_use, name, pid) }
- }
- val active = state.sub("active")
- for (pid in active.keys()) {
- val comps = active.optJSONObject(pid) ?: continue
- for (comp in comps.keys()) check(comps.optJSONObject(comp)?.optString("file") != name) { context.getString(R.string.cmgr_package_in_use, name, pid) }
- }
- val profiles = state.sub("profiles")
- for (scope in profiles.keys()) {
- val profile = profiles.optJSONObject(scope) ?: continue
- check(COMPONENTS.none { profile.optString(it) == name }) { context.getString(R.string.cmgr_package_in_use, name, scope) }
+ val installed = protons(context).distinctBy { it.id }.associateBy { it.id }
+ var changed = false
+ for (key in listOf("queued", "active")) {
+ val byProton = state.sub(key)
+ for (pid in byProton.keys().asSequence().toList()) {
+ val comps = byProton.optJSONObject(pid) ?: continue
+ for (comp in comps.keys().asSequence().toList()) {
+ val entry = comps.optJSONObject(comp) ?: continue
+ if (entry.optString("file") != name) continue
+ check(!liveSelection(key, entry, installed[pid])) { context.getString(R.string.cmgr_package_in_use, name, installed[pid]?.name ?: pid) }
+ comps.remove(comp)
+ changed = true
+ }
+ if (comps.length() == 0) byProton.remove(pid)
+ }
}
val f = File(packagesDir(context), name)
check(f.isFile) { context.getString(R.string.cmgr_package_not_stored, name) }
- f.delete()
+ val profiles = state.sub("profiles")
+ for (scope in profiles.keys().asSequence().toList()) {
+ val profile = profiles.optJSONObject(scope) ?: continue
+ for (comp in COMPONENTS.filter { profile.optString(it) == name }) {
+ rememberProfiledComponent(state, comp)
+ profile.remove(comp)
+ changed = true
+ }
+ if (profile.length() == 0) profiles.remove(scope)
+ }
+ check(f.delete()) { name }
+ if (changed) saveState(context, state)
context.getString(R.string.cmgr_deleted, name)
}
diff --git a/app/src/main/java/com/droiddeck/launcher/session/GpuClockPin.kt b/app/src/main/java/com/droiddeck/launcher/session/GpuClockPin.kt
index 7855c49590..40135f08de 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/GpuClockPin.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/GpuClockPin.kt
@@ -26,6 +26,7 @@ object GpuClockPin {
pinned = true
"gpu clock: held at its top"
} catch (t: Throwable) {
+ File(context.filesDir, MARKER).delete()
Log.w(TAG, "pin", t)
"gpu clock: pin failed"
}
diff --git a/app/src/main/java/com/droiddeck/launcher/session/LoadingState.kt b/app/src/main/java/com/droiddeck/launcher/session/LoadingState.kt
index a23f23bebf..f69983f0db 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/LoadingState.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/LoadingState.kt
@@ -87,11 +87,10 @@ class LoadingState(context: Context, private val steam: Boolean = true) {
if (line.startsWith("== STEP ")) {
stepAt = at
stepText = line.substringAfter("== STEP ").substringAfter(' ')
- val m = INSTALL_COUNT.find(line)
- if (m != null) {
+ clientDownload(line)?.let { (what, percent) ->
clientDownloadAt = at
- clientDownload = m.groupValues[1]
- clientPercent = m.groupValues[2].toInt() * 100 / maxOf(1, m.groupValues[3].toInt())
+ clientDownload = what
+ clientPercent = percent
}
} else {
val m = UPDATE_PROGRESS.find(line)
@@ -132,6 +131,19 @@ class LoadingState(context: Context, private val steam: Boolean = true) {
}
}
+ internal fun clientDownload(line: String): Pair? {
+ val count = INSTALL_COUNT.find(line) ?: return null
+ val mb = INSTALL_MEGABYTES.find(line.substring(count.range.last + 1))
+ val done = mb?.groupValues?.get(1)?.toLongOrNull()
+ val total = mb?.groupValues?.get(2)?.toLongOrNull()
+ if (done != null && total != null && total > 0) {
+ return "$done / $total MB" to (done * 100 / total).toInt().coerceIn(0, 100)
+ }
+ val part = count.groupValues[2].toIntOrNull() ?: return null
+ val all = count.groupValues[3].toIntOrNull() ?: return null
+ return count.groupValues[1] to (part.toLong() * 100 / maxOf(1, all)).coerceIn(0L, 100L).toInt()
+ }
+
internal fun readableScriptStep(scriptStep: String): Boolean {
val t = scriptStep.lowercase()
return t.startsWith("download") || t.startsWith("checking the linux") || t.startsWith("unpacking") || t.startsWith("installing")
@@ -140,5 +152,6 @@ class LoadingState(context: Context, private val steam: Boolean = true) {
private const val TAIL_BYTES = 48L * 1024
private val UPDATE_PROGRESS = Regex("""Downloading update \((\d+) of (\d+) KB\)""")
private val INSTALL_COUNT = Regex("""downloading Steam: (\S+) \((\d+)/(\d+)\)""")
+ private val INSTALL_MEGABYTES = Regex("""^, (\d+) of (\d+) MB""")
}
}
diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt
index 4824a44424..8cd846513d 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt
@@ -390,10 +390,12 @@ object SessionFiles {
private fun activeStartupMovie(text: String): VdfBlock? = customizationMovie(text) ?: olderMovie(text)
/** The movie Steam's config selects, as a path like `/uioverrides/movies/x.webm`; null when none is named. */
- internal fun startupMoviePath(config: File): String? {
+ internal fun startupMoviePath(config: File): String? = startupMovieLocalPath(config)?.takeIf { it.isNotEmpty() }
+
+ internal fun startupMovieLocalPath(config: File): String? {
val text = runCatching { config.readText() }.getOrNull() ?: return null
val movie = activeStartupMovie(text) ?: return null
- return scalar(text.substring(movie.keyStart, movie.close + 1), "LocalPath")?.takeIf { it.isNotEmpty() }
+ return scalar(text.substring(movie.keyStart, movie.close + 1), "LocalPath")
}
/** Both `StartupMovie` sections of Steam's config as written there, for the report; null when there is none. */
diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt
index 93df369004..e8041fe0b8 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt
@@ -4,7 +4,6 @@ import android.content.Context
import android.content.pm.ActivityInfo
import androidx.annotation.StringRes
import com.droiddeck.launcher.R
-import com.droiddeck.launcher.core.CpuAllocationDefaults
import com.droiddeck.launcher.core.GameEnvironment
import com.droiddeck.launcher.core.TextureFiltering
import com.droiddeck.launcher.gpu.Cardboard
@@ -50,9 +49,9 @@ object SessionPrefs {
)
fun orientation(context: Context): Int =
- prefs(context).getInt("orientation", ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
+ prefs(context).getInt("orientation", ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
.takeIf { value -> orientationOptions.any { it.first == value } }
- ?: ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+ ?: ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
fun setOrientation(context: Context, orientation: Int) {
require(orientationOptions.any { it.first == orientation })
@@ -382,30 +381,19 @@ object SessionPrefs {
prefs(context).edit().putBoolean("wifiDiscoveryAsked", true).apply()
}
- internal data class CoreAllocation(val clientOverride: Boolean, val clientCpus: String, val gameCpus: String)
-
- internal fun coreAllocation(context: Context, defaults: CpuAllocationDefaults.Allocation? = CpuAllocationDefaults.device): CoreAllocation {
- val saved = prefs(context)
- return CoreAllocation(
- saved.getBoolean("clientCpusOverride", defaults != null && !saved.contains("clientCpus")),
- saved.getString("clientCpus", defaults?.client.orEmpty()).orEmpty(),
- saved.getString("gameCpus", defaults?.game.orEmpty()).orEmpty(),
- )
- }
-
- fun clientCpusOverride(context: Context): Boolean = coreAllocation(context).clientOverride
+ fun clientCpusOverride(context: Context): Boolean = prefs(context).getBoolean("clientCpusOverride", false)
fun setClientCpusOverride(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("clientCpusOverride", on).apply()
}
- fun clientCpus(context: Context): String = coreAllocation(context).clientCpus
+ fun clientCpus(context: Context): String = prefs(context).getString("clientCpus", "").orEmpty()
fun setClientCpus(context: Context, list: String) {
prefs(context).edit().putString("clientCpus", list).apply()
}
- fun gameCpus(context: Context): String = coreAllocation(context).gameCpus
+ fun gameCpus(context: Context): String = prefs(context).getString("gameCpus", "").orEmpty()
fun setGameCpus(context: Context, list: String) {
prefs(context).edit().putString("gameCpus", list).apply()
diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt
index 86643fc15f..762de4f93b 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt
@@ -71,6 +71,7 @@ class SessionService : Service() {
private val steamDownloadMonitor = SteamDownloadMonitor()
private var downloadMonitorTask: Runnable? = null
private var downloadActive = false
+ private var clientInstallActive = false
@Volatile private var steamLibraryMounts = emptyMap()
private var suspendDownloadNow = false
private var suspendPolicy = SessionPrefs.SUSPEND_MANUAL
@@ -321,6 +322,7 @@ class SessionService : Service() {
suspendDownloadNow = false
steamDownloadMonitor.reset()
downloadActive = false
+ clientInstallActive = false
steamSleepToken = null
completeNativeSleep()
suspendOperationPending = false
@@ -640,8 +642,8 @@ class SessionService : Service() {
}
},
)
- mainHandler.post { updateSuspendPolicy() }
updateDownloadMonitoring()
+ mainHandler.post { updateSuspendPolicy() }
}
}
@@ -1413,8 +1415,7 @@ class SessionService : Service() {
private fun updateSuspendPolicy() {
if (!SessionState.running) return
val hidden = !hasVisibleSurface
- val downloadsBlockingSuspend = steamDownloadsInBackground && SessionState.mode == MODE_STEAM &&
- suspendPolicy != SessionPrefs.SUSPEND_NEVER && hidden && downloadActive && !suspendDownloadNow
+ val downloadsBlockingSuspend = downloadsKeepAwake() && hidden && !suspendDownloadNow
if (suspendPolicy == SessionPrefs.SUSPEND_MANUAL && hidden && !downloadsBlockingSuspend) {
manualPauseRequested = true
} else if (!hidden && !SessionState.suspended) {
@@ -1828,8 +1829,7 @@ class SessionService : Service() {
.setContentText(getString(
when {
SessionState.suspended -> R.string.session_notification_paused
- downloadActive && steamDownloadsInBackground &&
- suspendPolicy != SessionPrefs.SUSPEND_NEVER -> R.string.session_notification_downloads
+ downloadsKeepAwake() -> R.string.session_notification_downloads
else -> R.string.session_notification
}
))
@@ -1837,8 +1837,7 @@ class SessionService : Service() {
.apply {
if (SessionState.suspended) {
addAction(Notification.Action.Builder(null, getString(R.string.resume_session), resume).build())
- } else if (downloadActive && steamDownloadsInBackground &&
- suspendPolicy != SessionPrefs.SUSPEND_NEVER) {
+ } else if (downloadsKeepAwake()) {
val suspend = PendingIntent.getService(
this@SessionService, 3,
Intent(this@SessionService, SessionService::class.java).setAction(ACTION_SUSPEND_NOW),
@@ -1858,33 +1857,50 @@ class SessionService : Service() {
getSystemService(NotificationManager::class.java)?.notify(NOTIFICATION_ID, buildNotification())
}
+ private fun downloadsKeepAwake(): Boolean =
+ downloadActive && (steamDownloadsInBackground || clientInstallActive) &&
+ SessionState.mode == MODE_STEAM && suspendPolicy != SessionPrefs.SUSPEND_NEVER
+
+ private fun downloadWatchWanted(): Boolean =
+ SessionState.running && SessionState.mode == MODE_STEAM && suspendPolicy != SessionPrefs.SUSPEND_NEVER &&
+ (steamDownloadsInBackground || !SessionState.firstFrameSeen)
+
private fun updateDownloadMonitoring() {
- val enabled = SessionState.running && SessionState.mode == MODE_STEAM &&
- steamDownloadsInBackground && suspendPolicy != SessionPrefs.SUSPEND_NEVER
- if (!enabled) {
+ if (!downloadWatchWanted()) {
val wasActive = downloadActive
downloadMonitorTask?.let(mainHandler::removeCallbacks)
downloadMonitorTask = null
steamDownloadMonitor.reset()
downloadActive = false
+ if (clientInstallActive) SessionEvents.record("steam.client_download", mapOf("active" to false))
+ clientInstallActive = false
if (wasActive) refreshNotification()
return
}
if (downloadMonitorTask != null) return
val poll = object : Runnable {
override fun run() {
- if (downloadMonitorTask !== this || !SessionState.running ||
- SessionState.mode != MODE_STEAM || !steamDownloadsInBackground ||
- suspendPolicy == SessionPrefs.SUSPEND_NEVER) {
+ if (downloadMonitorTask !== this) return
+ if (!downloadWatchWanted()) {
+ downloadMonitorTask = null
+ updateDownloadMonitoring()
+ updateSuspendPolicy()
return
}
+ val root = LinuxRuntime.rootDir(this@SessionService)
val wasActive = downloadActive
- downloadActive = steamDownloadMonitor.poll(
- LinuxRuntime.rootDir(this@SessionService),
+ val wasInstalling = clientInstallActive
+ clientInstallActive = !SessionState.firstFrameSeen &&
+ (clientInstallActive || SteamDownloadMonitor.clientInstallPending(root))
+ downloadActive = clientInstallActive || steamDownloadsInBackground && steamDownloadMonitor.poll(
+ root,
receivedBytes = TrafficStats.getUidRxBytes(android.os.Process.myUid()),
client = SessionState.steamClientArch,
mounts = steamLibraryMounts,
)
+ if (wasInstalling != clientInstallActive) {
+ SessionEvents.record("steam.client_download", mapOf("active" to clientInstallActive))
+ }
if (wasActive != downloadActive) refreshNotification()
updateSuspendPolicy()
mainHandler.postDelayed(this, DOWNLOAD_POLL_MS)
diff --git a/app/src/main/java/com/droiddeck/launcher/session/SteamDownloadMonitor.kt b/app/src/main/java/com/droiddeck/launcher/session/SteamDownloadMonitor.kt
index 37f7c1fb90..ff3602c1bd 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/SteamDownloadMonitor.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/SteamDownloadMonitor.kt
@@ -1,7 +1,7 @@
package com.droiddeck.launcher.session
import java.io.File
-import java.io.RandomAccessFile
+import java.io.FileInputStream
internal class SteamDownloadMonitor {
private data class ManifestState(
@@ -63,16 +63,17 @@ internal class SteamDownloadMonitor {
lastContentActivityAt = 0L
}
runCatching {
- RandomAccessFile(log, "r").use { input ->
- input.seek(contentLogOffset)
+ FileInputStream(log).use { input ->
+ input.channel.position(contentLogOffset)
+ val reader = input.bufferedReader(Charsets.ISO_8859_1)
while (true) {
- val line = input.readLine() ?: break
+ val line = reader.readLine() ?: break
when {
"Client version:" in line -> {
activeContentUpdates.clear()
lastContentActivityAt = 0L
}
- CONTENT_UPDATE.find(line)?.let { match ->
+ " update changed : " in line && CONTENT_UPDATE.find(line)?.let { match ->
val appId = match.groupValues[1]
val updateType = match.groupValues[2]
val state = match.groupValues[3]
@@ -85,14 +86,15 @@ internal class SteamDownloadMonitor {
}
true
} == true -> Unit
- CURRENT_RATE.find(line)?.groupValues?.get(1)?.toDoubleOrNull()?.let { it > 0.0 } == true ->
+ "Current download rate: " in line &&
+ CURRENT_RATE.find(line)?.groupValues?.get(1)?.toDoubleOrNull()?.let { it > 0.0 } == true ->
lastContentActivityAt = now
"Downloading " in line && " chunks for depot " in line ->
lastContentActivityAt = now
}
if (activeContentUpdates.isNotEmpty()) lastContentActivityAt = now
}
- contentLogOffset = input.filePointer
+ contentLogOffset = input.channel.position()
}
}
return activeContentUpdates.isNotEmpty() && lastContentActivityAt > 0L &&
@@ -138,13 +140,21 @@ internal class SteamDownloadMonitor {
private fun value(text: String, key: String): String? =
Regex("\"$key\"\\s+\"([^\"]*)\"").find(text)?.groupValues?.get(1)
- private companion object {
- const val MANIFEST_PROGRESS_GRACE_MS = 8_000L
- const val CONTENT_ACTIVITY_GRACE_MS = 90_000L
- const val MIN_RECEIVE_BYTES_PER_SEC = 64L * 1024L
- val PATH = Regex("\"path\"\\s+\"([^\"]+)\"")
- val STEAM_HOMES = listOf("root/.local/share/Steam", "root/.droiddeck-x64/.local/share/Steam")
- val CONTENT_UPDATE = Regex("""AppID (\d+) (App|Workshop|Shader) update changed : (.*)""")
- val CURRENT_RATE = Regex("""Current download rate: ([\d.]+) Mbps""")
+ companion object {
+ fun clientInstallPending(runtimeRoot: File): Boolean {
+ val home = File(runtimeRoot, "root")
+ val steam = File(home, ".local/share/Steam")
+ val stamped = File(steam, "package/droiddeck-installed").isFile ||
+ File(steam, "package/bannerlator-installed").isFile
+ return !(stamped && File(steam, "steamrtarm64/steam").isFile) || File(home, ".bl-steam-repair").exists()
+ }
+
+ private const val MANIFEST_PROGRESS_GRACE_MS = 8_000L
+ private const val CONTENT_ACTIVITY_GRACE_MS = 90_000L
+ private const val MIN_RECEIVE_BYTES_PER_SEC = 64L * 1024L
+ private val PATH = Regex("\"path\"\\s+\"([^\"]+)\"")
+ private val STEAM_HOMES = listOf("root/.local/share/Steam", "root/.droiddeck-x64/.local/share/Steam")
+ private val CONTENT_UPDATE = Regex("""AppID (\d+) (App|Workshop|Shader) update changed : (.*)""")
+ private val CURRENT_RATE = Regex("""Current download rate: ([\d.]+) Mbps""")
}
}
diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt
index 611b7f3dba..91a0f96f5b 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt
@@ -104,6 +104,29 @@ object StoreInstallRoot {
.map { it to guestFor(context, it) }
}
+ /** Xodus has its own PRoot mount table and cannot see the selected Steam library's SD bind. */
+ fun externalRootsForXodus(context: Context): List> {
+ val roots = externalRoots(context).toMutableList()
+ val selectedLibrary = GameStorage.effective(context)?.let { File(it.path, ON_VOLUME) }
+ ?.takeUnless { isInternal(context, it) }
+ if (selectedLibrary != null && roots.none { it.first.absolutePath == selectedLibrary.absolutePath }) {
+ roots += selectedLibrary to guestFor(context, selectedLibrary)
+ }
+ return roots
+ }
+
+ fun externalBindSpecs(context: Context): List = externalBindSpecs(externalRoots(context), LinuxRuntime.rootDir(context))
+
+ fun externalBindSpecsForXodus(context: Context): List =
+ externalBindSpecs(externalRootsForXodus(context), LinuxRuntime.rootDir(context))
+
+ internal fun externalBindSpecs(roots: List>, guestRoot: File): List =
+ roots.mapNotNull { (host, guest) ->
+ if (!host.isDirectory || !host.canRead()) return@mapNotNull null
+ val target = File(guestRoot, guest.removePrefix("/"))
+ if (target.isDirectory || target.mkdirs()) "${host.path}:$guest" else null
+ }
+
private fun guestFor(context: Context, root: File): String {
val sm = context.getSystemService(StorageManager::class.java)
val uuid = runCatching { sm?.getStorageVolume(root)?.uuid }.getOrNull()?.takeIf { it.isNotBlank() }?.replace(Regex("[^A-Za-z0-9-]"), "")
@@ -114,11 +137,21 @@ object StoreInstallRoot {
fun isInternal(context: Context, root: File): Boolean = root.absolutePath == internalRoot(context).absolutePath
fun externalGuestPath(context: Context, host: File): String? {
+ return externalGuestPath(host, externalRoots(context))
+ }
+
+ fun guestPath(context: Context, host: File): String = externalGuestPath(context, host) ?: host.path
+
+ fun guestPathForXodus(context: Context, host: File): String =
+ externalGuestPath(host, externalRootsForXodus(context)) ?: host.path
+
+ internal fun externalGuestPath(host: File, roots: List>): String? {
val path = host.absolutePath
- for ((root, guest) in externalRoots(context)) {
- val dir = root.absolutePath
+ for ((root, guest) in roots.sortedByDescending { it.first.absolutePath.length }) {
+ val dir = root.absolutePath.trimEnd(File.separatorChar)
if (path == dir) return guest
- if (path.startsWith("$dir/")) return guest + "/" + path.removePrefix("$dir/")
+ val prefix = dir + File.separator
+ if (path.startsWith(prefix)) return guest + "/" + path.removePrefix(prefix).replace(File.separatorChar, '/')
}
return null
}
diff --git a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicClientLibrary.kt b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicClientLibrary.kt
index 8521a90f5d..e5ea933d83 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicClientLibrary.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicClientLibrary.kt
@@ -251,7 +251,7 @@ internal object EpicClientLibrary {
SessionPrefs.addedGameStoredAppId(app, oldFolder.path)?.let { SteamLiveShortcuts.remove(app, it) }
changed = true
}
- val next = StoreGameSidecar(
+ val next = withLaunchArgs(StoreGameSidecar(
Store.EPIC, appName, item.optString("DisplayName").ifEmpty { appName }, exe,
installVersion = item.optString("AppVersionString"), installedAt = existing?.installedAt?.takeIf { it > 0 } ?: folder.lastModified(),
cover = existing?.cover, hero = existing?.hero,
@@ -260,7 +260,7 @@ internal object EpicClientLibrary {
epic = existing?.epic ?: com.droiddeck.launcher.stores.EpicOptions(),
cloud = existing?.cloud ?: true,
launcher = StoreLaunch.LAUNCHER,
- )
+ ), commandArgs(item.optString("LaunchCommand")))
val sidecarChanged = existing?.toJson()?.toString(2) != next.toJson().toString(2)
val launcher = File(folder, StoreLaunch.LAUNCHER)
if (sidecarChanged || runCatching { launcher.readText() }.getOrNull() != StoreLaunch.launcherText(next)) {
@@ -328,6 +328,7 @@ internal object EpicClientLibrary {
.put("CatalogItemId", record.optString("itemId"))
.put("InstallLocation", dir)
.put("LaunchExecutable", record.optString("launchExecutable"))
+ .put("LaunchCommand", record.optString("launchCommand"))
.put("AppVersionString", record.optString("version"))
.put("SidecarDeploymentId", record.optJSONObject("sidecar")?.optString("deploymentId").orEmpty())
.put("DisplayName", title?.takeIf(String::isNotBlank) ?: dir.substringAfterLast('/'))
@@ -358,7 +359,11 @@ internal object EpicClientLibrary {
write(File(manifests, "$guid.item"), item(install, tags, ownership == true).toString(2))
runCatching { egstore(install, guid) { token } }.onFailure { Log.w(TAG, "${install.appName}: .egstore not written (${it.javaClass.simpleName})") }
after.put(install.appName, JSONObject().put("guid", guid).put("signature", install.signature).apply { if (ownership != null) put("ownership", ownership) })
- StoreGameSidecar.read(install.folder)?.let { StoreLaunch.refreshLauncher(install.folder, it) }
+ StoreGameSidecar.read(install.folder)?.let { sidecar ->
+ val next = runCatching { manifestArgs(install, guid) }.getOrNull()?.let { withLaunchArgs(sidecar, it) } ?: sidecar
+ if (next !== sidecar) next.write(install.folder)
+ StoreLaunch.refreshLauncher(install.folder, next)
+ }
}
for (name in before.keys().asSequence().toList()) {
if (after.has(name)) continue
@@ -376,6 +381,33 @@ internal object EpicClientLibrary {
return changed
}
+ private const val LAUNCH_ARGS = "launchArgs"
+
+ private fun manifestArgs(install: Install, guid: String): List? {
+ val manifest = File(install.folder, ".egstore/$guid.manifest").takeIf { it.isFile } ?: return null
+ val launch = EpicNative.inspect(manifest.readBytes(), JSONObject().put("op", "launch")) ?: return null
+ val build = launch.optString("buildVersion")
+ if (install.version.isNotEmpty() && build != install.version) return null
+ val args = launch.optJSONArray("args") ?: return null
+ return List(args.length()) { args.optString(it) }.filter { it.isNotEmpty() }
+ }
+
+ private fun commandArgs(command: String): List {
+ if (command.isBlank()) return emptyList()
+ val args = EpicNative.call("launch.split", JSONObject().put("command", command))?.optJSONArray("args") ?: return emptyList()
+ return List(args.length()) { args.optString(it) }.filter { it.isNotEmpty() }
+ }
+
+ internal fun withLaunchArgs(sidecar: StoreGameSidecar, args: List): StoreGameSidecar {
+ val previous = sidecar.extra[LAUNCH_ARGS]?.split('\n')?.filter { it.isNotEmpty() }.orEmpty()
+ val kept = sidecar.args.filterNot { it in previous }
+ val added = args.filterNot { it in kept }
+ val next = kept + added
+ val extra = LinkedHashMap(sidecar.extra).apply { if (added.isEmpty()) remove(LAUNCH_ARGS) else put(LAUNCH_ARGS, added.joinToString("\n")) }
+ if (next == sidecar.args && extra == sidecar.extra) return sidecar
+ return sidecar.copy(args = next, extra = extra)
+ }
+
private fun ownershipToken(token: String, install: Install): Boolean? =
runCatching { EpicApiClient.getCustomAttribute(token, install.namespace, install.catalogItemId, "OwnershipToken") }
.getOrNull()?.trim()?.lowercase()?.let { it == "true" }
diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxInstaller.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxInstaller.kt
index 44e9ceff33..296ff050b8 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxInstaller.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxInstaller.kt
@@ -39,8 +39,9 @@ internal class XboxInstaller(private val app: Context, private val item: Catalog
var sequence = -1L
try {
val source = if (content) selected else item.id
+ val guestFolder = StoreInstallRoot.guestPathForXodus(app, folder)
val selection = if (content) emptyList() else listOf("--selected-content-id", selected)
- Xodus.start(app, listOf("streaming", source, folder.path, "--market", market,
+ Xodus.start(app, listOf("streaming", source, guestFolder, "--market", market,
"--progress-json", "--control-stdin") + selection).use { process ->
child = process
val diagnostics = Xodus.diagnostics(process)
diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxRuntime.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxRuntime.kt
index 28d6c12d99..d1ba4a52e7 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxRuntime.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxRuntime.kt
@@ -46,7 +46,7 @@ internal object XboxRuntime {
val market = game.second.extra["market"]?.takeIf { it.matches(Regex("[A-Z]{2}")) } ?: Xodus.market()
val directory = views.create(app.filesDir)
val process = try {
- Xodus.start(app, listOf("run", game.first.path, "droiddeck:prepare", "--exe", game.second.exe,
+ Xodus.start(app, listOf("run", StoreInstallRoot.guestPathForXodus(app, game.first), "droiddeck:prepare", "--exe", game.second.exe,
"--materialize-chain", "--market", market), launchDirectory = directory, credentialGeneration = credentials)
} catch (e: Exception) { XboxLaunchViews.remove(directory); throw e }
if (!launches.attach(token, process)) { process.close(); error("Xbox launch was cancelled") }
diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt
index fde5b0650c..94b8138253 100644
--- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt
+++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt
@@ -5,7 +5,9 @@ import android.os.Environment
import com.droiddeck.launcher.core.AddonPack
import com.droiddeck.launcher.runtime.LinuxNetworkLinkComponent
import com.droiddeck.launcher.runtime.LinuxRuntime
+import com.droiddeck.launcher.runtime.ProotFastPath
import com.droiddeck.launcher.session.SessionPrefs
+import com.droiddeck.launcher.stores.StoreInstallRoot
import org.json.JSONObject
import java.io.Closeable
import java.io.File
@@ -79,10 +81,24 @@ internal object Xodus {
networkLink.publish()
networkLink.start()
val runtime = (runtimeDirectory ?: File(app.filesDir, "xbox-runtime")).apply { mkdirs() }
- val command = LinuxRuntime.command(app, null, null, Environment.getExternalStorageDirectory(), listOf(
+ val root = LinuxRuntime.rootDir(app)
+ val external = Environment.getExternalStorageDirectory()
+ val extraBinds = StoreInstallRoot.externalBindSpecsForXodus(app)
+ val binds = LinuxRuntime.binds(app, null, null, external, extraBinds)
+ val fastPathPreloaded = runCatching {
+ File(root, "etc/ld.so.preload").useLines { lines -> lines.any { it.trim() == ProotFastPath.LIBRARY } }
+ }.getOrDefault(false)
+ val fastPathKey = if (ProotFastPath.enabled(app) && fastPathPreloaded &&
+ File(root, ProotFastPath.LIBRARY.removePrefix("/")).isFile) ProotFastPath.key(root, binds) else null
+ val guestCommand = mutableListOf(
"/usr/bin/env", "HOME=/root", "XODUS_LOG=off", "RUST_LOG=off",
"XDG_RUNTIME_DIR=${runtime.path}", "DROIDDECK_XBOX_CREDENTIAL_SOCKET=${credentials.name}", binary,
- ) + args)
+ )
+ fastPathKey?.let { key ->
+ guestCommand.addAll(guestCommand.lastIndex, ProotFastPath.guestEnv(root, binds, key))
+ }
+ guestCommand.addAll(args)
+ val command = LinuxRuntime.commandWithBinds(app, root, binds, guestCommand)
val builder = ProcessBuilder(command).directory(LinuxRuntime.rootDir(app))
if (launchDirectory != null) builder.environment()["TMPDIR"] = launchDirectory.path
builder.environment().apply {
@@ -90,6 +106,7 @@ internal object Xodus {
put("PROOT_LOADER", LinuxRuntime.prootLoader(app).path)
put("PROOT_TMP_DIR", LinuxRuntime.prootTempDir(app).path)
if (SessionPrefs.prootNoSeccomp(app)) put("PROOT_NO_SECCOMP", "1")
+ fastPathKey?.let { ProotFastPath.hostEnv(it).let { (key, value) -> put(key, value) } }
LinuxRuntime.prootLibraryPath(app).takeIf { it.isNotEmpty() }?.let { put("LD_LIBRARY_PATH", it) }
}
val digest = java.security.MessageDigest.getInstance("SHA-256")
diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt
index 1840d0f077..6e44aca350 100644
--- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt
+++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt
@@ -132,7 +132,7 @@ class FrontEndState(
val controller: com.droiddeck.launcher.input.ControllerPrefs.Settings? = null,
val phantomProcessStatus: PhantomProcessStatus = PhantomProcessStatus.NOT_APPLICABLE,
val showPhantomGate: Boolean = false,
- val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
+ val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
val launcherFullscreen: Boolean = true,
val downloadSource: String = DownloadSource.MODE_AUTO,
val downloadMirror: String = "",
diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt
index 3b70318edd..d443237c5b 100644
--- a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt
+++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt
@@ -128,6 +128,7 @@ import androidx.compose.ui.graphics.lerp
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
@@ -173,6 +174,7 @@ private data class PaneKey(val chip: String, val tab: String, val signedIn: Bool
@Composable
internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier) {
val ctx = LocalContext.current
+ val focusManager = LocalFocusManager.current
com.droiddeck.launcher.stores.xbox.XboxContent.plan?.let { content ->
androidx.compose.material3.AlertDialog(
onDismissRequest = { com.droiddeck.launcher.stores.xbox.XboxContent.dismiss() },
@@ -280,7 +282,7 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
val heroFocus = remember { androidx.compose.ui.focus.FocusRequester() }
var detailFocused by remember { mutableStateOf(false) }
fun move(kind: String) { focusMove = kind to (focusMove?.second ?: 0) + 1 }
- fun open(key: String) { lastOpened = key; openGame = key; move("detail") }
+ fun open(key: String) { focusManager.clearFocus(force = true); lastOpened = key; openGame = key; move("detail") }
fun closeGame() { openGame = null; move("card") }
fun switchTab(to: String) { tab = to; move("first") }
val pickChip: (String) -> Unit = { id ->
@@ -478,7 +480,11 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
androidx.compose.material3.LinearProgressIndicator(Modifier.fillMaxWidth().height(3.dp))
}
!k.signedIn -> Box(Modifier.fillMaxWidth().verticalScroll(scroll).padding(top = 4.dp, bottom = 16.dp)) { SignInCard(st, viewportH - 20.dp) }
- else -> Storefront(st, k.tab, query, s, a, grids.getOrPut(k) { LazyGridState() }, onQuery = { query = it }, onOpen = { open(it) }, onTab = { switchTab(it) })
+ else -> Storefront(
+ st, k.tab, query, s, a, grids.getOrPut(k) { LazyGridState() },
+ clearSearchFocus = openGame != null,
+ onQuery = { query = it }, onOpen = { open(it) }, onTab = { switchTab(it) },
+ )
}
}
}
@@ -539,7 +545,7 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
seenActive.clear(); seenActive.addAll(activeKeys)
if (fresh.isNotEmpty()) StoresMotion.takeInstall()?.let { StoresMotion.fly(it) }
}
- StoresState.pendingInstall?.let { item -> InstallWhere(item) }
+ StoresState.pendingInstall?.let { item -> StoreTheme(item.store) { InstallWhere(item) } }
}
@Composable
@@ -938,6 +944,7 @@ internal fun StoreLogo(store: Store, size: Dp) {
private fun Storefront(
store: Store, tab: String, query: String, s: FrontEndState, a: FrontEndActions,
grid: LazyGridState,
+ clearSearchFocus: Boolean,
onQuery: (String) -> Unit, onOpen: (String) -> Unit, onTab: (String) -> Unit,
) {
val ctx = LocalContext.current
@@ -1082,6 +1089,7 @@ private fun Storefront(
libraryLabel,
query, onQuery,
placeholder = if (tab == "store") stringResource(R.string.stores_search_catalog, store.label) else stringResource(R.string.stores_search_library),
+ clearSearchFocus = clearSearchFocus,
lead = if (tabs.size < 2) null else { {
val labels = tabs.map { if (it == "store") stringResource(R.string.stores_tab_store) else libraryLabel }
HeaderTabs(labels, tabs.indexOf(tab).coerceAtLeast(0)) { onTab(tabs[it]) }
@@ -1185,6 +1193,7 @@ private fun HeaderTabs(labels: List, selected: Int, onSelect: (Int) -> U
@Composable
internal fun ModeHeader(
title: String, query: String, onQuery: (String) -> Unit, placeholder: String,
+ clearSearchFocus: Boolean = false,
lead: (@Composable () -> Unit)? = null, trailing: @Composable () -> Unit,
) {
val colors = MaterialTheme.colorScheme
@@ -1206,6 +1215,7 @@ internal fun ModeHeader(
AdbTextField(
value = query, onValueChange = onQuery, label = "", keyboardType = KeyboardType.Text, imeAction = ImeAction.Search,
placeholder = placeholder, compact = true, focusOnShow = focusOnOpen,
+ clearFocus = clearSearchFocus,
onFocusChange = { focused -> if (!focused && query.isEmpty()) { searching = false; focusOnOpen = false } },
)
}
diff --git a/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt
index 8117c3ee5e..5c719ca90d 100644
--- a/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt
+++ b/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt
@@ -356,6 +356,7 @@ internal fun AdbTextField(
placeholder: String? = null,
compact: Boolean = false,
onFocusChange: (Boolean) -> Unit = {},
+ clearFocus: Boolean = false,
onNext: (() -> Unit)? = null,
onDone: (() -> Unit)? = null,
focusOnShow: Boolean = false,
@@ -444,6 +445,11 @@ internal fun AdbTextField(
?.showSoftInput(editText, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
}
}
+ if (clearFocus && editText.hasFocus()) {
+ editText.clearFocus()
+ (editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
+ ?.hideSoftInputFromWindow(editText.windowToken, 0)
+ }
editText.setTextColor(colors.onBackground.toArgb())
editText.setHintTextColor(colors.onSurfaceVariant.toArgb())
editText.hint = placeholder
diff --git a/app/src/main/rust/stores/JNI.md b/app/src/main/rust/stores/JNI.md
index c5cd077443..0d2308fa27 100644
--- a/app/src/main/rust/stores/JNI.md
+++ b/app/src/main/rust/stores/JNI.md
@@ -160,13 +160,15 @@ synchronous on the calling thread (network calls block: call them off the main t
| `cloud.list` | `accessToken`, `accountId`, `appName` | `files[]` of `name`, `modified` (ms, -1 unknown), `hash`, `readLink` |
| `cloud.writeLinks` | `accessToken`, `accountId`, `appName`, `names[]` | `links`: name → write link |
| `launch.args` | `displayName`, `accountId`, `namespace`, `locale`, `appName`, `deploymentId`, `additional` | `args[]` |
+| `launch.split` | `command` | `args[]` |
| `locale` | `language`, `region` | `key`, `tags[]`, `launchLocale` |
`nativeFetch` ops: `manifest.download` (`info`, optional `cdns`) → the manifest bytes;
`cloud.read` (`url`) → the file. `null` = failed. `nativeSend` op: `cloud.write` (`url`) with the
body → `{"ok": true}` or an error. `nativeInspect` parses manifest bytes: `{"op":"summary"}` →
`buildVersion`, `launchExe`, `prereqName`, `prereqPath`, `prereqRead`, `files[]` (`path`, `size`,
-`tags`); `{"op":"select","tags":[…]}` → `indices[]` of the files an install with those tags gets.
+`tags`); `{"op":"select","tags":[…]}` → `indices[]` of the files an install with those tags gets;
+`{"op":"launch"}` → the manifest's `buildVersion`, its `command` line and the `args[]` split from it.
### `nativeInstall`
diff --git a/app/src/main/rust/stores/src/epic/launch.rs b/app/src/main/rust/stores/src/epic/launch.rs
index 481e9b8255..8c5a104999 100644
--- a/app/src/main/rust/stores/src/epic/launch.rs
+++ b/app/src/main/rust/stores/src/epic/launch.rs
@@ -39,10 +39,72 @@ pub fn arguments(d: &LaunchData) -> Vec {
args
}
+pub fn split_command(command: &str) -> Vec {
+ let mut args = Vec::new();
+ let mut current = String::new();
+ let mut quoted = false;
+ let mut started = false;
+ let mut slashes = 0usize;
+ let mut chars = command.chars().map(|c| if c == '\t' { ' ' } else { c }).filter(|&c| c >= ' ' && c != '\u{7f}').peekable();
+ while let Some(c) = chars.next() {
+ if c == '\\' {
+ slashes += 1;
+ started = true;
+ continue;
+ }
+ if c == '"' {
+ current.extend(std::iter::repeat('\\').take(slashes / 2));
+ if slashes % 2 == 1 {
+ current.push('"');
+ } else if quoted && chars.peek() == Some(&'"') {
+ chars.next();
+ current.push('"');
+ } else {
+ quoted = !quoted;
+ }
+ slashes = 0;
+ started = true;
+ continue;
+ }
+ current.extend(std::iter::repeat('\\').take(slashes));
+ slashes = 0;
+ if c == ' ' && !quoted {
+ if started {
+ args.push(std::mem::take(&mut current));
+ started = false;
+ }
+ } else {
+ current.push(c);
+ started = true;
+ }
+ }
+ current.extend(std::iter::repeat('\\').take(slashes));
+ if started {
+ args.push(current);
+ }
+ args.retain(|a| !a.is_empty());
+ args
+}
+
#[cfg(test)]
mod tests {
use super::*;
+ #[test]
+ fn launch_command_splits_like_a_command_line() {
+ assert_eq!(split_command("-PCStore=EGS"), vec!["-PCStore=EGS"]);
+ assert_eq!(
+ split_command(" -a\t-b=\"c d\" \"-e f\" \"\" -g\r\n"),
+ vec!["-a", "-b=c d", "-e f", "-g"]
+ );
+ assert_eq!(
+ split_command(r#"-name="a\" b" -dir=C:\Games\ "-q=\\" -r"#),
+ vec![r#"-name=a" b"#, r"-dir=C:\Games\", r"-q=\", "-r"]
+ );
+ assert_eq!(split_command("-name=\"a\"\" b\" -s=\"\"\""), vec!["-name=a\" b", "-s=\""]);
+ assert!(split_command(" ").is_empty());
+ }
+
#[test]
fn arguments_in_order() {
let args = arguments(&LaunchData {
diff --git a/app/src/main/rust/stores/src/epic/manifest.rs b/app/src/main/rust/stores/src/epic/manifest.rs
index 2690e0f19d..98d31f3d9d 100644
--- a/app/src/main/rust/stores/src/epic/manifest.rs
+++ b/app/src/main/rust/stores/src/epic/manifest.rs
@@ -68,6 +68,7 @@ pub struct Manifest {
pub version: i64,
pub build_version: String,
pub launch_exe: String,
+ pub launch_command: String,
pub prereq_name: String,
pub prereq_path: String,
pub prereq_read: bool,
@@ -279,6 +280,7 @@ fn parse_binary(bytes: &[u8]) -> Result {
version,
build_version: meta.build_version,
launch_exe: meta.launch_exe,
+ launch_command: meta.launch_command,
prereq_name: meta.prereq_name,
prereq_path: meta.prereq_path,
prereq_read: meta.complete,
@@ -292,6 +294,7 @@ fn parse_binary(bytes: &[u8]) -> Result {
struct Meta {
build_version: String,
launch_exe: String,
+ launch_command: String,
prereq_name: String,
prereq_path: String,
complete: bool,
@@ -308,7 +311,7 @@ fn read_meta(data: &[u8]) -> Meta {
r.fstring()?;
meta.build_version = r.fstring()?;
meta.launch_exe = normalise_path(&r.fstring()?);
- r.fstring()?;
+ meta.launch_command = r.fstring()?;
let ids = r.count(4)?;
for _ in 0..ids {
r.fstring()?;
@@ -548,6 +551,7 @@ fn parse_json(bytes: &[u8]) -> Result {
version,
build_version: str_field("BuildVersionString"),
launch_exe: normalise_path(launch),
+ launch_command: str_field("LaunchCommand"),
prereq_name: str_field("PrereqName"),
prereq_path: normalise_path(&str_field("PrereqPath")),
prereq_read: true,
@@ -611,7 +615,7 @@ pub mod testing {
fstring(&mut meta, "App");
fstring(&mut meta, &m.build);
fstring(&mut meta, &m.exe);
- fstring(&mut meta, "");
+ fstring(&mut meta, "-PCStore=EGS \"-log=a b.txt\"");
if let Some((name, path)) = &m.prereq {
meta.extend_from_slice(&1i32.to_le_bytes());
fstring(&mut meta, "prereq-id");
@@ -763,6 +767,7 @@ mod tests {
assert_eq!(m.chunk_folder(), "ChunksV4");
assert_eq!(m.build_version, "1.2.3-CL-99");
assert_eq!(m.launch_exe, "Binaries/Win64/Game.exe");
+ assert_eq!(m.launch_command, "-PCStore=EGS \"-log=a b.txt\"");
assert_eq!(m.prereq_name, "UE4 Prerequisites (x64)");
assert_eq!(m.prereq_path, "Engine/Extras/UE4PrereqSetup_x64.exe");
assert!(m.prereq_read);
@@ -851,6 +856,7 @@ mod tests {
let doc = r#"{
"ManifestFileVersion": "013000000000",
"LaunchExeString": "Bin\\Game.exe",
+ "LaunchCommand": "-PCStore=EGS",
"BuildVersionString": "++Game+Release-1.0",
"PrereqName": "Redist", "PrereqPath": "Redist\\setup.exe",
"ChunkHashList": {
@@ -872,6 +878,7 @@ mod tests {
assert_eq!(m.version, 13);
assert_eq!(m.chunk_folder(), "ChunksV3");
assert_eq!(m.launch_exe, "Bin/Game.exe");
+ assert_eq!(m.launch_command, "-PCStore=EGS");
assert!(m.prereq_read);
assert_eq!(m.prereq_path, "Redist/setup.exe");
assert_eq!(m.chunks.len(), 2);
diff --git a/app/src/main/rust/stores/src/epic/service.rs b/app/src/main/rust/stores/src/epic/service.rs
index 67c1995bdf..2264f6c775 100644
--- a/app/src/main/rust/stores/src/epic/service.rs
+++ b/app/src/main/rust/stores/src/epic/service.rs
@@ -113,6 +113,7 @@ fn dispatch(op: &str, req: &Value) -> Value {
};
json!({ "args": launch::arguments(&data) })
}
+ "launch.split" => json!({ "args": launch::split_command(str_of(req, "command")) }),
"locale" => {
let key = locale::language_key(str_of(req, "language"), str_of(req, "region"));
json!({ "key": key, "tags": locale::tags_for_key(key), "launchLocale": locale::launch_locale(key) })
@@ -160,6 +161,11 @@ pub fn inspect(bytes: &[u8], request: &str) -> String {
.map(|a| a.iter().filter_map(|t| t.as_str()).map(str::to_string).collect());
json!({ "indices": locale::select(&m.files, tags.as_deref()) })
}
+ "launch" => json!({
+ "buildVersion": m.build_version,
+ "command": m.launch_command,
+ "args": launch::split_command(&m.launch_command),
+ }),
_ => json!({
"buildVersion": m.build_version,
"launchExe": m.launch_exe,
@@ -187,6 +193,8 @@ mod tests {
assert!(v["error"].is_string());
let v: Value = serde_json::from_str(&call("launch.args", r#"{"namespace":"ns","appName":"A"}"#)).unwrap();
assert_eq!(v["args"][0], "-EpicPortal");
+ let v: Value = serde_json::from_str(&call("launch.split", r#"{"command":"-PCStore=EGS \"-log=a b.txt\""}"#)).unwrap();
+ assert_eq!(v["args"], json!(["-PCStore=EGS", "-log=a b.txt"]));
}
#[test]
@@ -210,6 +218,10 @@ mod tests {
assert_eq!(v["files"].as_array().unwrap().len(), 2);
let v: Value = serde_json::from_str(&inspect(&bytes, r#"{"op":"select","tags":["English"]}"#)).unwrap();
assert_eq!(v["indices"], json!([0]));
+ let v: Value = serde_json::from_str(&inspect(&bytes, r#"{"op":"launch"}"#)).unwrap();
+ assert_eq!(v["buildVersion"], "b");
+ assert_eq!(v["command"], "-PCStore=EGS \"-log=a b.txt\"");
+ assert_eq!(v["args"], json!(["-PCStore=EGS", "-log=a b.txt"]));
let v: Value = serde_json::from_str(&inspect(b"nonsense", "{}")).unwrap();
assert!(v["error"].is_string());
}
diff --git a/app/src/test/java/com/droiddeck/launcher/core/CpuAllocationDefaultsTest.kt b/app/src/test/java/com/droiddeck/launcher/core/CpuAllocationDefaultsTest.kt
deleted file mode 100644
index ba6e31a10f..0000000000
--- a/app/src/test/java/com/droiddeck/launcher/core/CpuAllocationDefaultsTest.kt
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.droiddeck.launcher.core
-
-import org.junit.Assert.*
-import org.junit.Test
-
-class CpuAllocationDefaultsTest {
- private val thor = (0..7).associateWith { when (it) { in 0..2 -> 2.016; in 3..6 -> 2.8032; else -> 3.1872 } }
-
- @Test fun gen2UsesTheFourMiddleCoresAndOnePrime() {
- for (model in listOf("SM8550", "QCS8550", "sm8550-ac")) {
- assertEquals(CpuAllocationDefaults.Allocation("7", "3,4,5,6"), CpuAllocationDefaults.forDevice(model, "", thor))
- }
- assertEquals(CpuAllocationDefaults.Allocation("7", "3,4,5,6"), CpuAllocationDefaults.forDevice("", "kalama", thor))
- }
-
- @Test fun coreNumbersAndClockVariantsAreDetectedInsteadOfHardcoded() {
- val reordered = mapOf(0 to 3.36, 1 to 2.0, 2 to 2.0, 3 to 2.0, 4 to 2.8, 5 to 2.8, 6 to 2.8, 7 to 2.8)
- assertEquals(CpuAllocationDefaults.Allocation("0", "4,5,6,7"), CpuAllocationDefaults.forDevice("SM8550-AC", "kalama", reordered))
- }
-
- @Test fun anotherOrUnknownChipDoesNotAcquireThisDefault() {
- assertNull(CpuAllocationDefaults.forDevice("SM8650", "pineapple", thor))
- assertNull(CpuAllocationDefaults.forDevice("SM8650", "kalama", thor))
- assertNull(CpuAllocationDefaults.forDevice("", "", thor))
- }
-
- @Test fun missingOrUnexpectedTopologyKeepsTheSchedulerDefault() {
- assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor - 7))
- assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor + (7 to null)))
- assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor + (7 to 0.0)))
- assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor + (7 to Double.NaN)))
- assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", (0..7).associateWith { 2.8 }))
- }
-
- @Test fun allCoreGamesUndoTheClientsInheritedRestriction() {
- val all = CpuCores.listOrAll("")
- assertEquals(all, CpuCores.gameLaunchList("", clientPinned = true))
- assertEquals(all, CpuCores.gameLaunchList(all, clientPinned = true))
- assertEquals("", CpuCores.gameLaunchList("", clientPinned = false))
- assertEquals("0", CpuCores.gameLaunchList("0", clientPinned = true))
- }
-}
diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGameArtLookupTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGameArtLookupTest.kt
index 1f1e30c816..095cf9a5c5 100644
--- a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGameArtLookupTest.kt
+++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGameArtLookupTest.kt
@@ -1,5 +1,6 @@
package com.droiddeck.launcher.frontend
+import com.droiddeck.launcher.BuildConfig
import com.droiddeck.launcher.stores.CredentialCipher
import org.json.JSONArray
import org.json.JSONObject
@@ -92,8 +93,9 @@ class AddedGameArtLookupTest {
assertEquals("build", SteamGridDb.pick("", "build"))
assertEquals("build", SteamGridDb.pick(" ", "build"))
assertEquals("", SteamGridDb.pick("", ""))
- assertEquals("", SteamGridDb.builtInKey())
- assertEquals("", SteamGridDb.key(app))
+ val builtIn = SteamGridDb.builtInKey()
+ assertTrue(builtIn == BuildConfig.SGDB_API_KEY)
+ assertTrue(SteamGridDb.key(app) == builtIn.trim())
}
@Test fun theUsersKeyIsSealedOnDiskAndClears() {
@@ -106,7 +108,7 @@ class AddedGameArtLookupTest {
assertEquals("abcdef0123456789secretkey", SteamGridDb.key(app))
SteamGridDb.setUserKey(app, "")
assertFalse(file.exists())
- assertEquals("", SteamGridDb.key(app))
+ assertTrue(SteamGridDb.key(app) == SteamGridDb.builtInKey().trim())
}
@Test fun aFailedLookupIsNotRememberedAsNoMatch() {
diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesAccountTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesAccountTest.kt
new file mode 100644
index 0000000000..610f00bb4e
--- /dev/null
+++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGamesAccountTest.kt
@@ -0,0 +1,43 @@
+package com.droiddeck.launcher.frontend
+
+import java.io.File
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TemporaryFolder
+
+class AddedGamesAccountTest {
+ @get:Rule val tmp = TemporaryFolder()
+
+ private fun steamRoot(vararg blocks: Pair>): File = tmp.newFolder("Steam").also { root ->
+ File(root, "config").mkdirs()
+ File(root, "userdata/123/config").mkdirs()
+ File(root, "userdata/456/config").mkdirs()
+ val body = blocks.joinToString("") { (account, keys) ->
+ "\t\"${76561197960265728L + account}\"\n\t{\n" + keys.entries.joinToString("") { "\t\t\"${it.key}\"\t\t\"${it.value}\"\n" } + "\t}\n"
+ }
+ File(root, "config/loginusers.vdf").writeText("\"users\"\n{\n$body}\n")
+ }
+
+ @Test fun theAccountMarkedMostRecentIsUsed() {
+ val root = steamRoot(123L to mapOf("MostRecent" to "1", "AutoLogin" to "0", "timestamp" to "100"),
+ 456L to mapOf("MostRecent" to "0", "AutoLogin" to "1", "timestamp" to "200"))
+ assertEquals(File(root, "userdata/123/config"), AddedGames.accountConfig(root))
+ }
+
+ @Test fun withoutMostRecentTheAccountThatSignsInIsUsed() {
+ val root = steamRoot(123L to mapOf("AutoLogin" to "1", "timestamp" to "100"), 456L to mapOf("AutoLogin" to "0", "timestamp" to "200"))
+ assertEquals(File(root, "userdata/123/config"), AddedGames.accountConfig(root))
+ }
+
+ @Test fun withoutEitherMarkTheAccountUsedLastIsUsed() {
+ val root = steamRoot(456L to mapOf("AutoLogin" to "0", "timestamp" to "100"), 123L to mapOf("AutoLogin" to "0", "timestamp" to "200"))
+ assertEquals(File(root, "userdata/123/config"), AddedGames.accountConfig(root))
+ }
+
+ @Test fun twoAccountsWithoutAnyMarkGiveNoAccount() {
+ val root = steamRoot(123L to mapOf("AccountName" to "a"), 456L to mapOf("AccountName" to "b"))
+ assertNull(AddedGames.accountConfig(root))
+ }
+}
diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/SeededMacTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/SeededMacTest.kt
new file mode 100644
index 0000000000..e7a5212633
--- /dev/null
+++ b/app/src/test/java/com/droiddeck/launcher/runtime/SeededMacTest.kt
@@ -0,0 +1,21 @@
+package com.droiddeck.launcher.runtime
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNotEquals
+import org.junit.Test
+
+class SeededMacTest {
+ @Test
+ fun theAndroidIdSeedsAStableLocalMac() {
+ val mac = LinuxNetworkLinkComponent.seededMac { "0123456789abcdef" }
+ assertEquals(mac, LinuxNetworkLinkComponent.seededMac { "0123456789abcdef" })
+ assertNotEquals(mac, LinuxNetworkLinkComponent.seededMac { null })
+ assertEquals(0x02, mac.substringBefore(':').toInt(16) and 0x03)
+ }
+
+ @Test
+ fun aRomThatThrowsOnTheAndroidIdReadFallsBackToTheDefaultSeed() {
+ val mac = LinuxNetworkLinkComponent.seededMac { throw IllegalArgumentException("Illegal char: - at offset 8") }
+ assertEquals(LinuxNetworkLinkComponent.seededMac { null }, mac)
+ }
+}
diff --git a/app/src/test/java/com/droiddeck/launcher/session/BootMovieLibraryTest.kt b/app/src/test/java/com/droiddeck/launcher/session/BootMovieLibraryTest.kt
index ca68f58678..2c1d90ca0c 100644
--- a/app/src/test/java/com/droiddeck/launcher/session/BootMovieLibraryTest.kt
+++ b/app/src/test/java/com/droiddeck/launcher/session/BootMovieLibraryTest.kt
@@ -178,17 +178,39 @@ class BootMovieLibraryTest {
assertNull(SessionFiles.startupMoviePath(BootMovieLibrary.steamConfig(app)))
}
- @Test fun onlyTheThreeStartupMoviesOfSteamAreListed() {
- listOf("deck_startup", "oled_startup", "startup_machine", "controller_generic_thumbstick_move").forEach {
+ @Test fun onlyTheStartupMoviesOfSteamAreListed() {
+ listOf("deck_startup", "oled_startup", "startup_machine", "steam_os_startup", "controller_generic_thumbstick_move").forEach {
File(BootMovieLibrary.steamRoot(app), "steamui/movies/$it.webm").also { f -> f.parentFile!!.mkdirs(); f.writeText("movie") }
}
val ids = BootMovieLibrary.list(app).map { it.id }.filter { it.startsWith("steam:") }
assertEquals(
- listOf("steam:/movies/deck_startup.webm", "steam:/movies/oled_startup.webm", "steam:/movies/startup_machine.webm"),
+ listOf(
+ "steam:/movies/deck_startup.webm", "steam:/movies/oled_startup.webm", "steam:/movies/startup_machine.webm",
+ "steam:/movies/steam_os_startup.webm",
+ ),
ids.sorted(),
)
}
+ @Test fun steamsDefaultPickIsTakenOverAsItsOwnStartupMovie() {
+ val native = File(BootMovieLibrary.steamRoot(app), "steamui/movies/steam_os_startup.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
+ movie("a.webm")
+ steamPicksAt(SessionFiles.BOOT_MOVIE_PATH)
+ BootMovie.select(app, "file:a.webm")
+ steamPicksAt("")
+ assertTrue(BootMovie.syncFromSteam(app))
+ assertEquals("steam:/movies/steam_os_startup.webm", BootMovie.choice(app))
+ assertEquals(native, BootMovie.currentFile(app))
+ assertFalse(BootMovie.syncFromSteam(app))
+ }
+
+ @Test fun anEmptySteamPickThatWasNeverSeenChangesNothing() {
+ File(BootMovieLibrary.steamRoot(app), "steamui/movies/steam_os_startup.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
+ steamPicksAt("")
+ assertFalse(BootMovie.syncFromSteam(app))
+ assertEquals(BootMovie.DROIDDECK_30, BootMovie.choice(app))
+ }
+
@Test fun aMovieBoughtInThePointsShopIsListedAndAdopted() {
val file = File(BootMovieLibrary.steamRoot(app), "appcache/startupmovies/Bought.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
val entry = BootMovieLibrary.list(app).first { it.id == "steam:/appcache/startupmovies/Bought.webm" }
diff --git a/app/src/test/java/com/droiddeck/launcher/session/ComponentsSelectionTest.kt b/app/src/test/java/com/droiddeck/launcher/session/ComponentsSelectionTest.kt
new file mode 100644
index 0000000000..517d6ad2b3
--- /dev/null
+++ b/app/src/test/java/com/droiddeck/launcher/session/ComponentsSelectionTest.kt
@@ -0,0 +1,32 @@
+package com.droiddeck.launcher.session
+
+import org.json.JSONObject
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import java.io.File
+
+@RunWith(RobolectricTestRunner::class)
+class ComponentsSelectionTest {
+ private val proton = ComponentsManager.Proton("DroidDeck-Proton_11-11.1", "DroidDeck-Proton 11-11.1", File("/p"), "/p", "DroidDeck-Proton-11-11.1", false)
+ private val entry = JSONObject().put("file", "dxvk-low-latency-arm64ec-3.1.1-2-linux.wcp").put("protonVersion", "DroidDeck-Proton-11-11.1")
+
+ @Test
+ fun `a package swapped into an installed Proton is in use`() {
+ assertTrue(ComponentsManager.liveSelection("active", entry, proton))
+ assertTrue(ComponentsManager.liveSelection("queued", JSONObject().put("file", "x.wcp"), proton))
+ }
+
+ @Test
+ fun `a package left on a removed Proton is not in use`() {
+ assertFalse(ComponentsManager.liveSelection("active", entry, null))
+ assertFalse(ComponentsManager.liveSelection("queued", entry, null))
+ }
+
+ @Test
+ fun `a package from before a Proton update is not in use`() {
+ assertFalse(ComponentsManager.liveSelection("active", JSONObject(entry.toString()).put("protonVersion", "DroidDeck-Proton-11-9.1"), proton))
+ }
+}
diff --git a/app/src/test/java/com/droiddeck/launcher/session/CoreAllocationPrefsTest.kt b/app/src/test/java/com/droiddeck/launcher/session/CoreAllocationPrefsTest.kt
index 8a25bf4e72..901a82d3ff 100644
--- a/app/src/test/java/com/droiddeck/launcher/session/CoreAllocationPrefsTest.kt
+++ b/app/src/test/java/com/droiddeck/launcher/session/CoreAllocationPrefsTest.kt
@@ -1,7 +1,6 @@
package com.droiddeck.launcher.session
import android.content.Context
-import com.droiddeck.launcher.core.CpuAllocationDefaults
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
@@ -14,36 +13,22 @@ import org.robolectric.annotation.Config
@Config(sdk = [33])
class CoreAllocationPrefsTest {
private val app get() = RuntimeEnvironment.getApplication()
- private val defaults = CpuAllocationDefaults.Allocation("7", "3,4,5,6")
private val saved get() = app.getSharedPreferences("session", Context.MODE_PRIVATE)
@Before fun clear() { saved.edit().clear().commit() }
- @Test fun absentPreferencesUseTheDeviceDefaultWithoutWritingIt() {
- assertEquals(SessionPrefs.CoreAllocation(true, "7", "3,4,5,6"), SessionPrefs.coreAllocation(app, defaults))
- assertTrue(saved.all.isEmpty())
- assertEquals(SessionPrefs.CoreAllocation(false, "", ""), SessionPrefs.coreAllocation(app, null))
+ @Test fun absentPreferencesLeaveEveryCoreToTheScheduler() {
+ assertFalse(SessionPrefs.clientCpusOverride(app))
+ assertEquals("", SessionPrefs.clientCpus(app))
+ assertEquals("", SessionPrefs.gameCpus(app))
}
- @Test fun explicitDisableAndAllCoreChoicesSurviveAnUpdate() {
- saved.edit().putBoolean("clientCpusOverride", false).putString("clientCpus", "").putString("gameCpus", "").commit()
- assertEquals(SessionPrefs.CoreAllocation(false, "", ""), SessionPrefs.coreAllocation(app, defaults))
- }
-
- @Test fun existingCustomMasksArePreserved() {
- saved.edit().putBoolean("clientCpusOverride", true).putString("clientCpus", "0,1").putString("gameCpus", "2,7").commit()
- assertEquals(SessionPrefs.CoreAllocation(true, "0,1", "2,7"), SessionPrefs.coreAllocation(app, defaults))
- }
-
- @Test fun anOldClientMaskIsNotEnabledWithoutAnOverrideChoice() {
- saved.edit().putString("clientCpus", "0,1").commit()
- assertEquals(SessionPrefs.CoreAllocation(false, "0,1", "3,4,5,6"), SessionPrefs.coreAllocation(app, defaults))
- }
-
- @Test fun changingOneChoiceDoesNotReplaceTheOtherDefaults() {
- SessionPrefs.setGameCpus(app, "0,1,2,3,4,5,6,7")
- assertEquals(SessionPrefs.CoreAllocation(true, "7", "0,1,2,3,4,5,6,7"), SessionPrefs.coreAllocation(app, defaults))
- SessionPrefs.setClientCpusOverride(app, false)
- assertEquals(SessionPrefs.CoreAllocation(false, "7", "0,1,2,3,4,5,6,7"), SessionPrefs.coreAllocation(app, defaults))
+ @Test fun savedChoicesAreKept() {
+ SessionPrefs.setClientCpusOverride(app, true)
+ SessionPrefs.setClientCpus(app, "7")
+ SessionPrefs.setGameCpus(app, "3,4,5,6")
+ assertTrue(SessionPrefs.clientCpusOverride(app))
+ assertEquals("7", SessionPrefs.clientCpus(app))
+ assertEquals("3,4,5,6", SessionPrefs.gameCpus(app))
}
}
diff --git a/app/src/test/java/com/droiddeck/launcher/session/LoadingStateTest.kt b/app/src/test/java/com/droiddeck/launcher/session/LoadingStateTest.kt
new file mode 100644
index 0000000000..c062823494
--- /dev/null
+++ b/app/src/test/java/com/droiddeck/launcher/session/LoadingStateTest.kt
@@ -0,0 +1,36 @@
+package com.droiddeck.launcher.session
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Test
+
+class LoadingStateTest {
+ @Test fun clientDownloadCountsMegabytesWhenTheRuntimeSaysThem() {
+ assertEquals(
+ "45 / 360 MB" to 12,
+ LoadingState.clientDownload("== STEP 17:38:20 downloading Steam: bins_linuxarm64_linuxarm64 (2/17), 45 of 360 MB"),
+ )
+ }
+
+ @Test fun aStalledDownloadStillShowsWhereItIs() {
+ assertEquals(
+ "45 / 360 MB" to 12,
+ LoadingState.clientDownload(
+ "== STEP 17:39:20 downloading Steam: bins_linuxarm64_linuxarm64 (2/17), 45 of 360 MB" +
+ " - interrupted (curl exit 28), trying again in 5 s",
+ ),
+ )
+ }
+
+ @Test fun anOlderRuntimeShowsThePartAndItsNumber() {
+ assertEquals(
+ "bins_linuxarm64_linuxarm64" to 11,
+ LoadingState.clientDownload("== STEP 17:38:17 downloading Steam: bins_linuxarm64_linuxarm64 (2/17)"),
+ )
+ assertEquals("a_all" to 50, LoadingState.clientDownload("== STEP 00:00:00 downloading Steam: a_all (1/2), 0 of 0 MB"))
+ }
+
+ @Test fun otherStepsAreNotClientDownloads() {
+ assertNull(LoadingState.clientDownload("== STEP 17:38:14 checking the Steam client (a first run downloads it)"))
+ }
+}
diff --git a/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt b/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt
index 5ce8030d5a..5d67d041a2 100644
--- a/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt
+++ b/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt
@@ -20,7 +20,7 @@ class OrientationTest {
}
@Test fun landscapeChoicesPersistGloballyAndCanRestoreAutomaticRotation() {
- assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, SessionPrefs.orientation(context))
+ assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
for (value in listOf(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
@@ -34,7 +34,7 @@ class OrientationTest {
@Test fun invalidStoredOrientationFallsBackAndInvalidChoicePreservesTheSavedValue() {
val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
prefs.edit().putInt("orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT).commit()
- assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, SessionPrefs.orientation(context))
+ assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
assertThrows(IllegalArgumentException::class.java) {
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
diff --git a/app/src/test/java/com/droiddeck/launcher/session/SteamDownloadMonitorTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SteamDownloadMonitorTest.kt
index e60c6dcd9f..52920aefca 100644
--- a/app/src/test/java/com/droiddeck/launcher/session/SteamDownloadMonitorTest.kt
+++ b/app/src/test/java/com/droiddeck/launcher/session/SteamDownloadMonitorTest.kt
@@ -101,6 +101,28 @@ class SteamDownloadMonitorTest {
}
}
+ @Test fun aLongLogIsFollowedFromWhereTheLastPollStopped() {
+ val root = Files.createTempDirectory("droiddeck-steam-download-").toFile()
+ try {
+ val contentLog = File(root, "root/.local/share/Steam/logs/content_log.txt").apply {
+ check(parentFile?.mkdirs() != false)
+ writeText(buildString {
+ repeat(5_000) { append("[2026-10-06 14:40:00] Detected write gap 64 MB in file \"data_$it.dat\"\r\n") }
+ append("[2026-10-06 14:44:17] AppID 44 App update changed : Running Update,Downloading,\r\n")
+ })
+ }
+ val monitor = SteamDownloadMonitor()
+
+ assertTrue(monitor.poll(root, now = 1_000L))
+ contentLog.appendText("[2026-10-06 14:45:03] AppID 44 App update changed : None\r\n")
+ assertFalse(monitor.poll(root, now = 2_000L))
+ contentLog.appendText("[2026-10-06 14:46:00] AppID 45 App update changed : Running Update,Downloading,\r\n")
+ assertTrue(monitor.poll(root, now = 3_000L))
+ } finally {
+ root.deleteRecursively()
+ }
+ }
+
@Test fun theOtherClientsLogIsReadFromItsStart() {
val root = Files.createTempDirectory("droiddeck-steam-download-").toFile()
try {
@@ -203,6 +225,38 @@ class SteamDownloadMonitorTest {
}
}
+ @Test fun theClientIsPendingUntilItIsInstalledAndStamped() {
+ val root = Files.createTempDirectory("droiddeck-steam-client-").toFile()
+ try {
+ val steam = File(root, "root/.local/share/Steam")
+ assertTrue(SteamDownloadMonitor.clientInstallPending(root))
+ File(steam, "steamrtarm64").mkdirs()
+ File(steam, "steamrtarm64/steam").writeText("client")
+ assertTrue(SteamDownloadMonitor.clientInstallPending(root))
+ File(steam, "package").mkdirs()
+ File(steam, "package/droiddeck-installed").writeText("1791686101\n")
+ assertFalse(SteamDownloadMonitor.clientInstallPending(root))
+ } finally {
+ root.deleteRecursively()
+ }
+ }
+
+ @Test fun anOlderStampCountsAndARepairRequestIsPending() {
+ val root = Files.createTempDirectory("droiddeck-steam-client-").toFile()
+ try {
+ val steam = File(root, "root/.local/share/Steam")
+ File(steam, "steamrtarm64").mkdirs()
+ File(steam, "steamrtarm64/steam").writeText("client")
+ File(steam, "package").mkdirs()
+ File(steam, "package/bannerlator-installed").writeText("1\n")
+ assertFalse(SteamDownloadMonitor.clientInstallPending(root))
+ File(root, "root/.bl-steam-repair").writeText("1\n")
+ assertTrue(SteamDownloadMonitor.clientInstallPending(root))
+ } finally {
+ root.deleteRecursively()
+ }
+ }
+
private fun manifest(root: File, appId: String, downloaded: Long, total: Long, flags: Int): File {
val file = File(root, "steamapps/appmanifest_$appId.acf")
check(file.parentFile?.mkdirs() != false)
diff --git a/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt
index c40ef5b201..78e9bbc0d0 100644
--- a/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt
+++ b/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt
@@ -38,6 +38,43 @@ class StoreInstallRootTest {
assertEquals(1, StoreInstallRoot.targets(app).size)
}
+ @Test fun externalStoreInstallPathsMapIntoTheirGuestMountWithoutPrefixCollisions() {
+ val cardRoot = File(app.filesDir, "card/Games").apply { mkdirs() }
+ val guestRoot = "/mnt/droiddeck-stores/card"
+ val roots = listOf(cardRoot to guestRoot)
+
+ assertEquals("$guestRoot/Stores/Xbox/Doom", StoreInstallRoot.externalGuestPath(
+ File(cardRoot, "Stores/Xbox/Doom"), roots))
+ assertEquals(null, StoreInstallRoot.externalGuestPath(
+ File(cardRoot.parentFile, "Games-old/Stores/Xbox/Doom"), roots))
+ }
+
+ @Test fun xodusMapsTheSelectedSteamLibraryOnAnExternalVolume() {
+ val library = File(app.filesDir, "card/steam").apply { mkdirs() }
+ val storeRoot = File(library, "Games").apply { mkdirs() }
+ SessionPrefs.setGameStorage(app, library.path, "Card")
+
+ val xodusRoot = StoreInstallRoot.externalRootsForXodus(app).single { it.first.absolutePath == storeRoot.absolutePath }
+ val gameFolder = File(storeRoot, "Xbox/Doom")
+ assertEquals("${xodusRoot.second}/Xbox/Doom", StoreInstallRoot.guestPathForXodus(app, gameFolder))
+
+ val bindSpecs = StoreInstallRoot.externalBindSpecsForXodus(app)
+ assertTrue(bindSpecs.contains("${storeRoot.path}:${xodusRoot.second}"))
+ assertTrue(File(LinuxRuntime.rootDir(app), xodusRoot.second.removePrefix("/")).isDirectory)
+ }
+
+ @Test fun externalStoreBindsCreateGuestTargetsAndSkipUnavailableVolumes() {
+ val host = File(app.filesDir, "card/Games").apply { mkdirs() }
+ val guestRoot = "/mnt/droiddeck-stores/card"
+ val guestFs = File(app.filesDir, "linuxfs").apply { mkdirs() }
+ val missing = File(app.filesDir, "missing/Games")
+
+ assertEquals(listOf("${host.path}:$guestRoot"), StoreInstallRoot.externalBindSpecs(
+ listOf(host to guestRoot, missing to "/mnt/droiddeck-stores/missing"), guestFs))
+ assertTrue(File(guestFs, "mnt/droiddeck-stores/card").isDirectory)
+ assertFalse(File(guestFs, "mnt/droiddeck-stores/missing").exists())
+ }
+
@Test fun anExistingInstallWinsOverAFreshFolderUnderTheChosenRoot() {
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
val existing = File(StoreInstallRoot.storeDir(StoreInstallRoot.internalRoot(app), Store.GOG), "Old Name").apply { mkdirs() }
diff --git a/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicClientTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicClientTest.kt
index 720e122c19..c0687db98c 100644
--- a/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicClientTest.kt
+++ b/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicClientTest.kt
@@ -285,6 +285,28 @@ class EpicClientTest {
assertTrue(EpicClient.loopback("http://localhost:5/launcher/authorized?code=1"))
}
+ @Test fun theManifestLaunchCommandJoinsTheGameArguments() {
+ val store = com.droiddeck.launcher.stores.Store.EPIC
+ val epicArgs = listOf("-EpicPortal", "-epicapp=Fig", "-epicenv=Prod")
+ val installed = com.droiddeck.launcher.stores.StoreGameSidecar(store, "Fig", "Fig Game", exe = "Fig.exe", args = epicArgs)
+ val first = EpicClientLibrary.withLaunchArgs(installed, listOf("-PCStore=EGS"))
+ assertEquals(epicArgs + "-PCStore=EGS", first.args)
+ assertTrue(EpicClientLibrary.withLaunchArgs(first, listOf("-PCStore=EGS")) === first)
+ val updated = EpicClientLibrary.withLaunchArgs(first, listOf("-PCStore=EGS", "-log=a b.txt"))
+ assertEquals(epicArgs + listOf("-PCStore=EGS", "-log=a b.txt"), updated.args)
+ val dropped = EpicClientLibrary.withLaunchArgs(updated, emptyList())
+ assertEquals(epicArgs, dropped.args)
+ assertFalse(dropped.extra.containsKey("launchArgs"))
+ val reinstalled = first.copy(args = epicArgs)
+ assertEquals(epicArgs + "-PCStore=EGS", EpicClientLibrary.withLaunchArgs(reinstalled, listOf("-PCStore=EGS")).args)
+ assertTrue(EpicClientLibrary.withLaunchArgs(installed, emptyList()) === installed)
+ val own = installed.copy(args = epicArgs + "-PCStore=EGS")
+ assertTrue(EpicClientLibrary.withLaunchArgs(own, listOf("-PCStore=EGS")) === own)
+ val ownUpdated = EpicClientLibrary.withLaunchArgs(own, listOf("-PCStore=EGS", "-log=a b.txt"))
+ assertEquals(epicArgs + listOf("-PCStore=EGS", "-log=a b.txt"), ownUpdated.args)
+ assertEquals(epicArgs + "-PCStore=EGS", EpicClientLibrary.withLaunchArgs(ownUpdated, emptyList()).args)
+ }
+
@Test fun itemsDescribeTheInstallForTheLauncher() {
val install = EpicClientLibrary.Install(
"Fig", "ns1", "item1", "Fig Game", "1.0.5", "Binaries/Win64/Fig.exe", "/root/Games/Stores/Epic/Fig Game",
diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md
index a6e02b8e27..62530ca48d 100644
--- a/docs/development/game-environment.md
+++ b/docs/development/game-environment.md
@@ -52,6 +52,12 @@ environment entries and is intentionally narrower than **Reset game profile**.
Values are literal strings, with no shell expansion; quotes are only needed when
the consuming program expects them.
+A Unity game under FEX (`UnityPlayer.dll` for Windows builds under Proton,
+`UnityPlayer.so` or `GameAssembly.so` for native Linux builds started by
+**Linux x86 (FEX)**) keeps FEX's TSO on when the Default profile's FEX preset
+turns it off: without TSO such games can deadlock or crash (seen with Megabonk
+and Crab Game). A FEX preset chosen for the game itself still applies.
+
## Defaults and available suggestions
The initial configuration enables Mesa shader caching with
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-games b/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-games
index d86d10b6cc..fe1cf0d971 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-games
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-games
@@ -8,7 +8,7 @@ X64 = os.environ.get("BL_STEAM_CLIENT_ARCH") == "x86_64"
CLIENT_HOME = (os.environ.get("BL_X64_HOME") or os.path.join(HOME, ".droiddeck-x64")) if X64 else HOME
STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(CLIENT_HOME, ".local/share/Steam")
LIBRARIES = ((STEAM_ROOT, "Steam Games"), ("/mnt/droiddeck-sd/x86-64" if X64 else "/mnt/droiddeck-sd", "SD Games"))
-NOT_GAMES = {228980, 1070560, 1391110, 1493710, 1628350, 3127680, 4183110, 4185400, 4427310, 4628740}
+NOT_GAMES = {228980, 1070560, 1161040, 1391110, 1493710, 1628350, 1826330, 3127680, 4183110, 4185400, 4427310, 4628740}
APPS_DIR = os.path.join(HOME, ".local/share/applications")
PREFIX = "droiddeck-game-"
NAME = re.compile(r'^\s*"name"\s*"([^"]*)"', re.M)
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex
index 331dcfecc2..6ca792143d 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex
@@ -589,7 +589,8 @@ def guest_environment(fex, env):
result["FEX_THUNKHOSTLIBS"] = fex["host_thunks"]
result["FEX_THUNKGUESTLIBS"] = fex["guest_thunks"]
result["FEX_THUNKCONFIG"] = os.path.join(CONFIG_DIR, "ThunksConfig.json")
- preload = [part for part in split_paths(result.get("LD_PRELOAD")) if os.path.exists(part) and not is_arm(part)]
+ preload = [part for part in split_paths(result.get("LD_PRELOAD"))
+ if "/" not in part or (os.path.exists(part) and not is_arm(part))]
library_path = [part for part in (result.get("LD_LIBRARY_PATH") or "").split(":")
if part and "arm64" not in part and "aarch64" not in part]
for name, parts in (("LD_PRELOAD", preload), ("LD_LIBRARY_PATH", library_path)):
@@ -671,15 +672,26 @@ def launch(command, env, mode, decide=None):
return os.execve(fex["bin"], [fex["bin"], program] + command[1:], guest)
-def game_environment(env):
+def game_environment(env, command):
try:
game_env = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-game-env"))
env = game_env["game_gpu"](env)
app = game_env["game_id"](env) or env.get("SteamAppId") or env.get("SteamGameId")
if not app:
return env
- with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
- return game_env["apply_config"](env, json.load(source), str(app))
+ fixes = {}
+ game = game_env["Game"](resolve(command[0], env), command[1:])
+ for check in game_env["FIXES"]:
+ found = check(game)
+ if found and found[0]:
+ fixes.update(found[0])
+ say(found[2])
+ try:
+ with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
+ config = json.load(source)
+ except FileNotFoundError:
+ config = {"version": 1}
+ return game_env["apply_config"](env, config, str(app), fixes)
except FileNotFoundError:
return env
except Exception as error:
@@ -810,7 +822,7 @@ def main(argv):
return 0
if not command:
return 2
- return launch(command, game_environment(dict(os.environ)), os.environ.get("DROIDDECK_FEX", "auto"))
+ return launch(command, game_environment(dict(os.environ), command), os.environ.get("DROIDDECK_FEX", "auto"))
if action == "run":
try:
mode, decide, command = parse_run(args)
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env
index a38d77d8c5..53537c072f 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env
@@ -87,6 +87,12 @@ def dotnet_memory_ordering(game):
return DOTNET_FEX, [], ".NET runtime: FEX with full TSO and without multiblock"
+@fix
+def unity_memory_ordering(game):
+ if {"unityplayer.so", "gameassembly.so", "unityplayer.dll"} & game.files:
+ return {"FEX_TSOENABLED": "1"}, [], "Unity: FEX with TSO"
+
+
@fix
def godot_vulkan(game):
if is_godot(game) and not game.has_arg("--rendering-driver"):
@@ -114,6 +120,21 @@ def arkham_city_x87(game):
return {"FEX_X87REDUCEDPRECISION": "0"}, [], "Batman: Arkham City: FEX with full x87 precision"
+
+@fix
+def caravan_sandwitch_feature_level(game):
+ if "caravansandwitch.exe" in game.files or game.stem == "caravansandwitch-win64-shipping":
+ return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Caravan SandWitch: D3D12 feature level 12_1 (12_2 hands it mesh shader pipelines vkd3d-proton cannot build)"
+
+
+@fix
+def cyberpunk_feature_level(game):
+ if game.stem == "cyberpunk2077" or (
+ game.stem == "redprelauncher"
+ and os.path.isfile(os.path.join(os.path.dirname(game.exe), "bin", "x64", "Cyberpunk2077.exe"))
+ ):
+ return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Cyberpunk 2077: D3D12 feature level 12_1"
+
def skip_red_launcher(command):
"""Cyberpunk 2077's prelauncher opens REDlauncher, a Qt WebEngine window that hands over to the
game half a minute later and then stays up beside it, well over a core busy for as long as the
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-seed-redists b/tools/linuxfs/overlay/usr/local/bin/droiddeck-seed-redists
index 831a0e4cee..86d3f1c31a 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-seed-redists
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-seed-redists
@@ -24,7 +24,7 @@ read_scripts() { xargs -0 -r awk -v want="${1:-redists}" '
proc[depth] = 1
program = tolower(part[4])
sub(/.*[\\\/]/, "", program)
- if (program ~ /vulkan/) vulkan[depth] = 1
+ if (program ~ /vulkan|uplay|ubisoft/) vulkan[depth] = 1
next
}
if (n == 3) pending = part[2]
@@ -243,7 +243,7 @@ for system in "${regs[@]}"; do
had=()
for line in "${kept[@]}"; do had[$line]=1; done
printf '%s\n' "${other[@]}" "${kept[@]}" >"$seeded"
- echo "== took Vulkan runtime markers out of $reg"
+ echo "== took Vulkan runtime and Ubisoft Connect markers out of $reg"
fi
if [ ${#had[@]} -gt 0 ] && { [ -z "$id" ] || [ "$id" != "$prev" ]; }; then
declare -A held=()
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat
index 3972faa9b3..1de4bcf1c9 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat
@@ -583,9 +583,8 @@ class Helper:
picked = COMPAT["picked_apps"](state)
runnable = {t["name"].lower() for t in live}
apps = sorted(set(installed) | set(picks) | set(prior_auto) | native_choices, key=COMPAT["app_order"])
- overrides = COMPAT["requested_games"](
- COMPAT["game_requests"](), catalog, [t["name"] for t in live])
- apps = sorted(set(apps) | set(overrides), key=COMPAT["app_order"])
+ asked = [app for app, request in COMPAT["game_requests"]().items() if COMPAT["valid_game_request"](app, request)]
+ apps = sorted(set(apps) | set(asked), key=COMPAT["app_order"])
current = dict(page.compat("many(%s)" % json.dumps(apps)) or {})
refused = set(apps) - set(current)
refused_native = native_choices & refused
@@ -597,7 +596,6 @@ class Helper:
if isinstance(state.get("auto"), dict):
state["auto"] = prior_auto
native_choices -= refused
- overrides = {app: tool for app, tool in overrides.items() if app not in refused}
current["0"] = top["selected"]
native = COMPAT["native_targets"](self.steam_root, apps)
raw_mapping = COMPAT["read_config_mapping"](
@@ -619,6 +617,9 @@ class Helper:
current[app] = ""
elif not current.get(app):
current.pop(app, None)
+ requests = COMPAT["settled_game_requests"](state, current, catalog)
+ overrides = COMPAT["requested_games"](requests or {}, catalog, [t["name"] for t in live])
+ overrides = {app: tool for app, tool in overrides.items() if app not in refused}
changes, auto = COMPAT["plan_mapping"](
current, installed, [t["name"] for t in live], default,
COMPAT["followers"](state, current), native, picks, overrides,
@@ -630,7 +631,8 @@ class Helper:
state.update(
auto={app: tool for app, tool in auto.items() if tool is not COMPAT["NATIVE_CHOICE"]},
native_choices=sorted(refused_native | {app for app, tool in auto.items() if tool is COMPAT["NATIVE_CHOICE"]}),
- picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True)
+ picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True,
+ games_applied=COMPAT["applied_game_requests"](requests, overrides, state))
state.pop("native", None)
if waiting:
state["pending"] = wanted
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-install b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-install
index 8ebef7ea5d..45bd96c259 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-install
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-install
@@ -25,6 +25,7 @@ stamp=$steam_root/package/droiddeck-installed
legacy_stamp=$steam_root/package/bannerlator-installed
unconfirmed=$steam_root/package/droiddeck-unconfirmed
repair_request=$HOME/.bl-steam-repair
+parts=$steam_root/package/droiddeck-download
if [ -f "$legacy_stamp" ] && [ ! -f "$stamp" ]; then
mv -f "$legacy_stamp" "$stamp" || true
fi
@@ -47,6 +48,10 @@ if [ -n "$fallback" ]; then
fi
if [ -n "$repair" ]; then
echo "== STEP $(date -u +%H:%M:%S) repairing the Steam client ($repair)"
+ if [ ! -f "$parts/.repair" ]; then
+ rm -rf "$parts"
+ mkdir -p "$parts" && : > "$parts/.repair"
+ fi
rm -f "$stamp" "$legacy_stamp" "$steam_root/.crash" "$steam_root/steam.pid" \
"$steam_root"/package/steam_client_*.manifest "$steam_root"/package/steam_client_*.installed
for part in "$steam_root"/package/*.zip.*; do
@@ -69,6 +74,62 @@ fi
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
+
+nap() {
+ [ -n "${nap_fd:-}" ] || exec {nap_fd}<> <(:)
+ read -r -t "$1" -u "$nap_fd" _ 2>/dev/null || :
+}
+size_of() {
+ local n=0
+ [ -f "$1" ] && n=$(wc -c < "$1")
+ echo $((n))
+}
+limits=(--connect-timeout 30 --speed-limit 4096 --speed-time 60)
+read -r -a delays <<< "${BL_STEAM_RETRY_DELAYS:-5 10 20 30 30}"
+
+step() { echo "== STEP $(date -u +%H:%M:%S) $*"; }
+progress() {
+ local mb=$(( (done_bytes + $(size_of "$1")) / 1000000 ))
+ [ -z "${3:-}" ] && [ "$mb" = "${shown_mb:-}" ] && [ "$2" = "${shown_part:-}" ] && return 0
+ shown_mb=$mb shown_part=$2
+ step "downloading Steam: $2 ($i/$total), $mb of $((total_bytes / 1000000)) MB${3:+ - $3}"
+}
+
+fetch() {
+ local url=$1 dest=$2 size=$3 sum=$4 part=$5 failures=0 bad=0 finished=0 before rc fd wait
+ while :; do
+ if [ -f "$dest" ] && { [ "$finished" = 1 ] || { [ "$size" -gt 0 ] && [ "$(size_of "$dest")" -ge "$size" ]; }; }; then
+ echo "$sum $dest" | sha256sum -c --quiet 2>/dev/null && return 0
+ rm -f "$dest"
+ finished=0 bad=$((bad + 1))
+ [ "$bad" -lt 3 ] || { echo "droiddeck-steam-install: $part does not match its checksum" >&2; return 1; }
+ fi
+ before=$(size_of "$dest")
+ exec {fd}< <(code=$(curl -fsSL "${limits[@]}" -w '%{http_code}' -C - -o "$dest" "$url") && echo "0 $code" || echo "$? $code")
+ until read -r -t 5 -u "$fd" rc http; do
+ if [ $? -le 128 ]; then rc=1; break; fi
+ progress "$dest" "$part"
+ done
+ exec {fd}<&-
+ if [ "$rc" = 0 ]; then finished=1; continue; fi
+ case "$rc:${http:-}" in
+ 22:416 | 33:*) rm -f "$dest" ;;
+ 22:4??)
+ echo "droiddeck-steam-install: $part: HTTP $http from ${url%/*}" >&2
+ return 1
+ ;;
+ esac
+ if [ "$(size_of "$dest")" -gt "$before" ]; then failures=0; else failures=$((failures + 1)); fi
+ if [ "$failures" -gt "${#delays[@]}" ]; then
+ echo "droiddeck-steam-install: could not download $part (curl exit $rc); what arrived is kept for the next try" >&2
+ return 1
+ fi
+ wait=${delays[$((failures > 0 ? failures - 1 : 0))]}
+ progress "$dest" "$part" "interrupted (curl exit $rc), trying again in ${wait} s"
+ nap "$wait"
+ done
+}
+
fetch_manifest() {
cdn=""
for candidate in $cdn_list; do
@@ -88,7 +149,8 @@ fetch_manifest() {
/^\t"/ && NF >= 3 && $4 == "" { block = $2 }
$2 == "file" { file[block] = $4 }
$2 == "sha2" { sha[block] = $4 }
- END { for (b in file) if (b ~ /_all$/ || b ~ /_linuxarm64_linuxarm64$/) print b, file[b], sha[b] }
+ $2 == "size" { size[block] = $4 }
+ END { for (b in file) if (b ~ /_all$/ || b ~ /_linuxarm64_linuxarm64$/) print b, file[b], sha[b], size[b] + 0 }
' "$work/manifest" | sort > "$work/parts"
[ -s "$work/parts" ] && return 0
echo "droiddeck-steam-install: no client components in $manifest; its blocks are:" \
@@ -114,23 +176,35 @@ if [ -n "$sync" ]; then
echo "== STEP $(date -u +%H:%M:%S) updating the arm64 Steam client to $version (was ${installed:-none}) for the x86-64 client"
fi
total=$(grep -c . "$work/parts" 2>/dev/null || echo 0)
+total_bytes=$(awk '{ n += $4 } END { print n + 0 }' "$work/parts")
-mkdir -p "$steam_root/package"
-while read -r block file sum; do
+mkdir -p "$parts"
+for left in "$parts"/*; do
+ [ -e "$left" ] || continue
+ name=${left##*/}
+ name=${name%.unpacked}
+ grep -qF " $name " "$work/parts" || rm -rf "$left"
+done
+done_bytes=0
+while read -r block file sum size; do
i=$((${i:-0} + 1))
- echo "== STEP $(date -u +%H:%M:%S) downloading Steam: $block ($i/$total)"
+ if [ -f "$parts/$file.unpacked" ]; then
+ done_bytes=$((done_bytes + size))
+ continue
+ fi
+ progress "$parts/$file" "$block"
fetched=""
for host in "${cdn_order[@]}"; do
- if curl -fsSL --connect-timeout 10 --speed-limit 1024 --speed-time 60 --max-time 1800 \
- "$host/$file" -o "$work/$file" && echo "$sum $work/$file" | sha256sum -c --quiet; then
+ if fetch "$host/$file" "$parts/$file" "$size" "$sum" "$block"; then
fetched=$host
break
fi
- rm -f "$work/$file"
done
[ -n "$fetched" ] || { echo "droiddeck-steam-install: $file failed on every CDN" >&2; exit 1; }
- unzip -qo "$work/$file" -d "$steam_root"
- rm -f "$work/$file"
+ unzip -qo "$parts/$file" -d "$steam_root"
+ : > "$parts/$file.unpacked"
+ rm -f "$parts/$file"
+ done_bytes=$((done_bytes + size))
done < "$work/parts"
find "$steam_root" -depth -name '*\\*' | while read -r odd; do
fixed=${odd//\\//}
@@ -159,6 +233,7 @@ ln -sfn "$steam_root/linuxarm64" "$HOME/.steam/sdkarm64"
ln -sfn "$steam_root/steamrtarm64" "$HOME/.steam/binarm64"
ln -sfn "$steam_root/linux32" "$HOME/.steam/sdk32"
echo "$version" > "$stamp"
+rm -rf "$parts"
if [ -n "$fallback" ]; then
echo "$stable_channel" > "$channel_state"
echo "== STEP $(date -u +%H:%M:%S) the Steam client now follows $stable_channel (beta in ~/.config/droiddeck/steam-channel returns to $beta_channel)"
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-shortcuts b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-shortcuts
index 3764e4a92c..0910cf6faf 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-shortcuts
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-shortcuts
@@ -18,13 +18,17 @@ TAG = "droiddeck-app"
def account_dir(steam_root):
"""The most recent account's userdata folder, else the only one that is not 0."""
users = os.path.join(steam_root, "config", "loginusers.vdf")
- recent = None
+ recent, best = None, None
try:
with open(users, encoding="utf-8", errors="replace") as f:
text = f.read()
for block in re.finditer(r'"(\d{5,})"\s*\{([^}]*)\}', text):
- if re.search(r'"MostRecent"\s*"1"', block.group(2)):
- recent = int(block.group(1))
+ stamp = re.search(r'"timestamp"\s*"(\d+)"', block.group(2))
+ rank = (bool(re.search(r'"MostRecent"\s*"1"', block.group(2))),
+ bool(re.search(r'"AutoLogin"\s*"1"', block.group(2))),
+ int(stamp.group(1)) if stamp else 0)
+ if any(rank) and (best is None or rank >= best):
+ recent, best = int(block.group(1)), rank
except OSError:
pass
userdata = os.path.join(steam_root, "userdata")
diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility
index 41a37a9aa5..29fe4f8e43 100755
--- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility
+++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility
@@ -1113,10 +1113,89 @@ def requested_tool(request, catalog):
def game_requests(directory=None):
- value = read_json(state_path("games.json", directory))
- if value.get("version") != 1 or not isinstance(value.get("games"), dict):
- return {}
- return value["games"]
+ return read_game_requests(directory)[0]
+
+
+def read_game_requests(directory=None):
+ try:
+ with open(state_path("games.json", directory), encoding="utf-8") as f:
+ text = f.read()
+ value = json.loads(text)
+ except (OSError, ValueError):
+ return {}, None
+ if not isinstance(value, dict) or value.get("version") != 1 or not isinstance(value.get("games"), dict):
+ return {}, text
+ return value["games"], text
+
+
+def write_game_requests(requests, original, directory=None):
+ path = state_path("games.json", directory)
+ try:
+ with open(path, encoding="utf-8") as f:
+ if f.read() != original:
+ return False
+ except OSError:
+ if original is not None:
+ return False
+ return write_json(path, {"version": 1, "games": requests})
+
+
+def valid_game_request(app, request):
+ return (isinstance(app, str) and re.fullmatch(r"[1-9][0-9]*", app) is not None and int(app) <= 0xFFFFFFFF and
+ (request is None or isinstance(request, dict) and isinstance(request.get("dir"), str) and
+ request["dir"] != "" and isinstance(request.get("valve"), bool)))
+
+
+def settle_game_requests(requests, state, current, catalog, missing_is_cleared=False):
+ recorded = state.get("games_applied")
+ if isinstance(recorded, dict):
+ applied = dict(recorded)
+ else:
+ applied = dict(requests) if "tools" in state else {}
+ by_name = {t["name"]: t for t in catalog}
+ out = dict(requests)
+ for app, request in requests.items():
+ if not valid_game_request(app, request) or app not in applied or applied[app] != request:
+ continue
+ if request is None:
+ del out[app]
+ continue
+ wanted = requested_tool(request, catalog)
+ if wanted is None:
+ continue
+ if app in current:
+ picked = current[app]
+ elif missing_is_cleared:
+ picked = ""
+ else:
+ continue
+ if picked == wanted:
+ continue
+ tool = by_name.get(picked)
+ if tool and tool["dir"]:
+ out[app] = {"valve": tool["valve"], "dir": tool["dir"]}
+ else:
+ del out[app]
+ return out, out != requests
+
+
+def settled_game_requests(state, current, catalog, missing_is_cleared=False, directory=None):
+ for _ in range(2):
+ requests, text = read_game_requests(directory)
+ settled, moved = settle_game_requests(requests, state, current, catalog, missing_is_cleared)
+ if not moved or write_game_requests(settled, text, directory):
+ return settled
+ return None
+
+
+def applied_game_requests(requests, overrides, state):
+ recorded = state.get("games_applied")
+ before = recorded if isinstance(recorded, dict) else {}
+ if requests is None:
+ return dict(before)
+ return {app: request if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL else before[app]
+ for app, request in requests.items()
+ if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL or app in before}
def requested_games(requests, catalog, runnable=None):
@@ -1306,7 +1385,8 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
else:
default = state.get("default") if state.get("default") in names else TOOL
steam_root = os.path.dirname(os.path.dirname(os.path.abspath(config_path)))
- overrides = requested_games(game_requests(directory), catalog)
+ requests = settled_game_requests(state, current, catalog, not steam_running(), directory)
+ overrides = requested_games(requests or {}, catalog)
managed = state.get("auto", {}).keys() if isinstance(state.get("auto"), dict) else ()
native_choices = state.get("native_choices", ())
native = native_targets(steam_root, set(apps) | set(picks) | set(managed) | set(native_choices))
@@ -1325,6 +1405,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
state["auto"] = {app: tool for app, tool in auto.items() if tool is not NATIVE_CHOICE}
state["native_choices"] = sorted(app for app, tool in auto.items() if tool is NATIVE_CHOICE)
state["picked"] = picked_after(current, changes)
+ state["games_applied"] = applied_game_requests(requests, overrides, state)
state.pop("native", None)
state["tools"] = catalog
state.setdefault("default", default)
diff --git a/tools/packs/build.sh b/tools/packs/build.sh
index d06a4c8fb4..27611ab0b4 100755
--- a/tools/packs/build.sh
+++ b/tools/packs/build.sh
@@ -25,14 +25,7 @@ trap 'rm -rf "$work"' EXIT
sha256() { if command -v sha256sum >/dev/null; then sha256sum "$1" | cut -d' ' -f1; else shasum -a 256 "$1" | cut -d' ' -f1; fi; }
fetch() {
- local url=$1 expected=$2 dest=$3
- curl -fsSL --retry 4 -o "$dest" "$url"
- local actual
- actual=$(sha256 "$dest")
- if [ "$actual" != "$expected" ]; then
- echo "checksum mismatch for $url: $actual" >&2
- exit 1
- fi
+ bash "$here/fetch-verified.sh" "$@"
}
pack() {
diff --git a/tools/packs/fetch-verified.sh b/tools/packs/fetch-verified.sh
new file mode 100644
index 0000000000..41bba28190
--- /dev/null
+++ b/tools/packs/fetch-verified.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+set -euo pipefail
+url=${1:?URL required}
+expected=${2:?SHA-256 required}
+destination=${3:?destination required}
+[[ "$expected" =~ ^[a-f0-9]{64}$ ]] || { echo 'Invalid download SHA-256' >&2; exit 1; }
+cache=${DROIDDECK_PACK_CACHE:-"$HOME/.cache/droiddeck-pack-inputs"}
+mkdir -p "$cache" "$(dirname "$destination")"
+kept="$cache/$expected"
+verify() {
+ if command -v sha256sum >/dev/null; then
+ echo "$expected $1" | sha256sum -c - >/dev/null 2>&1
+ else
+ echo "$expected $1" | shasum -a 256 -c - >/dev/null 2>&1
+ fi
+}
+if [ -f "$kept" ] && verify "$kept"; then
+ echo "Verified pack input cache hit: $expected"
+else
+ part=$(mktemp "$cache/$expected.part.XXXXXX")
+ trap 'rm -f "$part"' EXIT
+ curl -fsSL --retry 4 --retry-all-errors --connect-timeout 15 --max-time 180 --retry-max-time 240 \
+ -o "$part" "$url"
+ verify "$part" || { echo "Checksum mismatch for $url" >&2; exit 1; }
+ if [ -d "$kept" ]; then
+ rm -rf -- "$kept"
+ fi
+ mv -f "$part" "$kept"
+ echo "Downloaded and verified pack input: $expected"
+fi
+cp "$kept" "$destination"
+verify "$destination" || { echo 'Copied pack input checksum mismatch' >&2; exit 1; }
diff --git a/tools/release/report-build.sh b/tools/release/report-build.sh
index fc031c634f..75b16f666f 100644
--- a/tools/release/report-build.sh
+++ b/tools/release/report-build.sh
@@ -69,7 +69,7 @@ MARK=""
echo
} > /tmp/pr-report.md
cat /tmp/pr-report.md >> "$GITHUB_STEP_SUMMARY"
-ID=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR}/comments" --paginate --jq ".[] | select(.body | startswith(\"$MARK\")) | .id" | head -1 || true)
+ID=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR}/comments" --paginate --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$MARK\"))) | .id" | head -1 || true)
if [ -n "$ID" ]; then
gh api -X PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${ID}" -F body=@/tmp/pr-report.md >/dev/null
else
diff --git a/tools/release/runtime_inputs.py b/tools/release/runtime_inputs.py
index 83f87be033..ccce1f0f0d 100644
--- a/tools/release/runtime_inputs.py
+++ b/tools/release/runtime_inputs.py
@@ -21,7 +21,7 @@ PACKED_FILES = {'lib/arm64-v8a/libproot.so': ('proot', 'libproot.so'),
PACKED_LIBRARIES = ['lib/arm64-v8a/libopencv_java4.so', 'lib/arm64-v8a/libmediapipe_tasks_jni.so']
PACK_NAMES = ['proot', 'directaudio', 'tracking', 'xbox', 'comet']
SOURCE_PATHS = ['app/build.gradle', 'app/src/main/cpp/fakeinput_steam.cpp', 'app/src/main/assets/pulseaudio.tzst',
- 'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio',
+ 'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio', 'tools/packs',
'tools/gamescope/release.env', 'tools/droiddeck-esync/release.env',
'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/components', 'tools/ci', 'tools/build_local.sh',
'tools/release/runtime_inputs.py', 'app/src/main/assets/desktop-removal',
diff --git a/tools/tests/test_ci_checks.py b/tools/tests/test_ci_checks.py
index 3a0216d778..b7c29fceba 100644
--- a/tools/tests/test_ci_checks.py
+++ b/tools/tests/test_ci_checks.py
@@ -1,6 +1,9 @@
import itertools
+import json
import os
from pathlib import Path
+import shlex
+import shutil
import subprocess
import tempfile
import unittest
@@ -12,6 +15,37 @@ ROOT = Path(__file__).resolve().parents[2]
class CiChecksTest(unittest.TestCase):
+ def test_pr_cache_writes_and_source_timestamp_policy(self):
+ jobs = yaml.safe_load((ROOT / '.github/workflows/build.yml').read_text())['jobs']
+ cache = next(step for step in jobs['build']['steps']
+ if step.get('uses') == 'gradle/actions/setup-gradle@v4')['with']
+ self.assertEqual(cache['cache-read-only'],
+ "${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}")
+ gradle = (ROOT / 'app/build.gradle').read_text()
+ self.assertIn("gitValue(['show', '-s', '--format=%ct', '--end-of-options', sourceCommit])", gradle)
+
+ def test_report_comment_lookup_ignores_human_marker(self):
+ if not shutil.which('jq'):
+ self.skipTest('jq required to execute comment selection')
+ script = (ROOT / 'tools/release/report-build.sh').read_text()
+ line = next(line for line in script.splitlines() if line.startswith('ID='))
+ arguments = shlex.split(line[len('ID=$('):].split(' | head', 1)[0])
+ query = arguments[arguments.index('--jq') + 1].replace('$MARK', '')
+ comments = [dict(id=1, user=dict(login='someone'), body=' forged'),
+ dict(id=2, user=dict(login='github-actions[bot]'), body=' result')]
+ result = subprocess.check_output(['jq', '-r', query], input=json.dumps(comments), text=True)
+ self.assertEqual(result.strip(), '2')
+
+ def test_build_and_tests_use_identical_generated_metadata(self):
+ jobs = yaml.safe_load((ROOT / '.github/workflows/build.yml').read_text())['jobs']
+ steps = {step.get('id'): step for step in jobs['build']['steps']}
+ self.assertEqual(steps['build']['env'], steps['unit-tests']['env'])
+ self.assertIn('DROIDDECK_BUILD_LABEL', steps['unit-tests']['env'])
+ self.assertIn('SGDB_API_KEY', steps['unit-tests']['env'])
+ gradle = (ROOT / 'app/build.gradle').read_text()
+ self.assertIn("outputs.doNotCacheIf('CI executes the test suite on every run') { true }", gradle)
+ self.assertIn('outputs.upToDateWhen { false }', gradle)
+
def test_independent_jobs_wait_only_for_the_pinned_source(self):
jobs = yaml.safe_load((ROOT / '.github/workflows/build.yml').read_text())['jobs']
for name in ('xbox', 'components', 'python-tests'):
diff --git a/tools/tests/test_droiddeck_fex.py b/tools/tests/test_droiddeck_fex.py
index fed546dddc..e65b21277e 100644
--- a/tools/tests/test_droiddeck_fex.py
+++ b/tools/tests/test_droiddeck_fex.py
@@ -549,11 +549,12 @@ class LaunchTest(FexTestCase):
def test_the_guest_environment(self):
arm = self.write(self.tmp / "arm.so", elf(183))
x86 = self.write(self.tmp / "x86.so", elf(62))
- env = {"LD_PRELOAD": "%s:%s %s" % (arm, x86, self.tmp / "gone.so"),
+ env = {"LD_PRELOAD": "%s:%s %s libMelonLoader.Bootstrap.so" % (arm, x86, self.tmp / "gone.so"),
"LD_LIBRARY_PATH": "/steam/steamrtarm64:/usr/lib/aarch64-linux-gnu:/game/lib:/steam/linuxarm64",
"FEX_ROOTFS": "/usr/share/guestos/fex-mesa", "FEX_TSOENABLED": "1"}
guest = FEX["guest_environment"]({"portable": True}, env)
- self.assertEqual((guest["LD_PRELOAD"], guest["LD_LIBRARY_PATH"], guest["FEX_PORTABLE"]), (str(x86), "/game/lib", "1"))
+ self.assertEqual((guest["LD_PRELOAD"], guest["LD_LIBRARY_PATH"], guest["FEX_PORTABLE"]),
+ ("%s:libMelonLoader.Bootstrap.so" % x86, "/game/lib", "1"))
self.assertNotIn("FEX_ROOTFS", guest)
self.assertEqual(guest["FEX_TSOENABLED"], "1")
self.assertTrue(guest["FEX_APP_CONFIG_LOCATION"].endswith("/config/"))
@@ -690,6 +691,32 @@ class LaunchTest(FexTestCase):
command, env, mode = G["launch"].call_args[0]
self.assertEqual((command, mode), (["/game/run.sh", "-a"], "auto"))
+ def test_steam_games_get_their_settings_and_linux_unity_keeps_tso(self):
+ config = self.home / ".config/droiddeck/game-environment.json"
+ unity = self.write(self.tmp / "Megabonk/Megabonk.x86_64", elf(62), 0o755)
+ self.write(self.tmp / "Megabonk/UnityPlayer.so", elf(62))
+ self.write(self.tmp / "Megabonk/GameAssembly.so", elf(62))
+ other = self.write(self.tmp / "Other/game.x86_64", elf(62), 0o755)
+ self.write(config, json.dumps({"version": 1, "shared": {"FEX_TSOENABLED": "0", "FEX_MULTIBLOCK": "1"},
+ "games": {"20": {"FEX_TSOENABLED": "0"}}}))
+
+ def started(program, app):
+ with mock.patch.dict(G, {"launch": mock.Mock(return_value=0), "GAME_ENVIRONMENT": str(config)}), \
+ mock.patch.dict(os.environ, {"SteamAppId": app}, clear=True):
+ _, said = self.quiet(FEX["main"], ["steam", "waitforexitandrun", str(program), "-arg"])
+ command, env, _ = G["launch"].call_args[0]
+ self.assertEqual(command, [str(program), "-arg"])
+ return env.get("FEX_TSOENABLED"), env.get("FEX_MULTIBLOCK"), said
+
+ tso, multiblock, said = started(unity, "10")
+ self.assertEqual((tso, multiblock), ("1", "1"))
+ self.assertIn("Unity: FEX with TSO", said)
+ self.assertEqual(started(other, "10")[:2], ("0", "1"))
+ self.assertEqual(started(unity, "20")[:2], ("0", "1"))
+ config.unlink()
+ self.assertEqual(started(unity, "10")[:2], ("1", None))
+ self.assertEqual(started(other, "10")[:2], (None, None))
+
class AppInfoTest(unittest.TestCase):
COMPAT = runpy.run_path(str(BIN / "steam-compatibility"))
diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py
index c5c308c8cc..13b31f7435 100644
--- a/tools/tests/test_game_environment.py
+++ b/tools/tests/test_game_environment.py
@@ -357,6 +357,59 @@ class GameEnvironmentTest(unittest.TestCase):
(asylum / name).touch()
self.assertEqual(MODULE["engine_fixes"](str(asylum / "BmLauncher.exe"), []), ({}, [], []))
+ def test_caravan_sandwitch_and_cyberpunk_run_at_feature_level_12_1(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ caravan = Path(tmp) / "Caravan SandWitch"
+ shipping = caravan / "CaravanSandWitch/Binaries/Win64"
+ shipping.mkdir(parents=True)
+ for name in ("CaravanSandWitch.exe", ".droiddeck-launch.bat"):
+ (caravan / name).touch()
+ (shipping / "CaravanSandWitch-Win64-Shipping.exe").touch()
+ cyberpunk = Path(tmp) / "Cyberpunk 2077"
+ (cyberpunk / "bin/x64").mkdir(parents=True)
+ for name in ("REDprelauncher.exe", "bin/x64/Cyberpunk2077.exe"):
+ (cyberpunk / name).touch()
+ games = [caravan / "CaravanSandWitch.exe", caravan / ".droiddeck-launch.bat",
+ shipping / "CaravanSandWitch-Win64-Shipping.exe",
+ cyberpunk / "REDprelauncher.exe", cyberpunk / "bin/x64/Cyberpunk2077.exe"]
+ for exe in games:
+ env, extra, notes = MODULE["engine_fixes"](str(exe), [])
+ self.assertEqual((env, extra), ({"VKD3D_FEATURE_LEVEL": "12_1"}, []), exe)
+ self.assertTrue(notes)
+ config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2"}}
+ self.assertEqual(MODULE["apply_config"]({}, config, "1582650", env)["VKD3D_FEATURE_LEVEL"], "12_1")
+ config["games"] = {"1582650": {"VKD3D_FEATURE_LEVEL": "12_2"}}
+ self.assertEqual(MODULE["apply_config"]({}, config, "1582650", env)["VKD3D_FEATURE_LEVEL"], "12_2")
+ other = Path(tmp) / "Other/Binaries/Win64"
+ other.mkdir(parents=True)
+ (other / "Other-Win64-Shipping.exe").touch()
+ self.assertEqual(MODULE["engine_fixes"](str(other / "Other-Win64-Shipping.exe"), []), ({}, [], []))
+ witcher = Path(tmp) / "The Witcher 3"
+ witcher.mkdir()
+ (witcher / "REDprelauncher.exe").touch()
+ self.assertNotIn("VKD3D_FEATURE_LEVEL", MODULE["engine_fixes"](str(witcher / "REDprelauncher.exe"), [])[0])
+
+ def test_unity_players_keep_tso_over_the_preset(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ def game(*names):
+ for name in names:
+ (Path(tmp) / name).parent.mkdir(parents=True, exist_ok=True)
+ (Path(tmp) / name).touch()
+ return str(Path(tmp) / names[0])
+
+ il2cpp = game("Megabonk/Megabonk.x86_64", "Megabonk/UnityPlayer.so", "Megabonk/GameAssembly.so")
+ mono = game("Mono/Game.x86_64", "Mono/UnityPlayer.so")
+ windows = game("Crab Game/Crab Game.exe", "Crab Game/UnityPlayer.dll", "Crab Game/GameAssembly.dll")
+ windows_mono = game("RoR2/Risk of Rain 2.exe", "RoR2/UnityPlayer.dll", "RoR2/MonoBleedingEdge/mono-2.0-bdwgc.dll")
+ for exe in (il2cpp, mono, windows, windows_mono):
+ env, extra, notes = MODULE["engine_fixes"](exe, [])
+ self.assertEqual((env, extra, notes), ({"FEX_TSOENABLED": "1"}, [], ["Unity: FEX with TSO"]))
+ performance = {"version": 1, "shared": {"FEX_TSOENABLED": "0", "FEX_VECTORTSOENABLED": "0"}}
+ result = MODULE["apply_config"]({}, performance, "3405340", env)
+ self.assertEqual((result["FEX_TSOENABLED"], result["FEX_VECTORTSOENABLED"]), ("1", "0"))
+ performance["games"] = {"3405340": {"FEX_TSOENABLED": "0"}}
+ self.assertEqual(MODULE["apply_config"]({}, performance, "3405340", env)["FEX_TSOENABLED"], "0")
+
def test_a_new_fix_only_needs_registering(self):
with tempfile.TemporaryDirectory() as tmp:
(Path(tmp) / "Game.exe").touch()
diff --git a/tools/tests/test_gpu_clock_pin.c b/tools/tests/test_gpu_clock_pin.c
new file mode 100644
index 0000000000..5fdbe60330
--- /dev/null
+++ b/tools/tests/test_gpu_clock_pin.c
@@ -0,0 +1,188 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "../../app/src/main/cpp/adrenotools/src/hook/kgsl.h"
+#include "../../app/src/main/cpp/waylandcomp/src/gpu_clock_pin.h"
+
+enum { NONE, OPEN, DEVICE, CONTEXT, CONSTRAINT, MEMORY, MAP, SYNC, SUBMIT, THREAD, WAIT };
+static atomic_int failure, descriptors, contexts, memories, mappings, submissions, waits;
+static atomic_bool timeout_wait;
+static bool legacy_core;
+static uint32_t commands[1024];
+
+int __android_log_print(int priority, const char *tag, const char *format, ...) {
+ (void)priority; (void)tag; (void)format;
+ return 0;
+}
+
+int __wrap_open(const char *path, int flags, ...) {
+ (void)flags;
+ assert(!strcmp(path, "/dev/kgsl-3d0"));
+ if (atomic_load(&failure) == OPEN) { errno = EACCES; return -1; }
+ assert(atomic_fetch_add(&descriptors, 1) == 0);
+ return 91;
+}
+
+int __wrap_close(int fd) {
+ assert(fd == 91);
+ assert(atomic_fetch_sub(&descriptors, 1) == 1);
+ errno = EBADF;
+ return 0;
+}
+
+void *__wrap_mmap(void *address, size_t size, int protection, int flags, int fd, off_t offset) {
+ (void)address; (void)protection; (void)flags;
+ assert(fd == 91 && size == sizeof(commands) && offset == (23 << 12));
+ if (atomic_load(&failure) == MAP) { errno = EACCES; return MAP_FAILED; }
+ assert(atomic_fetch_add(&mappings, 1) == 0);
+ return commands;
+}
+
+int __wrap_munmap(void *address, size_t size) {
+ assert(address == commands && size == sizeof(commands));
+ assert(atomic_fetch_sub(&mappings, 1) == 1);
+ return 0;
+}
+
+#ifdef __ANDROID__
+int __wrap_ioctl(int fd, int request, ...) {
+#else
+int __wrap_ioctl(int fd, unsigned long request, ...) {
+#endif
+ assert(fd == 91);
+ va_list args;
+ va_start(args, request);
+ void *arg = va_arg(args, void *);
+ va_end(args);
+ int step = NONE;
+ switch ((unsigned int)request) {
+ case IOCTL_KGSL_DEVICE_GETPROPERTY: step = DEVICE; break;
+ case IOCTL_KGSL_DRAWCTXT_CREATE: step = CONTEXT; break;
+ case IOCTL_KGSL_SETPROPERTY: step = CONSTRAINT; break;
+ case IOCTL_KGSL_GPUMEM_ALLOC_ID: step = MEMORY; break;
+ case IOCTL_KGSL_GPUMEM_SYNC_CACHE: step = SYNC; break;
+ case IOCTL_KGSL_GPU_COMMAND: step = SUBMIT; break;
+ case IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID: step = WAIT; break;
+ }
+ if (step && atomic_load(&failure) == step) { errno = EACCES; return -1; }
+ switch ((unsigned int)request) {
+ case IOCTL_KGSL_DEVICE_GETPROPERTY: {
+ struct kgsl_device_getproperty *property = arg;
+ assert(property->type == KGSL_PROP_DEVICE_INFO);
+ ((struct kgsl_devinfo *)property->value)->chip_id = legacy_core ? 0x04030000 : 0x07030000;
+ break;
+ }
+ case IOCTL_KGSL_DRAWCTXT_CREATE: {
+ struct kgsl_drawctxt_create *context = arg;
+ assert(context->flags & KGSL_CONTEXT_PWR_CONSTRAINT);
+ context->drawctxt_id = 17;
+ atomic_fetch_add(&contexts, 1);
+ break;
+ }
+ case IOCTL_KGSL_SETPROPERTY: {
+ struct kgsl_device_getproperty *property = arg;
+ assert(property->type == KGSL_PROP_PWR_CONSTRAINT);
+ struct kgsl_device_constraint *constraint = property->value;
+ assert(constraint->context_id == 17 && constraint->type == KGSL_CONSTRAINT_PWRLEVEL);
+ assert(((struct kgsl_device_constraint_pwrlevel *)constraint->data)->level == KGSL_CONSTRAINT_PWR_MAX);
+ break;
+ }
+ case IOCTL_KGSL_GPUMEM_ALLOC_ID: {
+ struct kgsl_gpumem_alloc_id *memory = arg;
+ memory->id = 23; memory->gpuaddr = 0x100000; memory->mmapsize = sizeof(commands);
+ atomic_fetch_add(&memories, 1);
+ break;
+ }
+ case IOCTL_KGSL_GPUMEM_SYNC_CACHE:
+ assert(((struct kgsl_gpumem_sync_cache *)arg)->op == KGSL_GPUMEM_CACHE_CLEAN);
+ break;
+ case IOCTL_KGSL_GPU_COMMAND: {
+ struct kgsl_gpu_command *command = arg;
+ struct kgsl_command_object *object = (void *)(uintptr_t)command->cmdlist;
+ assert(command->context_id == 17 && command->numcmds == 1);
+ assert(command->flags & KGSL_CMDBATCH_PWR_CONSTRAINT);
+ assert(object->id == 23 && object->gpuaddr == 0x100000 && object->size == 8);
+ assert(commands[0] == (legacy_core ? 0xc0001000 : 0x70100001) && commands[1] == 0);
+ command->timestamp = atomic_fetch_add(&submissions, 1) + 1;
+ break;
+ }
+ case IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID:
+ atomic_fetch_add(&waits, 1);
+ if (atomic_load(&timeout_wait)) { errno = ETIMEDOUT; return -1; }
+ break;
+ case IOCTL_KGSL_DRAWCTXT_DESTROY:
+ assert(atomic_fetch_sub(&contexts, 1) == 1);
+ break;
+ case IOCTL_KGSL_GPUMEM_FREE_ID:
+ assert(atomic_fetch_sub(&memories, 1) == 1);
+ break;
+ default: assert(!"unexpected ioctl");
+ }
+ return 0;
+}
+
+int __real_pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *);
+int __wrap_pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start)(void *), void *arg) {
+ if (atomic_load(&failure) == THREAD) return EAGAIN;
+ return __real_pthread_create(thread, attr, start, arg);
+}
+
+static void assert_released(void) {
+ assert(!atomic_load(&descriptors) && !atomic_load(&contexts));
+ assert(!atomic_load(&memories) && !atomic_load(&mappings));
+}
+
+int main(void) {
+ assert(gpu_clock_pin_set(false));
+ assert_released();
+ legacy_core = true;
+ assert(gpu_clock_pin_set(true));
+ assert(gpu_clock_pin_set(false));
+ assert_released();
+ legacy_core = false;
+ for (int step = OPEN; step <= THREAD; ++step) {
+ atomic_store(&failure, step);
+ assert(!gpu_clock_pin_set(true));
+ assert(errno == (step == THREAD ? EAGAIN : EACCES));
+ assert_released();
+ }
+ atomic_store(&failure, NONE);
+ atomic_store(&submissions, 0);
+ assert(gpu_clock_pin_set(true));
+ assert(gpu_clock_pin_set(true));
+ for (int i = 0; i < 100 && atomic_load(&submissions) < 2; ++i) usleep(10000);
+ assert(atomic_load(&submissions) > 1);
+ assert(gpu_clock_pin_set(false));
+ assert(gpu_clock_pin_set(false));
+ assert_released();
+
+ atomic_store(&timeout_wait, true);
+ atomic_store(&submissions, 0);
+ atomic_store(&waits, 0);
+ assert(gpu_clock_pin_set(true));
+ for (int i = 0; i < 100 && atomic_load(&waits) < 2; ++i) usleep(10000);
+ assert(atomic_load(&waits) >= 2);
+ assert(atomic_load(&submissions) == 1);
+ assert(gpu_clock_pin_set(false));
+ assert_released();
+ atomic_store(&timeout_wait, false);
+
+ atomic_store(&failure, WAIT);
+ assert(gpu_clock_pin_set(true));
+ for (int i = 0; i < 100 && atomic_load(&descriptors); ++i) usleep(10000);
+ assert_released();
+ atomic_store(&failure, NONE);
+ assert(gpu_clock_pin_set(true));
+ assert(gpu_clock_pin_set(false));
+ assert_released();
+ puts("gpu clock pin: failure cleanup, renewal, bounded queue and restart passed");
+ return 0;
+}
diff --git a/tools/tests/test_gpu_clock_pin.py b/tools/tests/test_gpu_clock_pin.py
new file mode 100644
index 0000000000..f6f4668719
--- /dev/null
+++ b/tools/tests/test_gpu_clock_pin.py
@@ -0,0 +1,30 @@
+import pathlib
+import shutil
+import subprocess
+import sys
+import tempfile
+import unittest
+
+
+ROOT = pathlib.Path(__file__).resolve().parents[2]
+
+
+class GpuClockPinTest(unittest.TestCase):
+ @unittest.skipUnless(sys.platform.startswith('linux') and shutil.which('cc'), 'requires a Linux C compiler')
+ def test_constraint_lifecycle(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ directory = pathlib.Path(tmp)
+ (directory / 'android').mkdir()
+ (directory / 'android/log.h').write_text(
+ '#define ANDROID_LOG_WARN 5\n'
+ 'int __android_log_print(int, const char *, const char *, ...);\n')
+ binary = directory / 'gpu-clock-pin-test'
+ subprocess.run([
+ 'cc', '-std=c11', '-D_DEFAULT_SOURCE', '-D__user=', '-Wall', '-Wextra', '-Werror',
+ '-I', str(directory), '-pthread',
+ str(ROOT / 'tools/tests/test_gpu_clock_pin.c'),
+ str(ROOT / 'app/src/main/cpp/waylandcomp/src/gpu_clock_pin.c'),
+ '-Wl,--wrap=open,--wrap=close,--wrap=mmap,--wrap=munmap,--wrap=ioctl,--wrap=pthread_create',
+ '-o', str(binary),
+ ], check=True)
+ subprocess.run([str(binary)], check=True, timeout=10)
diff --git a/tools/tests/test_pack_downloads.py b/tools/tests/test_pack_downloads.py
new file mode 100644
index 0000000000..0b5eb60602
--- /dev/null
+++ b/tools/tests/test_pack_downloads.py
@@ -0,0 +1,125 @@
+import hashlib
+import http.server
+import json
+import os
+from pathlib import Path
+import shutil
+import socket
+import subprocess
+import tempfile
+import threading
+import unittest
+
+
+ROOT = Path(__file__).resolve().parents[2]
+FETCH = ROOT / 'tools/packs/fetch-verified.sh'
+
+
+class PackDownloadsTest(unittest.TestCase):
+ def setUp(self):
+ directory = tempfile.TemporaryDirectory()
+ self.addCleanup(directory.cleanup)
+ self.root = Path(directory.name)
+ self.cache = self.root / 'cache'
+ self.cache.mkdir()
+ self.destination = self.root / 'download'
+ self.remote = self.root / 'remote'
+ self.remote.write_bytes(b'verified input')
+ self.checksum = hashlib.sha256(self.remote.read_bytes()).hexdigest()
+ self.log = self.root / 'curl.log'
+ tool = self.root / 'bin/curl'
+ tool.parent.mkdir()
+ tool.write_text('#!/usr/bin/env python3\nimport json,os,shutil,sys\n'
+ 'args=sys.argv[1:]\n'
+ 'with open(os.environ["CURL_LOG"],"a") as f: f.write(json.dumps(args)+"\\n")\n'
+ 'shutil.copyfile(os.environ["REMOTE"],args[args.index("-o")+1])\n')
+ tool.chmod(0o755)
+ self.env = dict(os.environ, DROIDDECK_PACK_CACHE=str(self.cache), CURL_LOG=str(self.log),
+ REMOTE=str(self.remote), PATH=str(tool.parent) + os.pathsep + os.environ['PATH'])
+
+ def fetch(self, checksum=None, url='https://example.test/pinned', env=None):
+ return subprocess.run(['bash', str(FETCH), url, checksum or self.checksum, str(self.destination)],
+ env=env or self.env, capture_output=True, text=True)
+
+ def test_cold_download_then_warm_reuse_and_corruption_repair(self):
+ self.assertEqual(self.fetch().returncode, 0)
+ self.assertEqual(self.fetch().returncode, 0)
+ self.assertEqual(len(self.log.read_text().splitlines()), 1)
+ self.assertEqual(self.destination.read_bytes(), b'verified input')
+ (self.cache / self.checksum).write_bytes(b'corrupt')
+ self.assertEqual(self.fetch().returncode, 0)
+ self.assertEqual(len(self.log.read_text().splitlines()), 2)
+ self.assertEqual((self.cache / self.checksum).read_bytes(), b'verified input')
+
+ def test_directory_cache_entry_is_replaced_only_after_verification(self):
+ entry = self.cache / self.checksum
+ entry.mkdir()
+ sentinel = entry / 'old-entry'
+ sentinel.write_bytes(b'preserve until verified')
+ self.remote.write_bytes(b'tampered download')
+ self.assertNotEqual(self.fetch().returncode, 0)
+ self.assertEqual(sentinel.read_bytes(), b'preserve until verified')
+ self.assertFalse(self.destination.exists())
+ self.remote.write_bytes(b'verified input')
+ result = self.fetch()
+ self.assertEqual(result.returncode, 0, result.stderr)
+ self.assertTrue(entry.is_file())
+ self.assertEqual(entry.read_bytes(), b'verified input')
+ self.assertEqual(self.destination.read_bytes(), b'verified input')
+ self.assertEqual(list(self.cache.iterdir()), [entry])
+ self.assertEqual(self.fetch().returncode, 0)
+ self.assertEqual(len(self.log.read_text().splitlines()), 2)
+
+ def test_changed_pin_cannot_reuse_old_bytes(self):
+ self.assertEqual(self.fetch().returncode, 0)
+ self.remote.write_bytes(b'new approved input')
+ updated = hashlib.sha256(self.remote.read_bytes()).hexdigest()
+ self.assertEqual(self.fetch(updated).returncode, 0)
+ self.assertEqual(len(self.log.read_text().splitlines()), 2)
+ self.assertEqual(self.destination.read_bytes(), b'new approved input')
+
+ def test_bad_download_is_not_cached_or_written(self):
+ self.remote.write_bytes(b'tampered download')
+ self.assertNotEqual(self.fetch().returncode, 0)
+ self.assertFalse((self.cache / self.checksum).exists())
+ self.assertFalse(self.destination.exists())
+ self.assertEqual(list(self.cache.iterdir()), [])
+ arguments = json.loads(self.log.read_text())
+ self.assertIn('--retry-all-errors', arguments)
+ self.assertIn('--max-time', arguments)
+ self.assertIn('--retry-max-time', arguments)
+
+ def test_connection_reset_retries_then_verifies_real_download(self):
+ if not shutil.which('curl'):
+ self.skipTest('curl required for transport test')
+ content = self.remote.read_bytes()
+ attempts = []
+
+ class Handler(http.server.BaseHTTPRequestHandler):
+ def do_GET(self):
+ attempts.append(True)
+ if len(attempts) == 1:
+ self.connection.shutdown(socket.SHUT_RDWR)
+ self.connection.close()
+ return
+ self.send_response(200)
+ self.send_header('Content-Length', str(len(content)))
+ self.end_headers()
+ self.wfile.write(content)
+
+ def log_message(self, *args):
+ pass
+
+ server = http.server.ThreadingHTTPServer(('127.0.0.1', 0), Handler)
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
+ thread.start()
+ try:
+ env = dict(self.env, PATH=os.environ['PATH'])
+ result = self.fetch(url=f'http://127.0.0.1:{server.server_port}/input', env=env)
+ self.assertEqual(result.returncode, 0, result.stderr)
+ self.assertGreaterEqual(len(attempts), 2)
+ self.assertEqual(self.destination.read_bytes(), content)
+ finally:
+ server.shutdown()
+ server.server_close()
+ thread.join()
diff --git a/tools/tests/test_seed_redists.py b/tools/tests/test_seed_redists.py
index 042ab87d4e..bc71403f8b 100644
--- a/tools/tests/test_seed_redists.py
+++ b/tools/tests/test_seed_redists.py
@@ -45,6 +45,26 @@ VULKAN_SCRIPT = r'''"InstallScript"
'''
+UBISOFT_SCRIPT = r'''"installscript"
+{
+ "Run Process"
+ {
+ "Ubisoft Connect PC Client"
+ {
+ "process 1" "%INSTALLDIR%\\UbisoftConnectInstaller.exe"
+ "command 1" "/S"
+ }
+ "easyanticheat"
+ {
+ "HasRunKey" "HKEY_CURRENT_USER\\SOFTWARE\\Ubisoft\\WatchDogs2EAC"
+ "process 1" "%INSTALLDIR%\\EasyAntiCheat\\InstallWD2EAC.cmd"
+ "command 1" ""
+ }
+ }
+}
+'''
+
+
class SeedRedistsTest(unittest.TestCase):
def setUp(self):
self.tmp = Path(tempfile.mkdtemp())
@@ -353,5 +373,33 @@ class SeedRedistsTest(unittest.TestCase):
self.assertEqual(self.reg.read_text().count('"Vulkan111080"'), 2)
+ def ubisoft(self):
+ script = self.tmp / "legacycompat/evaluatorscript_447040.vdf"
+ script.parent.mkdir(parents=True)
+ script.write_text('"evaluatorscript"\n{\n\t"appid"\t\t"447040"\n\t"1"\n'
+ + "\n".join("\t" + line for line in UBISOFT_SCRIPT.splitlines()) + "\n}\n")
+ env = dict(os.environ, DROIDDECK_LIBRARIES="", DROIDDECK_SEED_SCRIPTS=str(script))
+ return subprocess.run(["bash", str(SCRIPT), str(self.steam)], env=env, capture_output=True, text=True, check=True)
+
+ def test_the_ubisoft_connect_installer_is_left_to_run(self):
+ self.ubisoft()
+ self.assertIn('"easyanticheat"=dword:00000001', self.user.read_text())
+ self.assertNotIn("Ubisoft Connect PC Client", self.reg.read_text())
+ self.assertNotIn("Ubisoft Connect PC Client", (self.reg.parent / ".droiddeck-redists").read_text())
+
+ def test_a_ubisoft_connect_marker_an_earlier_seeding_wrote_comes_out(self):
+ marker = "HKEY_LOCAL_MACHINE\\\\Software\\\\Valve\\\\Steam\\\\Apps\\\\447040\tUbisoft Connect PC Client"
+ self.reg.write_text(
+ "WINE REGISTRY Version 2\n"
+ "\n[Software\\\\Valve\\\\Steam\\\\Apps\\\\447040] 1791729070\n"
+ '"Ubisoft Connect PC Client"=dword:00000001\n'
+ "\n[Software\\\\Wow6432Node\\\\Valve\\\\Steam\\\\Apps\\\\447040] 1791729070\n"
+ '"Ubisoft Connect PC Client"=dword:00000001\n')
+ (self.reg.parent / ".droiddeck-redists").write_text(marker + "\n")
+ result = self.ubisoft()
+ self.assertNotIn("Ubisoft Connect PC Client", self.reg.read_text())
+ self.assertNotIn("Ubisoft Connect PC Client", (self.reg.parent / ".droiddeck-redists").read_text())
+ self.assertIn("Ubisoft Connect markers out", result.stdout)
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/tests/test_steam_compat_live.py b/tools/tests/test_steam_compat_live.py
index a86aab8644..af2d8cfb62 100644
--- a/tools/tests/test_steam_compat_live.py
+++ b/tools/tests/test_steam_compat_live.py
@@ -641,6 +641,114 @@ class ReconcileTest(unittest.TestCase):
self.assertEqual(page.mapping["10"], "GE-Proton9-1")
self.assertEqual(state["auto"], {"11": TOOL})
+ def games(self):
+ return json.loads((self.state / "games.json").read_text())["games"]
+
+ def write_games(self, games):
+ (self.state / "games.json").write_text(json.dumps({"version": 1, "games": games}))
+
+ def test_a_steam_pick_after_the_app_choice_is_kept_live(self):
+ page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
+ self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+ state = self.reconcile(page)
+ self.assertEqual(page.sets, [("10", TOOL_11)])
+ self.assertEqual(state["games_applied"], {"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+
+ page.sets.clear()
+ page.mapping["10"] = COMPAT["FEX_TOOL"]
+ state = self.reconcile(page)
+ self.assertEqual(page.sets, [])
+ self.assertEqual(page.mapping["10"], COMPAT["FEX_TOOL"])
+ self.assertEqual(self.games(), {})
+ self.assertEqual(state["games_applied"], {})
+
+ self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+ self.reconcile(page)
+ self.assertEqual(page.sets, [("10", TOOL_11)])
+
+ def test_a_steam_pick_of_our_proton_becomes_the_app_choice_live(self):
+ page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11])
+ self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+ self.reconcile(page)
+ page.sets.clear()
+ page.mapping["10"] = TOOL
+ state = self.reconcile(page)
+ self.assertEqual(page.sets, [])
+ self.assertEqual(self.games(), {"10": {"valve": True, "dir": "Proton Experimental (ARM64)"}})
+ self.assertEqual(state["games_applied"], self.games())
+
+ def test_use_the_default_applies_once_then_steam_picks_stand_live(self):
+ page = FakePage({"0": TOOL, "10": TOOL_11, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
+ self.write_games({"10": None})
+ self.reconcile(page)
+ self.assertEqual(page.sets, [("10", TOOL)])
+
+ page.sets.clear()
+ self.reconcile(page)
+ self.assertEqual(self.games(), {})
+ page.mapping["10"] = COMPAT["FEX_TOOL"]
+ self.reconcile(page)
+ self.assertEqual(page.sets, [])
+ self.assertEqual(page.mapping["10"], COMPAT["FEX_TOOL"])
+
+ def test_choices_an_earlier_build_applied_give_way_to_steam_picks_live(self):
+ (self.state / "state.json").write_text(json.dumps({"default": TOOL, "auto": {"11": TOOL}, "tools": []}))
+ self.write_games({"10": None, "11": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+ page = FakePage({"0": TOOL, "10": COMPAT["FEX_TOOL"], "11": "steamlinuxruntime_sniper"},
+ [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
+ self.reconcile(page)
+ self.assertEqual(page.sets, [])
+ self.assertEqual(self.games(), {})
+
+ def test_an_app_choice_written_during_a_sync_is_not_overwritten(self):
+ self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+ requests, text = COMPAT["read_game_requests"]()
+ self.write_games({"10": {"valve": True, "dir": "Proton Experimental (ARM64)"}})
+ self.assertFalse(COMPAT["write_game_requests"]({}, text))
+ self.assertEqual(self.games(), {"10": {"valve": True, "dir": "Proton Experimental (ARM64)"}})
+
+ def test_an_app_the_client_briefly_refuses_keeps_its_applied_choice_live(self):
+ page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
+ self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+ self.reconcile(page)
+ page.refused = {"10"}
+ state = self.reconcile(page)
+ self.assertEqual(state["games_applied"], {"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+ page.refused = set()
+ page.sets.clear()
+ page.mapping["10"] = COMPAT["FEX_TOOL"]
+ self.reconcile(page)
+ self.assertEqual(page.sets, [])
+ self.assertEqual(page.mapping["10"], COMPAT["FEX_TOOL"])
+
+ def test_an_app_rewriting_its_choices_during_both_tries_applies_none_of_them_live(self):
+ page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
+ self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+ self.reconcile(page)
+ page.sets.clear()
+ page.mapping["10"] = COMPAT["FEX_TOOL"]
+ self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}, "11": None})
+ with mock.patch.dict(COMPAT["settled_game_requests"].__globals__, write_game_requests=lambda *_: False):
+ state = self.reconcile(page)
+ self.assertEqual(page.sets, [])
+ self.assertEqual(state["games_applied"], {"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+
+ def test_a_steam_pick_is_kept_at_the_next_start(self):
+ config = self.steam / "config/config.vdf"
+ config.parent.mkdir(parents=True)
+ vdf = '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }'
+ entry = '"%s" { "name" "%s" "config" "" "priority" "250" }'
+ catalog = COMPAT["tool_catalog"](str(self.steam))
+ self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
+ config.write_text(vdf % (entry % ("0", TOOL) + entry % ("10", TOOL)))
+ with mock.patch.dict(COMPAT["register_default"].__globals__, steam_running=lambda: False):
+ COMPAT["register_default"](str(config), ["10"], catalog=catalog, directory=str(self.state), settle=True)
+ self.assertIn(entry % ("10", TOOL_11), " ".join(config.read_text().split()))
+ config.write_text(vdf % (entry % ("0", TOOL) + entry % ("10", COMPAT["FEX_TOOL"])))
+ COMPAT["register_default"](str(config), ["10"], catalog=catalog, directory=str(self.state), settle=True)
+ self.assertIn(entry % ("10", COMPAT["FEX_TOOL"]), " ".join(config.read_text().split()))
+ self.assertEqual(self.games(), {})
+
def test_file_mode_defers_to_the_live_helper(self):
(self.state / "live.pid").write_text("%d\n" % os.getpid())
self.assertTrue(COMPAT["live_helper_running"]())
diff --git a/tools/tests/test_steam_install.py b/tools/tests/test_steam_install.py
index 256e711332..6a02bcb0ae 100644
--- a/tools/tests/test_steam_install.py
+++ b/tools/tests/test_steam_install.py
@@ -26,25 +26,48 @@ class SteamInstallTest(unittest.TestCase):
self.bin = self.root / 'bin'
self.bin.mkdir()
curl = self.bin / 'curl'
- curl.write_text('''#!/bin/bash
-set -eu
-url=""
-out=""
-while [ $# -gt 0 ]; do
- case $1 in
- -o) out=$2; shift 2 ;;
- --connect-timeout|--max-time|--speed-limit|--speed-time|--retry|--retry-delay) shift 2 ;;
- -*) shift ;;
- *) url=$1; shift ;;
- esac
-done
-printf '%s\\n' "$url" >> "$TEST_REQUESTS"
-if [ -n "${TEST_FAIL_HOST:-}" ]; then
- case $url in *"$TEST_FAIL_HOST"*) exit 22 ;; esac
-fi
-cp "$TEST_CDN/${url##*/}" "$out"
+ curl.write_text('''#!/usr/bin/env python3
+import os, sys
+args = sys.argv[1:]
+url = next(a for a in args if a.startswith('https://'))
+out = args[args.index('-o') + 1]
+name = url.rsplit('/', 1)[1]
+offset = os.path.getsize(out) if '-C' in args and os.path.exists(out) else 0
+with open(os.environ['TEST_REQUESTS'], 'a') as log:
+ log.write(url + '\\n')
+with open(os.environ['TEST_REQUESTS'] + '.offsets', 'a') as log:
+ log.write(f'{name} {offset}\\n')
+def done(status, code='200'):
+ if '-w' in args:
+ sys.stdout.write(code)
+ sys.exit(status)
+host_fail = os.environ.get('TEST_FAIL_HOST')
+if host_fail and host_fail in url:
+ done(22, '000')
+action = []
+plan = os.environ.get('TEST_PLAN')
+if plan and os.path.exists(plan):
+ lines = open(plan).read().splitlines()
+ for n, line in enumerate(lines):
+ if line.split()[0] == name:
+ action = line.split()[1:]
+ del lines[n]
+ open(plan, 'w').write(''.join(l + '\\n' for l in lines))
+ break
+if action[:1] == ['fail']:
+ done(int(action[1]), '000')
+if action[:1] == ['http']:
+ done(22, action[1])
+if action[:1] == ['norange'] and offset:
+ done(33)
+data = open(os.path.join(os.environ['TEST_CDN'], name), 'rb').read()
+end = int(action[1]) if action[:1] == ['cut'] else len(data)
+with open(out, 'ab' if offset else 'wb') as target:
+ target.write(data[offset:end])
+done(28 if end < len(data) else 0)
''')
curl.chmod(0o755)
+ self.plan = self.root / 'plan'
if shutil.which('sha256sum') is None:
sha = self.bin / 'sha256sum'
sha.write_text('#!/bin/bash\nexec shasum -a 256 "$@"\n')
@@ -55,7 +78,8 @@ cp "$TEST_CDN/${url##*/}" "$out"
sha1.chmod(0o755)
self.env = dict(os.environ, HOME=str(self.home), XDG_DATA_HOME=str(self.data),
PATH=str(self.bin) + os.pathsep + os.environ['PATH'],
- TEST_CDN=str(self.cdn), TEST_REQUESTS=str(self.requests))
+ TEST_CDN=str(self.cdn), TEST_REQUESTS=str(self.requests),
+ TEST_PLAN=str(self.plan), BL_STEAM_RETRY_DELAYS='0 0 0')
for channel in ('steamdeck_publicbeta', 'steamdeck_stable'):
archive = self.cdn / (channel + '.zip')
with zipfile.ZipFile(archive, 'w') as package:
@@ -255,6 +279,143 @@ cp "$TEST_CDN/${url##*/}" "$out"
self.assertEqual(0, self.install().returncode)
self.assertFalse(self.requests.exists())
+ def publish(self, **parts):
+ """The CDN's client as these parts (block name -> byte count of incompressible content),
+ listed with sizes as Valve's manifest lists them."""
+ files = {}
+ blocks = ''
+ for block, length in parts.items():
+ archive = self.cdn / f'{block}.zip.{hashlib.sha1(block.encode()).hexdigest()}'
+ with zipfile.ZipFile(archive, 'w', zipfile.ZIP_STORED) as package:
+ package.writestr(f'parts/{block}', os.urandom(length))
+ if block.endswith('_linuxarm64_linuxarm64'):
+ package.writestr('steamrtarm64/steam', 'steamdeck_publicbeta')
+ data = archive.read_bytes()
+ files[block] = archive.name
+ blocks += (f'\t"{block}"\n\t{{\n\t\t"file"\t\t"{archive.name}"\n\t\t"size"\t\t"{len(data)}"\n'
+ f'\t\t"sha2"\t\t"{hashlib.sha256(data).hexdigest()}"\n\t}}\n')
+ (self.cdn / 'steam_client_steamdeck_publicbeta_linuxarm64').write_text(
+ '"linuxarm64"\n{\n\t"version"\t\t"123456"\n' + blocks + '}\n')
+ return files
+
+ def two_parts(self):
+ return self.publish(a_all=1_200_000, client_linuxarm64_linuxarm64=1_300_000)
+
+ def plan_for(self, name, *actions):
+ with self.plan.open('a') as plan:
+ plan.writelines(f'{name} {action}\n' for action in actions)
+
+ def offsets(self, name):
+ log = Path(str(self.requests) + '.offsets')
+ return [int(line.split()[1]) for line in log.read_text().splitlines() if line.split()[0] == name]
+
+ def requested(self):
+ return [line.rsplit('/', 1)[1] for line in self.requests.read_text().splitlines()]
+
+ @property
+ def download(self):
+ return self.steam / 'package/droiddeck-download'
+
+ def test_progress_is_counted_in_megabytes_across_parts(self):
+ self.two_parts()
+ result = self.install()
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertIn('downloading Steam: a_all (1/2), 0 of 2 MB\n', result.stdout)
+ self.assertIn('downloading Steam: client_linuxarm64_linuxarm64 (2/2), 1 of 2 MB\n', result.stdout)
+ self.assertTrue((self.steam / 'parts/a_all').is_file())
+ self.assertFalse(self.download.exists())
+
+ def test_a_dropped_connection_resumes_from_what_arrived(self):
+ files = self.two_parts()
+ client = files['client_linuxarm64_linuxarm64']
+ self.plan_for(client, 'cut 500000')
+ result = self.install()
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertEqual([0, 500000], self.offsets(client))
+ self.assertIn('interrupted (curl exit 28), trying again in 0 s', result.stdout)
+ self.assertEqual('123456\n', (self.steam / 'package/droiddeck-installed').read_text())
+
+ def test_a_failed_session_keeps_what_it_finished_and_fetched(self):
+ files = self.two_parts()
+ client = files['client_linuxarm64_linuxarm64']
+ self.plan_for(client, 'cut 400000', *['fail 6'] * 12)
+ result = self.install()
+ self.assertNotEqual(0, result.returncode)
+ self.assertIn('could not download client_linuxarm64_linuxarm64 (curl exit 6)', result.stderr)
+ self.assertFalse((self.steam / 'package/droiddeck-installed').exists())
+ self.assertTrue((self.download / (files['a_all'] + '.unpacked')).is_file())
+ self.assertFalse((self.download / files['a_all']).exists())
+ self.assertEqual(400000, (self.download / client).stat().st_size)
+ self.requests.unlink()
+ Path(str(self.requests) + '.offsets').unlink()
+ self.assertEqual(0, self.install().returncode)
+ self.assertEqual(['steam_client_steamdeck_publicbeta_linuxarm64', client], self.requested())
+ self.assertEqual([400000], self.offsets(client))
+ self.assertFalse(self.download.exists())
+
+ def test_a_server_that_will_not_resume_starts_the_part_over(self):
+ files = self.two_parts()
+ client = files['client_linuxarm64_linuxarm64']
+ self.plan_for(client, 'cut 400000', 'norange')
+ result = self.install()
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertEqual([0, 400000, 0], self.offsets(client))
+
+ def test_a_missing_part_hands_over_to_the_next_cdn_at_once(self):
+ files = self.two_parts()
+ client = files['client_linuxarm64_linuxarm64']
+ self.plan_for(client, 'http 404')
+ result = self.install()
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertEqual(['https://client-update.steamstatic.com/' + client,
+ 'https://client-update.akamai.steamstatic.com/' + client],
+ [line for line in self.requests.read_text().splitlines() if line.endswith(client)])
+ self.assertIn('HTTP 404 from https://client-update.steamstatic.com', result.stderr)
+ self.assertNotIn('trying again', result.stdout)
+
+ def test_a_server_error_is_retried_on_the_same_cdn(self):
+ files = self.two_parts()
+ client = files['client_linuxarm64_linuxarm64']
+ self.plan_for(client, 'http 503')
+ result = self.install()
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertEqual(['https://client-update.steamstatic.com/' + client] * 2,
+ [line for line in self.requests.read_text().splitlines() if line.endswith(client)])
+ self.assertIn('interrupted (curl exit 22), trying again in 0 s', result.stdout)
+
+ def test_bytes_that_do_not_check_out_are_fetched_again(self):
+ files = self.two_parts()
+ client = files['client_linuxarm64_linuxarm64']
+ self.download.mkdir(parents=True)
+ (self.download / client).write_bytes(b'x' * (self.cdn / client).stat().st_size)
+ result = self.install()
+ self.assertEqual(0, result.returncode, result.stderr)
+ self.assertEqual([0], self.offsets(client))
+
+ def test_parts_left_for_another_client_version_are_dropped(self):
+ files = self.two_parts()
+ self.download.mkdir(parents=True)
+ (self.download / 'a_all.zip.0123').write_bytes(b'older')
+ (self.download / 'b_all.zip.4567.unpacked').write_bytes(b'')
+ self.plan_for(files['client_linuxarm64_linuxarm64'], *['fail 7'] * 12)
+ self.assertNotEqual(0, self.install().returncode)
+ self.assertEqual([files['a_all'] + '.unpacked'], sorted(p.name for p in self.download.iterdir()))
+
+ def test_a_repair_unpacks_every_part_again_once(self):
+ files = self.two_parts()
+ self.assertEqual(0, self.install().returncode)
+ (self.home / '.bl-steam-repair').write_text('1\n')
+ self.requests.unlink()
+ self.plan_for(files['client_linuxarm64_linuxarm64'], *['fail 7'] * 12)
+ self.assertNotEqual(0, self.install().returncode)
+ self.assertIn(files['a_all'], self.requested())
+ self.requests.unlink()
+ self.assertEqual(0, self.install().returncode)
+ self.assertEqual(['steam_client_steamdeck_publicbeta_linuxarm64', files['client_linuxarm64_linuxarm64']],
+ self.requested())
+ self.assertFalse((self.home / '.bl-steam-repair').exists())
+ self.assertFalse(self.download.exists())
+
if __name__ == '__main__':
unittest.main()
diff --git a/tools/tests/test_steam_libraries.py b/tools/tests/test_steam_libraries.py
index 4f416a8401..95ae20c24a 100644
--- a/tools/tests/test_steam_libraries.py
+++ b/tools/tests/test_steam_libraries.py
@@ -153,6 +153,8 @@ class DesktopGamesTest(unittest.TestCase):
steam = root / "Steam"
manifest(steam / "steamapps", 40, name="Game")
manifest(steam / "steamapps", 1628350, name="Steam Linux Runtime 3.0 (sniper)", installdir="SteamLinuxRuntime_sniper")
+ manifest(steam / "steamapps", 1826330, name="Proton EasyAntiCheat Runtime", installdir="Proton EasyAntiCheat Runtime")
+ manifest(steam / "steamapps", 1161040, name="Proton BattlEye Runtime", installdir="Proton BattlEye Runtime")
manifest(steam / "steamapps", 5000, name="Some Proton", installdir="Some Proton")
(steam / "steamapps/common/Some Proton").mkdir(parents=True)
(steam / "steamapps/common/Some Proton/toolmanifest.vdf").write_text('"manifest"\n{\n}\n')
diff --git a/tools/tests/test_steam_shortcuts.py b/tools/tests/test_steam_shortcuts.py
index 60a2998a60..a927d4db07 100644
--- a/tools/tests/test_steam_shortcuts.py
+++ b/tools/tests/test_steam_shortcuts.py
@@ -203,6 +203,30 @@ class ShortcutsTest(unittest.TestCase):
self.assertEqual('-vulkan', steam['LaunchOptions'])
self.assertEqual('Mine', steam['AppName'])
+ def users(self, *blocks):
+ body = ''.join('\t"%d"\n\t{\n%s\t}\n' % (76561197960265728 + acct, ''.join('\t\t"%s"\t\t"%s"\n' % kv for kv in keys.items()))
+ for acct, keys in blocks)
+ (self.steam / 'config').mkdir(exist_ok=True)
+ (self.steam / 'config/loginusers.vdf').write_text('"users"\n{\n%s}\n' % body)
+ (self.steam / 'userdata/456/config').mkdir(parents=True, exist_ok=True)
+
+ def test_the_account_marked_most_recent_is_used(self):
+ self.users((123, dict(MostRecent='1', AutoLogin='0', timestamp='100')), (456, dict(MostRecent='0', AutoLogin='1', timestamp='200')))
+ self.assertEqual(str(self.steam / 'userdata/123'), shortcuts.account_dir(str(self.steam)))
+
+ def test_without_most_recent_the_account_that_signs_in_is_used(self):
+ self.users((123, dict(AutoLogin='1', timestamp='100')), (456, dict(AutoLogin='0', timestamp='200')))
+ self.assertEqual(str(self.steam / 'userdata/123'), shortcuts.account_dir(str(self.steam)))
+ self.assertIn(APPID, self.run_writer(self.game()))
+
+ def test_without_either_mark_the_account_used_last_is_used(self):
+ self.users((456, dict(AutoLogin='0', timestamp='100')), (123, dict(AutoLogin='0', timestamp='200')))
+ self.assertEqual(str(self.steam / 'userdata/123'), shortcuts.account_dir(str(self.steam)))
+
+ def test_two_accounts_without_any_mark_write_nothing(self):
+ self.users((123, dict(AccountName='a')), (456, dict(AccountName='b')))
+ self.assertIsNone(shortcuts.account_dir(str(self.steam)))
+
def test_an_older_record_without_launch_options_still_takes_the_apps(self):
self.run_writer(self.game())
record = self.record()
diff --git a/tools/xbox/build-local.sh b/tools/xbox/build-local.sh
index 6a3eb90ce5..979c95b12b 100755
--- a/tools/xbox/build-local.sh
+++ b/tools/xbox/build-local.sh
@@ -1,14 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
repo=$(cd "$(dirname "$0")/../.." && pwd)
-cache=${DROIDDECK_XBOX_CACHE:-"${HOME}/.cache/droiddeck-xbox-build"}
-mkdir -p "$cache"
-docker run --rm --platform linux/arm64 -v "$repo:/src" -v "$cache:/work" -w /src \
- -e CARGO_HOME=/work/cargo -e RUSTUP_HOME=/work/rustup -e XBOX_BUILD_DIR=/work/build ubuntu:24.04 bash -lc '
- set -euo pipefail
- apt-get update -qq
- DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
- build-essential pkg-config libssl-dev protobuf-compiler cmake curl git ca-certificates xz-utils python3 >/dev/null
+build='
export PATH=/work/cargo/bin:$PATH
if ! command -v rustup >/dev/null; then
version=$(python3 -c '\''import json;print(json.load(open("tools/xbox/backend.lock.json"))["rust"])'\'')
@@ -16,3 +9,23 @@ docker run --rm --platform linux/arm64 -v "$repo:/src" -v "$cache:/work" -w /src
fi
bash tools/xbox/build.sh
'
+if [[ $(uname -m) = x86_64 ]]; then
+ cache=${DROIDDECK_XBOX_CACHE:-"${HOME}/.cache/droiddeck-xbox-cross"}
+ platform=linux/amd64
+ image=droiddeck-xbox-cross:$(shasum -a 256 "$repo/tools/xbox/cross.Dockerfile" | cut -c1-12)
+ docker image inspect "$image" >/dev/null 2>&1 \
+ || docker build --platform "$platform" -t "$image" -f "$repo/tools/xbox/cross.Dockerfile" "$repo/tools/xbox"
+else
+ cache=${DROIDDECK_XBOX_CACHE:-"${HOME}/.cache/droiddeck-xbox-build"}
+ platform=linux/arm64
+ image=ubuntu:24.04
+ build='
+ apt-get update -qq
+ DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
+ build-essential pkg-config libssl-dev protobuf-compiler cmake curl git ca-certificates xz-utils python3 >/dev/null
+'"$build"
+fi
+mkdir -p "$cache"
+docker run --rm --platform "$platform" -v "$repo:/src" -v "$cache:/work" -w /src \
+ -e CARGO_HOME=/work/cargo -e RUSTUP_HOME=/work/rustup -e XBOX_BUILD_DIR=/work/build "$image" \
+ bash -lc "set -euo pipefail$build"
diff --git a/tools/xbox/build.sh b/tools/xbox/build.sh
index f5598aee19..99bee8c76b 100755
--- a/tools/xbox/build.sh
+++ b/tools/xbox/build.sh
@@ -13,7 +13,7 @@ export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=${CARGO_TARGET_AARCH64_UNKN
if [[ $(uname -m) = aarch64 ]]; then export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=cc; fi
cd "$source_dir"
cargo build --locked --release --no-default-features --target aarch64-unknown-linux-gnu -p xodus-cli -p xodus-service
-if [[ $(uname -m) = aarch64 ]]; then
+if [[ $(uname -m) = aarch64 || -n ${CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER:-} ]]; then
cargo test --locked --release --no-default-features --target aarch64-unknown-linux-gnu -p xodus-cli
cargo test --locked --release --no-default-features --target aarch64-unknown-linux-gnu -p xodus credential_
cargo test --locked --release --no-default-features --target aarch64-unknown-linux-gnu -p msixvc streaming_
diff --git a/tools/xbox/cross.Dockerfile b/tools/xbox/cross.Dockerfile
new file mode 100644
index 0000000000..665dd17d71
--- /dev/null
+++ b/tools/xbox/cross.Dockerfile
@@ -0,0 +1,28 @@
+FROM ubuntu:24.04
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+RUN dpkg --add-architecture arm64 \
+ && sed -i '/^Types:/a Architectures: amd64' /etc/apt/sources.list.d/ubuntu.sources \
+ && printf '%s\n' \
+ 'Types: deb' \
+ 'URIs: http://ports.ubuntu.com/ubuntu-ports/' \
+ 'Suites: noble noble-updates noble-security' \
+ 'Components: main universe restricted multiverse' \
+ 'Architectures: arm64' \
+ 'Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg' \
+ > /etc/apt/sources.list.d/ubuntu-ports.sources \
+ && apt-get update -qq \
+ && apt-get install -y -qq --no-install-recommends \
+ build-essential pkg-config protobuf-compiler cmake curl git ca-certificates xz-utils python3 \
+ gcc-aarch64-linux-gnu g++-aarch64-linux-gnu qemu-user \
+ libssl-dev:arm64 libstdc++6:arm64 \
+ && rm -rf /var/lib/apt/lists/*
+
+ENV CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
+ CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \
+ AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar \
+ PKG_CONFIG_ALLOW_CROSS=1 \
+ PKG_CONFIG_LIBDIR_aarch64_unknown_linux_gnu=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig \
+ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
+ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER=qemu-aarch64