diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aacad45f03..ebfd545ca2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -601,7 +601,7 @@ jobs: - name: Install Python test dependencies run: | sudo apt-get update -qq - sudo apt-get install -y -qq python3-yaml + sudo apt-get install -y -qq python3-yaml gcc-aarch64-linux-gnu qemu-user - name: Steam import and game environment tests run: python3 -m unittest discover -s tools/tests -p 'test_*.py' diff --git a/README.md b/README.md index 97043973e1..fb86fa6534 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Compatibility and performance vary by device; hardware validation is limited. De ## Credits and licence -GPL-3.0. Runtime, shim, input, and controller work build on WinNative and Bannerlator (maxjivi05). Epic Games and GOG support build on [Phobos’s](https://github.com/phobos665) adaptation of [Legendary](https://github.com/legendary-gl/legendary) and [gogdl](https://github.com/Heroic-Games-Launcher/heroic-gogdl), respectively. The registry entries a GOG game's install script (`goggame-.script`) sets are read the way [Heroic Games Launcher](https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher)'s GOG setup (GPL-3.0) reads them. LSFG frame generation is from the work of Camille LaVey and the [Eden](https://eden-emu.dev) emulator project, following [lsfg-vk](https://github.com/PancakeTAS/lsfg-vk), ported to WinNative and DroidDeck by [@maxjivi05](https://github.com/maxjivi05); it needs your own copy of [Lossless Scaling](https://store.steampowered.com/app/993090/) and ships none of its shaders. x86 AppImages, and any whose own runtime cannot unpack them, are unpacked with [uruntime](https://github.com/VHSgunzo/uruntime) by VHSgunzo (MIT), shipped unmodified with its licence, which also starts the arm64 emulator AppImages whose own runtime cannot run its extractor on Android. The Steam client's audio goes through [@The412Banner](https://github.com/The412Banner)'s [DirectAudio](https://github.com/The412Banner/directaudio) PulseAudio sink (LGPL-2.1-or-later), built from `tools/directaudio/sink` with its request size kept to its ring so clients are not asked to queue 100 ms ahead. mmap ring-buffer controller input was developed by ribbit384 ([WinNative #345](https://github.com/WinNative-Emu/WinNative/pull/345)). Why the x86-64 Steam client refused the arm64 client's sign-in was checked by reading Steam's saved token with the `ConnectCache` format from [deadlock-api-ingest](https://github.com/deadlock-api/deadlock-api-ingest). x86 programs that link OpenSSL 3 under FEX use the copy in the [Steam Linux Runtime 4.0](https://gitlab.steamos.cloud/steamrt/steamrt) platform. Hooks written with `WriteProcessMemory` into code [FEX](https://github.com/FEX-Emu/FEX) has translated go through `/proc//mem` again when the kernel refuses `process_vm_writev`, as [Wine](https://gitlab.winehq.org/wine/wine)'s `server/ptrace.c` wrote them before Wine 11. x86 Linux games under FEX get the same `/etc/asound.conf` that [pressure-vessel](https://gitlab.steamos.cloud/steamrt/steam-runtime-tools) writes into the Steam Linux Runtime, so ALSA plays through PulseAudio. Games render with [Mesa](https://gitlab.freedesktop.org/mesa/mesa) Turnip's own per-render-pass choice between tile memory and system memory, while the Steam client keeps `TU_DEBUG=sysmem`; [FEX](https://github.com/FEX-Emu/FEX)'s code disk cache was checked in its source and is already on through Proton. See [LICENSE](LICENSE). Steam and Proton belong to Valve Corporation; this project is not affiliated with Valve. +GPL-3.0. Runtime, shim, input, and controller work build on WinNative and Bannerlator (maxjivi05). Epic Games and GOG support build on [Phobos’s](https://github.com/phobos665) adaptation of [Legendary](https://github.com/legendary-gl/legendary) and [gogdl](https://github.com/Heroic-Games-Launcher/heroic-gogdl), respectively. The registry entries a GOG game's install script (`goggame-.script`) sets are read the way [Heroic Games Launcher](https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher)'s GOG setup (GPL-3.0) reads them. LSFG frame generation is from the work of Camille LaVey and the [Eden](https://eden-emu.dev) emulator project, following [lsfg-vk](https://github.com/PancakeTAS/lsfg-vk), ported to WinNative and DroidDeck by [@maxjivi05](https://github.com/maxjivi05); it needs your own copy of [Lossless Scaling](https://store.steampowered.com/app/993090/) and ships none of its shaders. x86 AppImages, and any whose own runtime cannot unpack them, are unpacked with [uruntime](https://github.com/VHSgunzo/uruntime) by VHSgunzo (MIT), shipped unmodified with its licence, which also starts the arm64 emulator AppImages whose own runtime cannot run its extractor on Android. The Steam client's audio goes through [@The412Banner](https://github.com/The412Banner)'s [DirectAudio](https://github.com/The412Banner/directaudio) PulseAudio sink (LGPL-2.1-or-later), built from `tools/directaudio/sink` with its request size kept to its ring so clients are not asked to queue 100 ms ahead. mmap ring-buffer controller input was developed by ribbit384 ([WinNative #345](https://github.com/WinNative-Emu/WinNative/pull/345)). Why the x86-64 Steam client refused the arm64 client's sign-in was checked by reading Steam's saved token with the `ConnectCache` format from [deadlock-api-ingest](https://github.com/deadlock-api/deadlock-api-ingest). x86 programs that link OpenSSL 3 under FEX use the copy in the [Steam Linux Runtime 4.0](https://gitlab.steamos.cloud/steamrt/steamrt) platform. Hooks written with `WriteProcessMemory` into code [FEX](https://github.com/FEX-Emu/FEX) has translated go through `/proc//mem` again when the kernel refuses `process_vm_writev`, as [Wine](https://gitlab.winehq.org/wine/wine)'s `server/ptrace.c` wrote them before Wine 11. x86 Linux games under FEX get the same `/etc/asound.conf` that [pressure-vessel](https://gitlab.steamos.cloud/steamrt/steam-runtime-tools) writes into the Steam Linux Runtime, so ALSA plays through PulseAudio. Games render with [Mesa](https://gitlab.freedesktop.org/mesa/mesa) Turnip's own per-render-pass choice between tile memory and system memory, while the Steam client keeps `TU_DEBUG=sysmem`; [FEX](https://github.com/FEX-Emu/FEX)'s code disk cache was checked in its source and is already on through Proton. The proot fast path picks the guest name of a host file bound under several names in the order [PRoot](https://github.com/proot-me/proot)'s `path/binding.c` (GPL-2.0-or-later) sorts its bindings, so links and `/proc/self/fd` read back as they do through proot. The session's [PipeWire](https://gitlab.freedesktop.org/pipewire/pipewire) (MIT) opens its sockets with the per-socket access settings documented in its `module-access.c`, and [WirePlumber](https://gitlab.freedesktop.org/pipewire/wireplumber) (MIT) keeps those clients at full permissions through its `access.rules`. Wine write watches use the userfaultfd support in [Proton](https://github.com/ValveSoftware/wine)'s `dlls/ntdll/unix/virtual.c` (LGPL-2.1-or-later): libblsession gives it the arm64 syscall number and answers its `PAGEMAP_SCAN` from `/proc/self/pagemap` where Android refuses the ioctl. Wine on arm64 sets a thread's full context by raising `SIGUSR2` from `syscall_dispatcher_return_slowpath` in [Wine](https://gitlab.winehq.org/wine/wine)'s `dlls/ntdll/unix/signal_arm64.c` (LGPL-2.1-or-later); libblsession runs that handler in place on a frame laid out as the [Linux](https://github.com/torvalds/linux) kernel's `arch/arm64/kernel/signal.c` builds it and returns through `rt_sigreturn`, so proot does not stop the thread for it. Wine's process list reads each process's memory counters from `/proc//status` in `fill_vm_counters` ([Wine](https://gitlab.winehq.org/wine/wine) `dlls/ntdll/unix/process.c`, LGPL-2.1-or-later), so libblsession gives those reads the kernel's file instead of a copy with `TracerPid` cleared. See [LICENSE](LICENSE). Steam and Proton belong to Valve Corporation; this project is not affiliated with Valve. XR glasses support builds on WinNative's VITURE glasses work. VITURE protocol details were checked against [XRLinuxDriver](https://github.com/wheaney/XRLinuxDriver) by [@wheaney](https://github.com/wheaney), including the VITURE protocol header it ships, [ar-drivers-rs](https://github.com/badicsalex/ar-drivers-rs) by [@badicsalex](https://github.com/badicsalex) and the [go-macos/iokit VITURE package](https://pkg.go.dev/github.com/go-macos/iokit/viture); the optional VITURE SDK belongs to VITURE and is not included. RayNeo support adapts [@informalTechCode](https://github.com/informalTechCode)'s [RayNeo-Air-Series-3DoF-Scaffold](https://github.com/informalTechCode/RayNeo-Air-Series-3DoF-Scaffold) (Apache-2.0) and references [@verncat](https://github.com/verncat)'s [RayNeo-Air-3S-Pro-OpenVR](https://github.com/verncat/RayNeo-Air-3S-Pro-OpenVR) (MIT) and [Monado](https://gitlab.freedesktop.org/monado/monado) (BSL-1.0); see [docs/third-party/rayneo](docs/third-party/rayneo/README.md). XREAL 1S support references [XRLinuxDriver](https://github.com/wheaney/XRLinuxDriver) and [xrealOneDeviceKit](https://github.com/wheaney/xrealOneDeviceKit) by @wheaney, [xreal_one_driver](https://github.com/rohitsangwan01/xreal_one_driver) by [@rohitsangwan01](https://github.com/rohitsangwan01) (MIT) and [xr-tools](https://github.com/0xcaff/xr-tools) by [@0xcaff](https://github.com/0xcaff). Rokid support follows the Rokid protocol notes in [ar-drivers-rs](https://github.com/badicsalex/ar-drivers-rs) and @badicsalex's [Void Computing write-ups](https://voidcomputing.hu/blog/worse-better-prettier/), and [Monado](https://gitlab.freedesktop.org/monado/monado)'s Rokid driver. The REDMAGIC glasses-display findings draw on [@mekhontsev](https://github.com/mekhontsev)'s [MagicDesk investigation](https://github.com/mekhontsev/magicdesk/blob/main/docs/xr-resolution-fix.md) and [@Coding-BR](https://github.com/Coding-BR)'s [decompiled Nubia kernel](https://github.com/Coding-BR/android_kernel_nubia_sm8850_qwjujube). VITURE, RayNeo, XREAL, Rokid and REDMAGIC are trademarks of their owners; this project is not affiliated with them. diff --git a/app/build.gradle b/app/build.gradle index c889af5882..e81b92711c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -122,8 +122,8 @@ android { applicationId "com.droiddeck.launcher" minSdkVersion 26 targetSdkVersion 28 - versionCode 14 - versionName "0.5.0" + versionCode 15 + versionName "0.6.0" buildConfigField "String", "BUILD_LABEL", "\"${escapedBuildLabel}\"" buildConfigField "String", "SOURCE_COMMIT", "\"${sourceCommit}\"" buildConfigField "int", "PR_NUMBER", "${prNumber}" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5439940930..fcd9b2e11b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -61,7 +61,7 @@ @@ -84,8 +84,8 @@ @@ -97,7 +97,7 @@ diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt similarity index 99% rename from app/src/main/java/com/droiddeck/launcher/MainActivity.kt rename to app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index abc1eee8f0..1081cb8948 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -80,7 +80,7 @@ import com.droiddeck.launcher.session.GameStorage import com.droiddeck.launcher.input.SecondScreenDisplay import com.droiddeck.launcher.input.SecondScreenDisplays -class MainActivity : ComponentActivity() { +class FrontEndActivity : ComponentActivity() { override fun attachBaseContext(newBase: android.content.Context) { super.attachBaseContext(newBase) com.droiddeck.launcher.core.AppLanguage.applyTo(this, newBase) @@ -392,8 +392,6 @@ class MainActivity : ComponentActivity() { private var touchMode by mutableStateOf(SessionPrefs.TOUCH_AUTO) private var suspendPolicy by mutableStateOf(SessionPrefs.SUSPEND_MANUAL) private var steamDownloadsInBackground by mutableStateOf(false) - private var zramCompression by mutableStateOf(false) - private var zramSupported by mutableStateOf(null) private var oscMode by mutableStateOf(SessionPrefs.OSC_AUTO) private var backActionsInverted by mutableStateOf(false) private var gameStorage by mutableStateOf("") @@ -699,7 +697,7 @@ class MainActivity : ComponentActivity() { else { switchPoll = null switchingTo = null - android.widget.Toast.makeText(this@MainActivity, R.string.game_link_session_busy, android.widget.Toast.LENGTH_LONG).show() + android.widget.Toast.makeText(this@FrontEndActivity, R.string.game_link_session_busy, android.widget.Toast.LENGTH_LONG).show() } return } @@ -757,6 +755,7 @@ class MainActivity : ComponentActivity() { downloadPrefix = DownloadSource.custom(this) DownloadSource.probe() animationsEnabled = SessionPrefs.animationsEnabled(this) + LauncherIcon.repair(this, intent?.component) launcherIcon = LauncherIcon.current(this) gameStoresEnabled = SessionPrefs.gameStoresEnabled(this) gameStoresSpeedTier = SessionPrefs.gameStoresSpeedTier(this) @@ -1037,7 +1036,7 @@ class MainActivity : ComponentActivity() { onWirelessAdbPair = { host, port, code, complete -> Thread({ val result = runCatching { - kotlinx.coroutines.runBlocking { WirelessAdbFix.pair(this@MainActivity, host, port, code) } + kotlinx.coroutines.runBlocking { WirelessAdbFix.pair(this@FrontEndActivity, host, port, code) } } val error = result.exceptionOrNull()?.let { it.localizedMessage ?: getString(R.string.main_wadb_pair_failed) } ui.post { complete(error) } @@ -1045,13 +1044,13 @@ class MainActivity : ComponentActivity() { }, onFindWirelessAdbPort = { host, complete -> Thread({ - val port = WirelessAdbFix.findConnectPort(this@MainActivity, host) + val port = WirelessAdbFix.findConnectPort(this@FrontEndActivity, host) ui.post { complete(port) } }, "wireless-adb-discovery").start() }, onWirelessAdbApply = { host, port, enabled, complete -> Thread({ - val result = runCatching { WirelessAdbFix.setChildProcessLimit(this@MainActivity, host, port, enabled) } + val result = runCatching { WirelessAdbFix.setChildProcessLimit(this@FrontEndActivity, host, port, enabled) } val error = result.exceptionOrNull()?.let { it.localizedMessage ?: getString(R.string.main_wadb_command_failed) } ui.post { if (error == null) refreshPhantomStatus() @@ -1061,7 +1060,7 @@ class MainActivity : ComponentActivity() { }, onSetPhantomProcessLimit = { enabled, complete -> Thread({ - val result = runCatching { WirelessAdbFix.setUsingSavedPairing(this@MainActivity, enabled) } + val result = runCatching { WirelessAdbFix.setUsingSavedPairing(this@FrontEndActivity, enabled) } val error = result.exceptionOrNull()?.let { it.localizedMessage ?: getString(R.string.main_wadb_unavailable) } ui.post { if (error == null) refreshPhantomStatus() @@ -1117,7 +1116,7 @@ class MainActivity : ComponentActivity() { showNonAdreno?.let { release -> ConfirmDialog( title = androidx.compose.ui.res.stringResource(R.string.main_non_adreno_title), - text = androidx.compose.ui.res.stringResource(R.string.main_non_adreno_text, com.droiddeck.launcher.core.DeviceSupport.gpuName(this@MainActivity), release.size / 1e6), + text = androidx.compose.ui.res.stringResource(R.string.main_non_adreno_text, com.droiddeck.launcher.core.DeviceSupport.gpuName(this@FrontEndActivity), release.size / 1e6), confirm = androidx.compose.ui.res.stringResource(R.string.main_install_anyway), onConfirm = { showNonAdreno = null; install(release) }, onDismiss = { showNonAdreno = null }, @@ -1616,8 +1615,6 @@ class MainActivity : ComponentActivity() { touchMode = touchMode, suspendPolicy = suspendPolicy, steamDownloadsInBackground = steamDownloadsInBackground, - zramCompression = if (mode == SessionService.MODE_STEAM) zramCompression else null, - zramSupported = zramSupported, pipSupported = com.droiddeck.launcher.session.SessionPipController.supported(this), pipAutoEnter = pipAutoEnter, unfoldedControls = if (mode == SessionService.MODE_STEAM && @@ -1686,7 +1683,6 @@ class MainActivity : ComponentActivity() { SessionPrefs.setSteamDownloadsInBackground(this, enabled) steamDownloadsInBackground = enabled }, - onZramCompression = { on -> SessionPrefs.setZramCompression(this, on); zramCompression = on }, onPipAutoEnter = { on -> SessionPrefs.setPipAutoEnter(this, on); pipAutoEnter = on }, onUnfoldedControls = { on -> SessionPrefs.setUnfoldedControls(this, on); unfoldedControls = on }, onUnfoldedControlsWithController = { on -> @@ -1918,9 +1914,6 @@ class MainActivity : ComponentActivity() { storageDiagnostics = SessionPrefs.storageDiagnosticsEnabled(this) settingsMode = mode Thread({ - val zram = com.droiddeck.launcher.core.ZramSupport.supported() - val zramOn = SessionPrefs.zramCompression(this) - ui.post { zramSupported = zram; zramCompression = zramOn } drivers.refreshDrivers() val storage = GameStorage.options(this) val deckyInstalled = if (mode == SessionService.MODE_STEAM) DeckyManager.installed(this) else null @@ -2037,7 +2030,7 @@ class MainActivity : ComponentActivity() { steamGamesX64 = scannedX64 steamGames = all.map { g -> val newer = current[g.appId] - if (newer != null && g.library != Library.ADDED && steamArtRefreshes[g.appId] != artRefreshesAtStart[g.appId]) g.withArt(newer.art, newer.hero, newer.icon) else g + if (newer != null && g.library != Library.ADDED && steamArtRefreshes[g.appId] != artRefreshesAtStart[g.appId]) g.withArt(newer.art, newer.hero, newer.icon, newer.logo) else g } shortcutLibraryScanning = false handleGameLink(all) diff --git a/app/src/main/java/com/droiddeck/launcher/HomeActivity.kt b/app/src/main/java/com/droiddeck/launcher/HomeActivity.kt index 54526834b5..71304e8837 100644 --- a/app/src/main/java/com/droiddeck/launcher/HomeActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/HomeActivity.kt @@ -23,7 +23,7 @@ class HomeActivity : Activity() { .setAction(SessionService.ACTION_HOME_GUIDE) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP) } else { - Intent(this, MainActivity::class.java) + Intent(this, FrontEndActivity::class.java) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP) } startActivity(destination) diff --git a/app/src/main/java/com/droiddeck/launcher/LauncherIcon.kt b/app/src/main/java/com/droiddeck/launcher/LauncherIcon.kt index 9183df76e8..89c33523ac 100644 --- a/app/src/main/java/com/droiddeck/launcher/LauncherIcon.kt +++ b/app/src/main/java/com/droiddeck/launcher/LauncherIcon.kt @@ -8,7 +8,7 @@ object LauncherIcon { const val DARK = "dark" const val LIGHT = "light" - private val aliases = linkedMapOf(DARK to "com.droiddeck.launcher.LauncherDark", LIGHT to "com.droiddeck.launcher.LauncherLight") + private val aliases = linkedMapOf(DARK to "com.droiddeck.launcher.MainActivity", LIGHT to "com.droiddeck.launcher.LauncherLight") val options: List> = listOf( DARK to R.string.setup_launcher_icon_dark, @@ -29,6 +29,12 @@ object LauncherIcon { fun activity(context: Context): ComponentName = component(context, current(context)) + fun repair(context: Context, launchedFrom: ComponentName?) { + if (!enabled(context, DARK) || !enabled(context, LIGHT) || launchedFrom == component(context, DARK)) return + context.packageManager.setComponentEnabledSetting(component(context, DARK), + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP) + } + fun set(context: Context, style: String) { if (style !in aliases || style == current(context)) return val pm = context.packageManager diff --git a/app/src/main/java/com/droiddeck/launcher/audio/DirectAudioRelayComponent.java b/app/src/main/java/com/droiddeck/launcher/audio/DirectAudioRelayComponent.java index 15ffd7bdb0..f1fa534927 100644 --- a/app/src/main/java/com/droiddeck/launcher/audio/DirectAudioRelayComponent.java +++ b/app/src/main/java/com/droiddeck/launcher/audio/DirectAudioRelayComponent.java @@ -17,6 +17,8 @@ public class DirectAudioRelayComponent extends SessionPart { private File logFile; private final File micFifoPath; private volatile int pid = -1; + private final Object micLock = new Object(); + private boolean micHot; public DirectAudioRelayComponent(File socketPath, File micFifoPath) { this.socketPath = socketPath; @@ -30,6 +32,9 @@ public class DirectAudioRelayComponent extends SessionPart { @Override public void start() { stop(); + synchronized (micLock) { + micHot = false; + } File binary = new File(app().getApplicationInfo().nativeLibraryDir, BINARY); if (!binary.isFile()) { Log.w(TAG, "helper missing at " + binary + "; DirectAudio will report itself unavailable"); @@ -79,12 +84,40 @@ public class DirectAudioRelayComponent extends SessionPart { app().getFilesDir(), null, line -> { Log.i(TAG, line); + trackMic(line); if (log != null) synchronized (log) { log.println(line); log.flush(); } }); Log.i(TAG, "started pid=" + pid + " socket=" + socketPath + (micFifoPath != null ? " mic=" + micFifoPath : " (no microphone)")); } + private void trackMic(String line) { + boolean start = line.startsWith("DA-Relay: mic start "); + if (!start && !line.startsWith("DA-Relay: mic stop ")) return; + synchronized (micLock) { + micHot = start; + micLock.notifyAll(); + } + } + + // Android keeps the input stream's wake lock while a frozen helper still has it started. + public boolean awaitMicReleased(long timeoutMs) { + long deadline = System.currentTimeMillis() + timeoutMs; + synchronized (micLock) { + while (micHot) { + long left = deadline - System.currentTimeMillis(); + if (left <= 0) return false; + try { + micLock.wait(left); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return false; + } + } + return true; + } + } + @Override public void stop() { if (pid != -1) { diff --git a/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java b/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java index 849455b7a0..3b73b6a3c9 100644 --- a/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java +++ b/app/src/main/java/com/droiddeck/launcher/audio/PulseAudioComponent.java @@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit; public class PulseAudioComponent extends SessionPart { private static final String TAG = "PulseAudio"; public static final String SOCKET_NAME = "PS0"; + private static final String MIC_SOURCE = "DirectAudioMic"; private static final String BUNDLE_STAMP = "2026-10-08-pa13-directaudio-native"; @@ -97,9 +98,9 @@ public class PulseAudioComponent extends SessionPart { config.add("set-default-sink DirectAudio"); config.add(".fail"); if (micFifoPath != null && !micFifoPath.isEmpty()) { - config.add("load-module module-pipe-source source_name=DirectAudioMic file=\"" + config.add("load-module module-pipe-source source_name=" + MIC_SOURCE + " file=\"" + micFifoPath + "\" format=s16le rate=48000 channels=1"); - config.add("set-default-source DirectAudioMic"); + config.add("set-default-source " + MIC_SOURCE); } FileUtils.writeString(new File(workingDir, "default.pa"), String.join("\n", config)); @@ -202,16 +203,24 @@ public class PulseAudioComponent extends SessionPart { } public boolean setSinkSuspended(boolean suspended) { + return suspend("sink", "@DEFAULT_SINK@", suspended); + } + + public boolean setMicSuspended(boolean suspended) { + return micFifoPath == null || micFifoPath.isEmpty() || suspend("source", MIC_SOURCE, suspended); + } + + private boolean suspend(String kind, String name, boolean suspended) { File pactl = new File(workingDir, "pactl"); if (!pactl.isFile() || pid <= 1) { - Log.w(TAG, "cannot change sink state: PulseAudio control client or server unavailable"); + Log.w(TAG, "cannot change " + kind + " state: PulseAudio control client or server unavailable"); return false; } java.lang.Process process = null; try { File modules = new File(workingDir, "modules/arm64"); ProcessBuilder builder = new ProcessBuilder( - pactl.getAbsolutePath(), "suspend-sink", "@DEFAULT_SINK@", Boolean.toString(suspended)); + pactl.getAbsolutePath(), "suspend-" + kind, name, Boolean.toString(suspended)); builder.directory(workingDir); builder.redirectErrorStream(true); builder.redirectOutput(new File("/dev/null")); @@ -222,18 +231,18 @@ public class PulseAudioComponent extends SessionPart { process = builder.start(); if (!process.waitFor(5, TimeUnit.SECONDS)) { process.destroyForcibly(); - Log.w(TAG, "timed out changing sink state to suspended=" + suspended); + Log.w(TAG, "timed out changing " + kind + " state to suspended=" + suspended); return false; } int status = process.exitValue(); - if (status != 0) Log.w(TAG, "sink state change failed with exit " + status); + if (status != 0) Log.w(TAG, kind + " state change failed with exit " + status); return status == 0; } catch (InterruptedException e) { Thread.currentThread().interrupt(); - Log.w(TAG, "interrupted changing sink state", e); + Log.w(TAG, "interrupted changing " + kind + " state", e); return false; } catch (Exception e) { - Log.w(TAG, "could not change sink state", e); + Log.w(TAG, "could not change " + kind + " state", e); return false; } finally { if (process != null && process.isAlive()) process.destroyForcibly(); diff --git a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt index f8806c7c03..c924f85329 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt @@ -14,7 +14,7 @@ import android.os.Build import android.os.Handler import android.os.IBinder import android.os.Looper -import com.droiddeck.launcher.MainActivity +import com.droiddeck.launcher.FrontEndActivity import com.droiddeck.launcher.R import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -185,7 +185,7 @@ class WirelessAdbPairingService : Service() { enableVibration(false) }) val open = PendingIntent.getActivity(this, 0, - Intent(this, MainActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), + Intent(this, FrontEndActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), PendingIntent.FLAG_IMMUTABLE) val cancel = PendingIntent.getService(this, 1, Intent(this, WirelessAdbPairingService::class.java).setAction(ACTION_CANCEL), PendingIntent.FLAG_IMMUTABLE) diff --git a/app/src/main/java/com/droiddeck/launcher/core/ZramSupport.kt b/app/src/main/java/com/droiddeck/launcher/core/ZramSupport.kt index 51c3b24948..3befaac385 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/ZramSupport.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/ZramSupport.kt @@ -1,26 +1,10 @@ package com.droiddeck.launcher.core -import android.app.ActivityManager -import android.content.Context -import android.os.Build import java.io.File object ZramSupport { - private const val GIB = 1L shl 30 - fun supported(): Boolean = kernelAtLeast(System.getProperty("os.version").orEmpty(), 5, 4) && swapTotalKb() > 0 - fun recommended(context: Context): Boolean { - if (!supported()) return false - val memory = ActivityManager.MemoryInfo() - context.getSystemService(ActivityManager::class.java).getMemoryInfo(memory) - val advertised = if (Build.VERSION.SDK_INT >= 34) memory.advertisedMem else 0L - return belowTwelveGb(advertised, memory.totalMem) - } - - fun belowTwelveGb(advertisedBytes: Long, totalBytes: Long): Boolean = - if (advertisedBytes > 0) advertisedBytes < 11 * GIB else totalBytes < 10 * GIB - fun kernelAtLeast(release: String, major: Int, minor: Int): Boolean { val parts = Regex("^(\\d+)\\.(\\d+)").find(release)?.groupValues ?: return false val ma = parts[1].toInt() diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGameArt.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGameArt.kt index 62d04d2477..8315c22e9e 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGameArt.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGameArt.kt @@ -5,6 +5,8 @@ import android.graphics.Bitmap import android.util.Log import com.droiddeck.launcher.files.PeIconExtractor import com.droiddeck.launcher.session.SessionPrefs +import com.droiddeck.launcher.stores.StoreArt +import com.droiddeck.launcher.stores.StoreGameSidecar import org.json.JSONObject import java.io.File import java.net.HttpURLConnection @@ -228,41 +230,93 @@ object AddedGameArt { return if (tmp.renameTo(png)) png else null } - fun fetchMissing(context: Context, games: List): Boolean { + internal class Sources( + val storeLogo: (AddedGames.Game) -> Boolean, + val steamSearch: (String) -> Int?, + val steam: (String, File, Set) -> Boolean, + val sgdbGame: (String, Int?, String) -> Int?, + val sgdb: (String, Int, File, Set) -> Boolean, + ) + + private val network = Sources( + storeLogo = ::storeLogo, + steamSearch = { name -> search(name)?.toIntOrNull() }, + steam = ::download, + sgdbGame = SteamGridDb::gameId, + sgdb = SteamGridDb::download, + ) + + private val EXTRAS = setOf(Slot.LOGO, Slot.ICON) + private val STEAM_SLOTS = setOf(Slot.COVER, Slot.WIDE, Slot.BACKGROUND, Slot.LOGO) + internal const val EXTRAS_TRIED = "extras-tried" + + internal fun missing(context: Context, game: AddedGames.Game): Set { + val own = local(game) + val cache = cacheDir(context, game) + fun has(slot: Slot, mine: File?, cached: String) = chosen(cache, slot) != null || mine != null || File(cache, cached).isFile + return Slot.values().filterNot { slot -> + when (slot) { + Slot.COVER -> has(slot, own.portrait, "p.jpg") + Slot.WIDE -> has(slot, own.header, "header.jpg") + Slot.BACKGROUND -> has(slot, own.hero, "hero.jpg") + Slot.LOGO -> has(slot, own.logo, "logo.png") + Slot.ICON -> has(slot, own.icon, "icon-sgdb.png") + } + }.toSet() + } + + private fun storeLogo(game: AddedGames.Game): Boolean { + val url = StoreGameSidecar.read(game.folder)?.logo ?: return false + return StoreArt.fetchLogo(game.folder, url) + } + + fun fetchMissing(context: Context, games: List): Boolean = + fetchMissing(context, games, SteamGridDb.key(context), network) + + internal fun fetchMissing(context: Context, games: List, sgdbKey: String, sources: Sources): Boolean { if (!SessionPrefs.addedGamesArt(context)) return false - val sgdbKey = SteamGridDb.key(context) val keyChangedAt = SteamGridDb.keyChangedAt(context) var sgdbDown = false var changed = false for (game in games) { - if (local(game).portrait != null) continue + val start = missing(context, game) + val full = Slot.COVER in start + val allowed = if (full) Slot.values().toSet() else EXTRAS + var need = start intersect allowed + if (need.isEmpty() || (need == setOf(Slot.ICON) && sgdbKey.isEmpty())) continue val cache = cacheDir(context, game) - if (File(cache, "p.jpg").isFile) continue + val tried = File(cache, EXTRAS_TRIED) + if (!full && tried.isFile && tried.lastModified() >= keyChangedAt && System.currentTimeMillis() - tried.lastModified() < RETRY_AFTER_MS) continue cache.mkdirs() - val match = steamMatch(context, game) { name -> - runCatching { search(name) }.onFailure { Log.w(TAG, "${game.name}: store search failed (${it.message})") }.getOrNull()?.toIntOrNull() + if (Slot.LOGO in need && game.source != Library.ADDED && runCatching { sources.storeLogo(game) }.getOrDefault(false)) { + changed = true + need = need - Slot.LOGO } - val appId = match.appId?.takeIf { match.certainty == SteamMatch.Certainty.FILES } - val id = match.appId?.toString() - if (id != null && download(id, cache)) changed = true - if (File(cache, "p.jpg").isFile || sgdbKey.isEmpty() || sgdbDown) continue - val stored: String? = try { - remembered(File(cache, "sgdb-id"), keyChangedAt) { - SteamGridDb.gameId(sgdbKey, appId ?: id?.toIntOrNull(), game.name)?.toString() + val match by lazy { + steamMatch(context, game) { name -> + runCatching { sources.steamSearch(name) }.onFailure { Log.w(TAG, "${game.name}: store search failed (${it.message})") }.getOrNull() } - } catch (e: Exception) { - Log.w(TAG, "${game.name}: SteamGridDB lookup failed (${e.javaClass.simpleName}); not asking again this pass") - sgdbDown = true - null } - val gridId = stored?.toIntOrNull() ?: continue - val grabbed = try { - SteamGridDb.download(sgdbKey, gridId, cache) - } catch (e: Exception) { - sgdbDown = true - false + val steamWant = need intersect STEAM_SLOTS + if (steamWant.isNotEmpty()) { + val id = match.appId?.toString() + if (id != null && sources.steam(id, cache, steamWant)) changed = true + need = missing(context, game) intersect allowed } - if (grabbed) changed = true + var asked = true + if (need.isNotEmpty() && sgdbKey.isNotEmpty()) { + if (sgdbDown) asked = false else try { + val gridId = remembered(File(cache, "sgdb-id"), keyChangedAt) { + sources.sgdbGame(sgdbKey, match.appId, game.name)?.toString() + }?.toIntOrNull() + if (gridId != null && sources.sgdb(sgdbKey, gridId, cache, need)) changed = true + } catch (e: Exception) { + Log.w(TAG, "${game.name}: SteamGridDB failed (${e.javaClass.simpleName}); not asking again this pass") + sgdbDown = true + asked = false + } + } + if ((missing(context, game) intersect EXTRAS).isEmpty()) tried.delete() else if (asked) tried.writeText("") } return changed } @@ -314,11 +368,13 @@ object AddedGameArt { return pickStoreResult(name, (0 until items.length()).map { items.getJSONObject(it) }.map { it.optString("id") to it.optString("name") }) } - private fun download(id: String, cache: File): Boolean { + private fun download(id: String, cache: File, slots: Set): Boolean { var got = false - for ((remote, localName) in listOf( - "library_600x900.jpg" to "p.jpg", "header.jpg" to "header.jpg", "library_hero.jpg" to "hero.jpg", "logo.png" to "logo.png", + for ((slot, remote, localName) in listOf( + Triple(Slot.COVER, "library_600x900.jpg", "p.jpg"), Triple(Slot.WIDE, "header.jpg", "header.jpg"), + Triple(Slot.BACKGROUND, "library_hero.jpg", "hero.jpg"), Triple(Slot.LOGO, "logo.png", "logo.png"), )) { + if (slot !in slots) continue val dst = File(cache, localName) if (dst.isFile) continue val bytes = get("$CDN$id/$remote") ?: steamAssetUrl(id, remote)?.let { get(it) } ?: continue diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/GameShortcuts.kt b/app/src/main/java/com/droiddeck/launcher/frontend/GameShortcuts.kt index 80cdd93c1b..45b2452694 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/GameShortcuts.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/GameShortcuts.kt @@ -11,13 +11,13 @@ import android.graphics.drawable.Icon import android.net.Uri import android.widget.Toast import com.droiddeck.launcher.LauncherIcon -import com.droiddeck.launcher.MainActivity +import com.droiddeck.launcher.FrontEndActivity import com.droiddeck.launcher.R import java.io.File object GameShortcuts { fun launchIntent(context: Context, gameId: String) = Intent(Intent.ACTION_VIEW, - Uri.parse(GameLaunchLink.uri(gameId)), context, MainActivity::class.java) + Uri.parse(GameLaunchLink.uri(gameId)), context, FrontEndActivity::class.java) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP) private fun info(context: Context, game: Library.SteamGame): ShortcutInfo { 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 1242d9add1..91691cb1e7 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt @@ -16,9 +16,10 @@ object Library { val icon: File? = null, val source: String = SOURCE_STEAM, val storeId: String? = null, + val logo: File? = null, ) { - fun withArt(art: File?, hero: File?, icon: File?) = - SteamGame(appId, name, art, library, gameId, hero, lastPlayed, gameFiles, protonPrefix, icon, source, storeId) + fun withArt(art: File?, hero: File?, icon: File?, logo: File? = this.logo) = + SteamGame(appId, name, art, library, gameId, hero, lastPlayed, gameFiles, protonPrefix, icon, source, storeId, logo) val gameIdString: String get() = java.lang.Long.toUnsignedString(gameId) val profileKey: String get() = if (library == ADDED) java.lang.Integer.toUnsignedString(appId) else appId.toString() @@ -68,6 +69,7 @@ object Library { ) private val STEAM_CAPSULES = listOf("library_capsule.jpg", "library_600x900.jpg") private val STEAM_HEROES = listOf("library_hero.jpg") + internal val STEAM_LOGOS = listOf("logo.png") private val STEAM_ICON = Regex("[a-fA-F0-9]{40}\\.(jpg|png)") private val NAME = Regex("^\\s*\"name\"\\s*\"([^\"]*)\"", RegexOption.MULTILINE) private val STATE = Regex("^\\s*\"StateFlags\"\\s*\"(\\d+)\"", RegexOption.MULTILINE) @@ -131,6 +133,7 @@ object Library { protonPrefix = protonPrefix(context, appId.toLong(), library, roots), icon = steamCacheImage(cache, appId, listOf("icon.jpg", "icon.png")) ?: File(cache, appId.toString()).listFiles()?.firstOrNull { it.isFile && STEAM_ICON.matches(it.name) }, + logo = steamCacheImage(cache, appId, STEAM_LOGOS), )) } } @@ -203,6 +206,7 @@ object Library { protonPrefix = protonPrefix(context, g.steamAppId?.toLong() ?: g.appId, libraries = roots), icon = art.icon?.takeIf { it.extension.lowercase() != "ico" }, source = g.source, storeId = g.storeId, + logo = art.logo, ) } diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/LibraryCache.kt b/app/src/main/java/com/droiddeck/launcher/frontend/LibraryCache.kt index 3d03b23073..cd30e400cf 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/LibraryCache.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/LibraryCache.kt @@ -27,6 +27,7 @@ object LibraryCache { icon = o.file("icon"), source = o.optString("source").ifEmpty { if (o.getString("library") == Library.ADDED) Library.ADDED else Library.SOURCE_STEAM }, storeId = o.optString("storeId").ifEmpty { null }, + logo = o.file("logo"), ) } to x64 }.getOrElse { e -> Log.w(TAG, "unreadable, ignored: ${e.message}"); Pair(emptyList(), false) } @@ -44,7 +45,7 @@ object LibraryCache { for (g in games) array.put( JSONObject().put("appId", g.appId).put("name", g.name).put("library", g.library).put("gameId", g.gameId) .put("lastPlayed", g.lastPlayed).putFile("art", g.art).putFile("hero", g.hero) - .putFile("gameFiles", g.gameFiles).putFile("protonPrefix", g.protonPrefix).putFile("icon", g.icon) + .putFile("gameFiles", g.gameFiles).putFile("protonPrefix", g.protonPrefix).putFile("icon", g.icon).putFile("logo", g.logo) .put("source", g.source).apply { g.storeId?.let { put("storeId", it) } }, ) val f = file(context) diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/SteamGameArt.kt b/app/src/main/java/com/droiddeck/launcher/frontend/SteamGameArt.kt index cb4f49f0fd..25a3cb8fb5 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/SteamGameArt.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/SteamGameArt.kt @@ -22,10 +22,12 @@ object SteamGameArt { val cover = chosenFile(context, game.appId, AddedGameArt.Slot.COVER) val hero = chosenFile(context, game.appId, AddedGameArt.Slot.BACKGROUND) val icon = chosenFile(context, game.appId, AddedGameArt.Slot.ICON) - if (cover == null && hero == null && icon == null) return game + val logo = chosenFile(context, game.appId, AddedGameArt.Slot.LOGO) + if (cover == null && hero == null && icon == null && logo == null) return game return Library.SteamGame( game.appId, game.name, cover ?: game.art, game.library, game.gameId, hero ?: game.hero, game.lastPlayed, game.gameFiles, game.protonPrefix, icon ?: game.icon, game.source, game.storeId, + logo ?: game.logo, ) } diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/SteamGridDb.kt b/app/src/main/java/com/droiddeck/launcher/frontend/SteamGridDb.kt index dec6c24cfb..2eaa89410d 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/SteamGridDb.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/SteamGridDb.kt @@ -84,18 +84,23 @@ object SteamGridDb { .filter { it.second > 0 && it.first > 0 } .maxByOrNull { it.second }?.first - fun download(key: String, id: Int, cache: File): Boolean { + internal fun cacheName(slot: AddedGameArt.Slot): String = + when (slot) { + AddedGameArt.Slot.COVER -> "p.jpg" + AddedGameArt.Slot.WIDE -> "header.jpg" + AddedGameArt.Slot.BACKGROUND -> "hero.jpg" + AddedGameArt.Slot.LOGO -> "logo.png" + AddedGameArt.Slot.ICON -> "icon-sgdb.png" + } + + fun download(key: String, id: Int, cache: File, slots: Set = AddedGameArt.Slot.values().toSet()): Boolean { var got = false - for ((path, local) in listOf( - "grids/game/$id?dimensions=600x900&$QUERY" to "p.jpg", - "grids/game/$id?dimensions=460x215,920x430&$QUERY" to "header.jpg", - "heroes/game/$id?$QUERY" to "hero.jpg", - "logos/game/$id?$QUERY" to "logo.png", - "icons/game/$id?$QUERY" to "icon-sgdb.png", - )) { + for (slot in AddedGameArt.Slot.values()) { + if (slot !in slots) continue + val local = cacheName(slot) val dst = File(cache, local) if (dst.isFile) continue - val items = json(key, "$API/$path")?.optJSONArray("data") ?: continue + val items = json(key, "$API/${path(id, slot)}")?.optJSONArray("data") ?: continue val url = best(items, local.endsWith(".png")) ?: continue val bytes = AddedGameArt.get(url) ?: continue val tmp = File(cache, "$local.tmp") diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/RuntimeInstallService.kt b/app/src/main/java/com/droiddeck/launcher/runtime/RuntimeInstallService.kt index d2cee04350..aa53092fe2 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/RuntimeInstallService.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/RuntimeInstallService.kt @@ -9,7 +9,7 @@ import android.content.Context import android.content.Intent import android.os.Build import android.os.IBinder -import com.droiddeck.launcher.MainActivity +import com.droiddeck.launcher.FrontEndActivity import com.droiddeck.launcher.R class RuntimeInstallService : Service() { @@ -75,7 +75,7 @@ class RuntimeInstallService : Service() { enableVibration(false) }) val open = PendingIntent.getActivity(this, 0, - Intent(this, MainActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), + Intent(this, FrontEndActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), PendingIntent.FLAG_IMMUTABLE) return Notification.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.ic_stat_session) diff --git a/app/src/main/java/com/droiddeck/launcher/session/GpuStatsComponent.kt b/app/src/main/java/com/droiddeck/launcher/session/GpuStatsComponent.kt index fb6efe09f3..0063509167 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GpuStatsComponent.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GpuStatsComponent.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.session +import android.os.SystemClock import android.util.Log import com.droiddeck.launcher.core.SessionPart import com.droiddeck.launcher.runtime.LinuxRuntime @@ -23,11 +24,16 @@ class GpuStatsComponent(val dir: File) : SessionPart() { } fun prepare(): Boolean { - if (!File(KGSL).exists() || MANGOHUD_FILES.none { File(KGSL, it).let { f -> f.exists() && !f.canRead() } }) return false + if (!File(KGSL).exists()) return false + val unreadable = MANGOHUD_FILES.any { File(KGSL, it).let { f -> f.exists() && !f.canRead() } } + if (!unreadable && !File(GPUBUSY).canRead()) return false return try { dir.mkdirs() dir.listFiles()?.forEach { java.nio.file.Files.deleteIfExists(it.toPath()) } feeds.clear() + PASSTHROUGH_FILES.forEach { name -> + runCatching { File(dir, name).writeText(File(KGSL, name).readText()) } + } loadFeed()?.let { load -> feeds.add(load) feeds.add(Feed(File(dir, "perf_now"), load.source, load.read, "%-6s\n", percent = true)) @@ -37,7 +43,7 @@ class GpuStatsComponent(val dir: File) : SessionPart() { feeds.add(Feed(File(dir, "cur_freq"), clock.source, { clock.read()?.times(1_000_000) }, "%-10d\n")) } pick("temp", tempSources(), "%6d\n") { milliCelsius(it) }?.let { feeds.add(it) } - feeds.forEach { feed -> feed.read()?.let { write(feed, it) } } + refresh() Log.i(TAG, "hud: kgsl stats from the session's own: " + MANGOHUD_FILES.joinToString { name -> "$name " + (feeds.firstOrNull { it.file.name == name }?.source ?: "none") }) @@ -55,11 +61,20 @@ class GpuStatsComponent(val dir: File) : SessionPart() { while (running) { try { Thread.sleep(PERIOD_MS) } catch (e: InterruptedException) { break } if (!running) break - for (feed in feeds) feed.read()?.let { write(feed, it) } + refresh() } }, "gpu-stats").apply { isDaemon = true; start() } } + // kgsl's gpubusy can read 0 0 straight after a read, so feeds that share a reader share one read. + private fun refresh() { + val values = HashMap<() -> Long?, Long?>() + for (feed in feeds) { + if (feed.read !in values) values[feed.read] = feed.read() + values[feed.read]?.let { write(feed, it) } + } + } + override fun stop() { running = false thread?.interrupt() @@ -67,16 +82,30 @@ class GpuStatsComponent(val dir: File) : SessionPart() { } private fun loadFeed(): Feed? { - pick("gpu_busy_percentage", LOAD_SOURCES, "%3d %%\n") { it.coerceIn(0, 100) }?.let { return it } - val gpubusy = "$KGSL/gpubusy" - val read = { - runCatching { - val parts = File(gpubusy).readText().trim().split(Regex("\\s+")) - val total = parts[1].toLong() - if (total > 0) (parts[0].toLong() * 100 / total).coerceIn(0, 100) else 0L + latchedBusyFeed()?.let { return it } + return pick("gpu_busy_percentage", LOAD_SOURCES, "%3d %%\n") { it.coerceIn(0, 100) } + } + + // kgsl publishes busy/total once per ~1 s of GPU-on time and zeroes it on any read while the GPU is + // power-collapsed, so direct pollers mostly see 0; latch each published window instead. + private fun latchedBusyFeed(): Feed? { + var load = 0L + var windowAt = 0L + val read = read@{ + val parts = runCatching { + File(GPUBUSY).readText().trim().split(Regex("\\s+")).map { it.toLong() } }.getOrNull() + if (parts == null || parts.size < 2) return@read null + val now = SystemClock.elapsedRealtime() + if (parts[1] > 0) { + load = (parts[0] * 100 / parts[1]).coerceIn(0, 100) + windowAt = now + } else if (now - windowAt > LOAD_HOLD_MS) { + load = 0 + } + load } - return if (read() != null) Feed(File(dir, "gpu_busy_percentage"), gpubusy, read, "%3d %%\n") else null + return if (read() != null) Feed(File(dir, "gpu_busy_percentage"), GPUBUSY, read, "%3d %%\n") else null } private fun pick(name: String, sources: List, format: String, unit: (Long) -> Long?): Feed? { @@ -100,8 +129,11 @@ class GpuStatsComponent(val dir: File) : SessionPart() { const val KGSL = "/sys/class/kgsl/kgsl-3d0" const val MSM_LOAD = "/sys/kernel/debug/dri/0/perf_now" const val MSM_CLOCK = "/sys/devices/platform/soc@0/3d00000.gpu/devfreq/3d00000.gpu/cur_freq" + private const val GPUBUSY = "$KGSL/gpubusy" private const val PERIOD_MS = 500L + private const val LOAD_HOLD_MS = 5_000L private val MANGOHUD_FILES = listOf("gpu_busy_percentage", "clock_mhz", "temp") + private val PASSTHROUGH_FILES = listOf("gpu_model", "gpu_chipid") private const val QCOM_GPU = "/sys/kernel/gpu" private val LOAD_SOURCES = listOf( "$KGSL/gpu_busy_percentage", "$KGSL/devfreq/gpu_load", "$KGSL/gpuload", "$QCOM_GPU/gpu_busy", 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 07a3c9f9e6..d9d2d8e1d3 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -7,7 +7,6 @@ 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.core.ZramSupport import com.droiddeck.launcher.gpu.Cardboard import com.droiddeck.launcher.gpu.ScreenEffects import org.json.JSONObject @@ -1051,15 +1050,6 @@ object SessionPrefs { }.apply() } - fun zramCompression(context: Context): Boolean { - val prefs = prefs(context) - return if (prefs.contains("zramCompression")) prefs.getBoolean("zramCompression", false) else ZramSupport.recommended(context) - } - - fun setZramCompression(context: Context, on: Boolean) { - prefs(context).edit().putBoolean("zramCompression", on).apply() - } - fun gameStorage(context: Context): String = prefs(context).getString("gameStorage", "") ?: "" 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 b938eb28a9..e463165b38 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -104,6 +104,8 @@ class SessionService : Service() { private var suspendOperationPending = false private var pipTask = false private var suspendAttemptFailed = false + private var freezePending = false + private var freezeCancelled = false private var pendingSteamGameId: String? = null private var pendingSteamGameGeneration = -1 // Bumped to cancel a running game-exit watch (a new launch, or the session ending). @@ -329,6 +331,7 @@ class SessionService : Service() { steamSleepToken = null completeNativeSleep() suspendOperationPending = false + freezePending = false suspendAttemptFailed = false suspendController = null SessionState.suspended = false @@ -619,9 +622,26 @@ class SessionService : Service() { helperRoots = { components.mapNotNull { it.suspendPid().takeIf { pid -> pid > 1 } } }, suspendAudio = { if (!pulse.setSinkSuspended(true)) Log.w(TAG, "could not suspend audio sink") + if (!pulse.setMicSuspended(true)) Log.w(TAG, "could not suspend microphone source") + val relay = components.firstNotNullOfOrNull { it as? DirectAudioRelayComponent } + if (relay != null && !relay.awaitMicReleased(MIC_RELEASE_TIMEOUT_MS)) { + Log.w(TAG, "microphone still open after ${MIC_RELEASE_TIMEOUT_MS} ms; suspending anyway") + } }, resumeAudio = { if (!pulse.setSinkSuspended(false)) Log.w(TAG, "could not resume audio sink") + if (!pulse.setMicSuspended(false)) Log.w(TAG, "could not resume microphone source") + }, + zramControl = File(filesDir, "${LinuxRuntime.DIR}/tmp/.bl-zram"), + pagedOut = { processes, unacknowledged, residentKb, swapKb, swapBeforeKb, millis -> + Log.i(TAG, "paged out $processes processes ($unacknowledged unacknowledged) in $millis ms: " + + "resident ${residentKb / 1024} MB, zram ${swapBeforeKb / 1024} -> ${swapKb / 1024} MB") + mainHandler.post { + SessionEvents.record("session.paged_out", mapOf( + "processes" to processes, "unacknowledged" to unacknowledged, "residentMb" to residentKb / 1024, + "swapMb" to swapKb / 1024, "swapBeforeMb" to swapBeforeKb / 1024, "ms" to millis, + )) + } }, ) // Watching first: a first run's client download must be known before anything is paused. @@ -704,8 +724,7 @@ class SessionService : Service() { guest.add("BL_SYNC_FALLBACK=" + (if (SessionPrefs.syncFallback(this)) "1" else "0")) guest.add("BL_FSYNC_FIRST=" + (if (SessionPrefs.fsyncFirst(this)) "1" else "0")) guest.add("BL_GAMESCOPE_REALTIME=" + (if (SessionPrefs.gamescopeRealtime(this)) "1" else "0")) - if (SessionState.mode == MODE_STEAM && SessionPrefs.zramCompression(this) && - com.droiddeck.launcher.core.ZramSupport.supported()) guest.add("BL_ZRAM=1") + if (com.droiddeck.launcher.core.ZramSupport.supported()) guest.add("BL_ZRAM=1") guest.add("BANNER_AUDIO_DIRECT_DECAY=0") val extra = extraEnv() + com.droiddeck.launcher.agent.AgentEnv.beginSession(this) if (extra.none { it.startsWith("TU_DEBUG=") }) guest.add("$GAME_TU_DEBUG=" + (tuOverride ?: if (tuDriver) "sysmem" else "")) @@ -1420,6 +1439,10 @@ class SessionService : Service() { SessionPrefs.SUSPEND_MANUAL -> manualPauseRequested && prepared && !downloadsBlockingSuspend else -> false } + if (freezePending && !shouldSuspend && !freezeCancelled) { + freezeCancelled = true + controller.cancelFreeze() + } if (suspendOperationPending || suspendAttemptFailed || shouldSuspend == SessionState.suspended) return val gen = sessionGen suspendOperationPending = true @@ -1430,20 +1453,31 @@ class SessionService : Service() { "nativeSleep" to (nativeSleepToken != null), )) if (shouldSuspend) { - controller.freeze { success -> + freezePending = true + freezeCancelled = false + val freezeSteamToken = steamSleepToken + val freezeNativeToken = nativeSleepToken + controller.freeze( + pageOut = steamSleepToken != null || nativeSleepToken != null || !activityVisible || !screenOn, + ) { success -> mainHandler.post { if (gen != sessionGen || !SessionState.running) return@post suspendOperationPending = false + freezePending = false if (success) { SessionState.suspended = true SessionEvents.transition(SessionPhase.SUSPENDED, "session.suspended") releaseLocks() refreshNotification() } else { - completeNativeSleep() - completeSteamSleep() - suspendAttemptFailed = true - Log.w(TAG, "could not confirm that the session stopped") + if (nativeSleepToken == freezeNativeToken) completeNativeSleep() + if (steamSleepToken == freezeSteamToken) completeSteamSleep() + if (freezeCancelled) { + SessionEvents.record("session.suspend_cancelled") + } else { + suspendAttemptFailed = true + Log.w(TAG, "could not confirm that the session stopped") + } } updateSuspendPolicy() } @@ -1614,6 +1648,7 @@ class SessionService : Service() { GameThreadHints.stop() SessionEvents.transition(SessionPhase.STOPPING, "session.stopping", mapOf("status" to status)) suspendOperationPending = false + freezePending = false launchWatcher?.stopWatching() launchWatcher = null syncWatcher?.stopWatching() @@ -1880,6 +1915,7 @@ class SessionService : Service() { companion object { private const val TAG = "SessionService" private const val TRACER_NICE = -6 + private const val MIC_RELEASE_TIMEOUT_MS = 5_000L private const val TU_DEBUG_SWITCH = "Download/droiddeck-tu-debug" private const val GAME_TU_DEBUG = "DROIDDECK_GAME_TU_DEBUG" private const val LEGACY_ENV_SWITCH = "Download/droiddeck-env" diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionSuspendController.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionSuspendController.kt index d694d67862..5d0e32f990 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionSuspendController.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionSuspendController.kt @@ -18,6 +18,9 @@ internal class SessionSuspendController( private val sleep: (Long) -> Unit = Thread::sleep, private val nowMillis: () -> Long = { System.nanoTime() / 1_000_000 }, private val executor: ExecutorService = Executors.newSingleThreadExecutor(), + private val zramControl: File? = null, + private val pagedOut: (processes: Int, unacknowledged: Int, residentKb: Long, swapKb: Long, swapBeforeKb: Long, millis: Long) -> Unit = + { _, _, _, _, _, _ -> }, ) { private enum class Role { SESSION_ROOT, SESSION_CHILD, HELPER_ROOT, HELPER_CHILD } @@ -38,9 +41,11 @@ internal class SessionSuspendController( private data class TaskIdentity(val process: ProcessRecord, val tid: Int, val started: Long) @Volatile private var closing = false + @Volatile private var cancelled = false private var frozen = emptyList() - fun freeze(completion: (Boolean) -> Unit) { + fun freeze(pageOut: Boolean = false, completion: (Boolean) -> Unit) { + cancelled = false submit({ val records = frozen.associateByTo(LinkedHashMap()) { it.pid to it.started } var complete = false @@ -59,17 +64,18 @@ internal class SessionSuspendController( records[it.pid to it.started] = ProcessRecord(it.pid, it.started, Role.HELPER_ROOT) } } + if (pageOut) pageOut(records, root.pid, helpers) val deadline = nowMillis() + FREEZE_TIMEOUT_MS var previous: Map? = null for (pass in 0 until FREEZE_MAX_PASSES) { - if (closing || nowMillis() >= deadline) break + if (closing || cancelled || nowMillis() >= deadline) break try { if (readProcess(root.pid)?.started != root.started) break addSnapshot(records, root.pid, helpers) if (readProcess(root.pid)?.started != root.started) break stop(records.values.toList()) sleep(if (pass == 0) 70L else 35L) - if (closing || nowMillis() >= deadline) break + if (closing || cancelled || nowMillis() >= deadline) break val current = stoppedSnapshot(records.values.toList(), root) if (current != null && current == previous) { complete = true @@ -97,6 +103,11 @@ internal class SessionSuspendController( }, { completion(false) }) } + // A freeze still queued or paging out stops before its next SIGSTOP pass and rolls back. + fun cancelFreeze() { + cancelled = true + } + fun resume(completion: (Boolean) -> Unit) { submit({ val records = frozen @@ -233,6 +244,65 @@ internal class SessionSuspendController( return tasks.takeIf { stopped && it.isNotEmpty() } } + // A stopped process cannot run libblsession's SIGURG handler, so the page-out has to finish + // before the stop. Android's low-memory killer otherwise finds the frozen game resident in RAM + // with most of zram still free. + private fun pageOut(records: MutableMap, ProcessRecord>, root: Int, helpers: List) { + val control = zramControl?.takeIf { it.isFile } ?: return + try { + addSnapshot(records, root, helpers) + control.writeText("1") + } catch (_: IOException) { + return + } + val targets = records.values.filter { record -> + try { + File(procRoot, "${record.pid}/maps").useLines { lines -> lines.any { it.endsWith("/libblsession.so") } } + } catch (_: IOException) { + false + } + } + if (targets.isEmpty()) return + val acks = targets.associateWith { File(control.parentFile, "${control.name}.ack.${it.pid}") } + acks.values.forEach { it.delete() } + val start = nowMillis() + val before = memoryKb(targets) + for (record in targets) send(record, SIGURG) + // A program can replace libblsession's SIGURG handler (PyInstaller's bootloader, the Go runtime); + // such a process never creates its ack and is not waited for once the start window has passed. + val waiting = targets.toMutableList() + while (!closing && !cancelled && nowMillis() - start < PAGE_OUT_TIMEOUT_MS) { + val started = nowMillis() - start >= PAGE_OUT_START_MS + waiting.removeAll { val ack = acks.getValue(it); ack.length() > 0 || (started && !ack.exists()) || isGone(it) } + if (waiting.isEmpty()) break + sleep(PAGE_OUT_POLL_MS) + } + val unacknowledged = targets.count { acks.getValue(it).length() == 0L && !isGone(it) } + acks.values.forEach { it.delete() } + val after = memoryKb(targets) + pagedOut(targets.size, unacknowledged, after.first, after.second, before.second, nowMillis() - start) + } + + private fun isGone(record: ProcessRecord): Boolean = + try { readProcess(record.pid)?.started != record.started } catch (_: Exception) { false } + + private fun memoryKb(records: List): Pair { + var resident = 0L + var swap = 0L + for (record in records) { + try { + File(procRoot, "${record.pid}/status").useLines { lines -> + for (line in lines) { + val kb = line.substringAfter(':').trim().substringBefore(' ').toLongOrNull() ?: continue + if (line.startsWith("VmRSS:")) resident += kb else if (line.startsWith("VmSwap:")) swap += kb + } + } + } catch (_: IOException) { + } + } + return resident to swap + } + // PRoot traces every guest. A stop sent while it runs becomes a group stop that it restarts // thread by thread; once it is stopped, each thread that takes a SIGSTOP stays parked in its // signal-delivery stop. So the roots stop first and every guest thread gets its own SIGSTOP. @@ -310,6 +380,10 @@ internal class SessionSuspendController( private companion object { const val SIGSTOP = 19 const val SIGCONT = 18 + const val SIGURG = 23 + const val PAGE_OUT_POLL_MS = 100L + const val PAGE_OUT_START_MS = 2_000L + const val PAGE_OUT_TIMEOUT_MS = 12_000L const val RESTORE_CHECKS = 80 const val FREEZE_TIMEOUT_MS = 8_000L const val FREEZE_MAX_PASSES = 256 diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreAccounts.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreAccounts.kt index 27bf133f18..a740eb088e 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreAccounts.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreAccounts.kt @@ -94,6 +94,20 @@ object StoreAccounts { return json.optString("display_name", "").ifEmpty { json.optString("username", "") }.ifEmpty { store.label } } + /** The name the Stores page shows. Xbox shows the gamertag, else the sign-in email with its name part masked. */ + fun displayName(context: Context, store: Store): String? { + if (store != Store.XBOX) return signedInAs(context, store) + val json = read(context, store) ?: return if (isUnavailable(store)) store.label else null + val signedIn = json.optString("username").takeIf { it.isNotBlank() } ?: return null + json.optString("gamertag").takeIf { it.isNotBlank() }?.let { return it } + return maskEmail(signedIn) + } + + internal fun maskEmail(name: String): String { + val at = name.indexOf('@') + return if (at <= 0) name.take(1) + "•••" else name.take(1) + "•••" + name.substring(at) + } + private fun seal(f: File, json: JSONObject, retry: Boolean = false): File? { if (keystoreFailed && !retry) return null val text = json.toString() diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreArt.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreArt.kt index 4b2b0b8039..14415fd9c6 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreArt.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreArt.kt @@ -14,13 +14,45 @@ object StoreArt { fun fetchInto(folder: File, sidecar: StoreGameSidecar) { sidecar.cover?.let { place(it, File(folder, "cover.jpg")) } - val wide = sidecar.hero ?: return - if (place(wide, File(folder, "hero.jpg"))) { - val header = File(folder, "header.jpg") - if (!header.isFile) runCatching { File(folder, "hero.jpg").copyTo(header, overwrite = true) } + sidecar.hero?.let { wide -> + if (place(wide, File(folder, "hero.jpg"))) { + val header = File(folder, "header.jpg") + if (!header.isFile) runCatching { File(folder, "hero.jpg").copyTo(header, overwrite = true) } + } + } + sidecar.logo?.let { fetchLogo(folder, it) } + } + + fun fetchLogo(folder: File, url: String): Boolean { + val dst = File(folder, LOGO) + if (dst.isFile && dst.length() > 0) return true + return writeLogo(get(url) ?: return false, dst) + } + + /** A logo is drawn over the hero, so it stays a PNG with its transparency instead of going through [place]. */ + internal fun writeLogo(bytes: ByteArray, dst: File): Boolean { + if (dst.isFile && dst.length() > 0) return true + val bitmap = runCatching { BitmapFactory.decodeByteArray(bytes, 0, bytes.size) }.getOrNull() ?: return false + val tmp = File(dst.path + ".tmp") + return try { + if (bitmap.width <= 0 || bitmap.height <= 0) return false + if (isPng(bytes)) tmp.writeBytes(bytes) else tmp.outputStream().use { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) } + tmp.renameTo(dst) + } catch (e: Exception) { + Log.w(TAG, "${dst.name}: ${e.javaClass.simpleName}") + false + } finally { + tmp.delete() + bitmap.recycle() } } + private val PNG_MAGIC = byteArrayOf(0x89.toByte(), 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A) + + private fun isPng(bytes: ByteArray): Boolean = bytes.size > PNG_MAGIC.size && PNG_MAGIC.indices.all { bytes[it] == PNG_MAGIC[it] } + + const val LOGO = "logo.png" + private fun place(url: String, dst: File): Boolean { if (dst.isFile && dst.length() > 0) return true val bytes = get(url) ?: return false diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreCatalog.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreCatalog.kt index debaf4ad04..cfb0ed53de 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreCatalog.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreCatalog.kt @@ -23,6 +23,7 @@ data class CatalogItem( val mature: Boolean = false, val subscription: Boolean = false, val includedWith: String = "", + val logoUrl: String? = null, ) { val accessible: Boolean get() = owned || subscription /** Licensed now, or a supported package the account's subscription can install. */ diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt index 25850f7479..aa42aa75e8 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt @@ -22,6 +22,7 @@ class StoreGameSidecar( val epic: EpicOptions = EpicOptions(), val cloud: Boolean = true, val achievements: Boolean = true, + val logo: String? = null, ) { val isInstalled: Boolean get() = state == STATE_INSTALLED @@ -33,7 +34,8 @@ class StoreGameSidecar( env: Map = this.env, installVersion: String = this.installVersion, installedAt: Long = this.installedAt, cover: String? = this.cover, hero: String? = this.hero, extra: Map = this.extra, state: String = this.state, epic: EpicOptions = this.epic, cloud: Boolean = this.cloud, achievements: Boolean = this.achievements, - ) = StoreGameSidecar(store, id, title, exe, launcher, args, env, installVersion, installedAt, cover, hero, extra, state, epic, cloud, achievements) + logo: String? = this.logo, + ) = StoreGameSidecar(store, id, title, exe, launcher, args, env, installVersion, installedAt, cover, hero, extra, state, epic, cloud, achievements, logo) fun toJson(): JSONObject = JSONObject().apply { put("version", VERSION) @@ -52,6 +54,7 @@ class StoreGameSidecar( if (installedAt > 0L) put("installedAt", installedAt) if (!cover.isNullOrEmpty()) put("cover", cover) if (!hero.isNullOrEmpty()) put("hero", hero) + if (!logo.isNullOrEmpty()) put("logo", logo) if (extra.isNotEmpty()) put("extra", JSONObject(extra as Map<*, *>)) } @@ -129,6 +132,7 @@ class StoreGameSidecar( epic = o.optJSONObject("epic")?.let { e -> EpicOptions(eos = e.optBoolean("eos", true), offline = e.optBoolean("offline", false)) } ?: EpicOptions(), cloud = o.optBoolean("cloud", true), achievements = o.optBoolean("achievements", true), + logo = o.optString("logo", "").ifEmpty { null }, ) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt index 9b3f7136d6..65fdf6e921 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt @@ -40,7 +40,7 @@ object StoreInstalls { val app = context.applicationContext onStep?.invoke(0, STEPS) val before = StoreGameSidecar.read(folder) - val finished = StoreLaunch.writeLauncher(folder, sidecar.copy(state = StoreGameSidecar.STATE_INSTALLED, epic = before?.epic ?: sidecar.epic, cloud = before?.cloud ?: sidecar.cloud, achievements = before?.achievements ?: sidecar.achievements)) + val finished = StoreLaunch.writeLauncher(folder, sidecar.copy(state = StoreGameSidecar.STATE_INSTALLED, epic = before?.epic ?: sidecar.epic, cloud = before?.cloud ?: sidecar.cloud, achievements = before?.achievements ?: sidecar.achievements, logo = sidecar.logo ?: before?.logo)) finished.write(folder) if (StoreGameSidecar.read(folder)?.isInstalled != true) throw java.io.IOException("the install record could not be written in ${folder.name}") onStep?.invoke(1, STEPS) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt index 0af6590120..bd94cfc3bc 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt @@ -24,6 +24,11 @@ object StoreLogFiles { Thread({ android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND); r.run() }, "store-log-flush").apply { isDaemon = true } } + private val CLOCK = SimpleDateFormat("HH:mm:ss.SSS", Locale.US) + + /** Appends [text] with a time stamp. Works in any of the app's processes. */ + fun stamped(context: Context, text: String) = append(context, "${synchronized(CLOCK) { CLOCK.format(Date()) }} $text") + fun append(context: Context, line: String) { val app = context.applicationContext pending.add(line) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt index e780733d97..317757a8bf 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt @@ -10,9 +10,6 @@ import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import com.droiddeck.launcher.stores.download.DownloadEntry -import java.text.SimpleDateFormat -import java.util.Date -import java.util.Locale object StoresState { private const val TAG = "Stores" @@ -79,7 +76,7 @@ object StoresState { val app = context.applicationContext com.droiddeck.launcher.stores.download.SavedQueue.restore(app) background("stores-refresh") { - val found = Store.entries.mapNotNull { store -> StoreAccounts.signedInAs(app, store)?.let { store to it } } + val found = Store.entries.mapNotNull { store -> StoreAccounts.displayName(app, store)?.let { store to it } } val onDisk = StoreInstallRoot.gameFolders(app).mapNotNull { folder -> StoreGameSidecar.read(folder)?.takeIf { it.isInstalled }?.let { InstalledStoreGame(it, folder) } } @@ -262,7 +259,7 @@ object StoresState { val text = StoreLog.redactLine(raw) Log.i(TAG, text) val app = appContext ?: return - StoreLogFiles.append(app, "${synchronized(CLOCK) { CLOCK.format(Date()) }} $text") + StoreLogFiles.stamped(app, text) } private var appContext: Context? = null @@ -295,8 +292,6 @@ object StoresState { } }, name).start() } - - private val CLOCK = SimpleDateFormat("HH:mm:ss.SSS", Locale.US) } interface StoreBackend { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonInstaller.kt b/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonInstaller.kt index 7eff5fbbe9..401f621ede 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonInstaller.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonInstaller.kt @@ -124,6 +124,7 @@ internal class AmazonInstaller( installVersion = versionId, installedAt = System.currentTimeMillis(), cover = cover, hero = item.imageUrl, extra = mapOf("entitlementId" to entitlementId, "sku" to sku), + logo = item.logoUrl, ) StoreInstalls.complete(app, folder, sidecar, onStep = { done, steps -> handle.stageProgress(done.toLong(), steps.toLong()) }) return folder.path diff --git a/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonLibrary.kt b/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonLibrary.kt index 841fe9217a..41f049979b 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonLibrary.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonLibrary.kt @@ -24,6 +24,7 @@ data class AmazonGame( val publisher: String = "", val productSku: String = "", val versionId: String = "", + val logoUrl: String = "", ) object AmazonLibrary { @@ -42,7 +43,8 @@ object AmazonLibrary { JSONObject() .put("productId", g.productId).put("entitlementId", g.entitlementId).put("title", g.title) .put("artUrl", g.artUrl).put("heroUrl", g.heroUrl).put("developer", g.developer) - .put("publisher", g.publisher).put("productSku", g.productSku).put("versionId", g.versionId), + .put("publisher", g.publisher).put("productSku", g.productSku).put("versionId", g.versionId) + .apply { if (g.logoUrl.isNotEmpty()) put("logoUrl", g.logoUrl) }, ) }.toString() @@ -60,6 +62,7 @@ object AmazonLibrary { publisher = o.optString("publisher", ""), productSku = o.optString("productSku", ""), versionId = o.optString("versionId", ""), + logoUrl = o.optString("logoUrl", ""), ) } return tidy(games) @@ -94,6 +97,7 @@ object AmazonLibrary { sizeBytes = prefs.getLong("size_${game.productId}", 0L).takeIf { it > 0 } ?: 0L, storeUrl = STORE_URL, extra = mapOf("entitlementId" to game.entitlementId, "sku" to game.productSku, "version" to ""), + logoUrl = game.logoUrl.ifEmpty { null }, ) } @@ -106,7 +110,7 @@ object AmazonLibrary { } } - private fun gameFrom(o: JSONObject, before: AmazonGame?): AmazonGame = AmazonGame( + internal fun gameFrom(o: JSONObject, before: AmazonGame?): AmazonGame = AmazonGame( productId = o.optString("productId"), entitlementId = o.optString("entitlementId"), title = o.optString("title"), @@ -116,6 +120,7 @@ object AmazonLibrary { publisher = o.optString("publisher"), productSku = o.optString("sku"), versionId = before?.versionId.orEmpty(), + logoUrl = o.optString("logo").ifEmpty { before?.logoUrl.orEmpty() }, ) private fun backfillPosters(app: Context, games: List) { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/download/SavedQueue.kt b/app/src/main/java/com/droiddeck/launcher/stores/download/SavedQueue.kt index 5a5eae4fa0..a9a25759e1 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/download/SavedQueue.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/download/SavedQueue.kt @@ -77,6 +77,7 @@ object SavedQueue { private fun itemJson(i: CatalogItem) = JSONObject().apply { put("store", i.store.id); put("id", i.id); put("title", i.title) put("image", i.imageUrl ?: ""); put("tall", i.tallImageUrl ?: "") + i.logoUrl?.let { put("logo", it) } put("tags", i.tags); put("developer", i.developer); put("description", i.description) put("size", i.sizeBytes); put("owned", i.owned); put("subscription", i.subscription) put("extra", JSONObject(i.extra)) @@ -91,6 +92,7 @@ object SavedQueue { tags = o.optString("tags"), developer = o.optString("developer"), description = o.optString("description"), owned = o.optBoolean("owned", true), subscription = o.optBoolean("subscription"), sizeBytes = o.optLong("size"), extra = extra?.keys()?.asSequence()?.associateWith { extra.getString(it) } ?: emptyMap(), + logoUrl = o.optString("logo").ifEmpty { null }, ) } } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/download/StoreDownloadService.kt b/app/src/main/java/com/droiddeck/launcher/stores/download/StoreDownloadService.kt index a32bceeb69..1f80eecf55 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/download/StoreDownloadService.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/download/StoreDownloadService.kt @@ -15,7 +15,7 @@ import android.os.IBinder import android.os.Looper import android.os.PowerManager import android.util.Log -import com.droiddeck.launcher.MainActivity +import com.droiddeck.launcher.FrontEndActivity import com.droiddeck.launcher.R import com.droiddeck.launcher.core.DeviceSupport import com.droiddeck.launcher.stores.StoresState @@ -189,7 +189,7 @@ class StoreDownloadService : Service() { } private fun openPage(context: Context, nav: String, code: Int): PendingIntent = - PendingIntent.getActivity(context, code, Intent(context, MainActivity::class.java).putExtra(EXTRA_NAV, nav) + PendingIntent.getActivity(context, code, Intent(context, FrontEndActivity::class.java).putExtra(EXTRA_NAV, nav) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP), PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) private fun openDownloads(context: Context, code: Int) = openPage(context, "stores:downloads", code) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicInstaller.kt b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicInstaller.kt index 8d40d002bf..3be966b968 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicInstaller.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicInstaller.kt @@ -133,7 +133,7 @@ internal class EpicInstaller( val sidecar = StoreGameSidecar( Store.EPIC, item.id, item.title, exe = picked.ifEmpty { "game.exe" }, args = args, installVersion = result.optString("buildVersion"), installedAt = System.currentTimeMillis(), - cover = cover, hero = item.imageUrl, extra = extra, + cover = cover, hero = item.imageUrl, extra = extra, logo = item.logoUrl, ) StoreInstalls.complete(app, folder, sidecar, onStep = { done, steps -> handle.stageProgress(done.toLong(), steps.toLong()) }) val disk = result.optLong("diskBytes", 0L) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicLibrary.kt b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicLibrary.kt index be665881b8..32a485bfba 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicLibrary.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicLibrary.kt @@ -25,6 +25,7 @@ data class EpicGame( val releaseDate: String = "", val publisher: String = "", val isDlc: Boolean = false, + val artLogo: String = "", ) object EpicLibrary { @@ -50,7 +51,8 @@ object EpicLibrary { .put("title", g.title).put("artCover", g.artCover).put("artSquare", g.artSquare) .put("developer", g.developer).put("description", g.description).put("version", g.version) .put("installSize", g.installSize).put("canRunOffline", g.canRunOffline) - .put("releaseDate", g.releaseDate).put("publisher", g.publisher), + .put("releaseDate", g.releaseDate).put("publisher", g.publisher) + .apply { if (g.artLogo.isNotEmpty()) put("artLogo", g.artLogo) }, ) }.toString() @@ -73,6 +75,7 @@ object EpicLibrary { canRunOffline = o.optBoolean("canRunOffline", true), releaseDate = o.optString("releaseDate", ""), publisher = o.optString("publisher", ""), + artLogo = o.optString("artLogo", ""), ) } return tidy(games) @@ -106,6 +109,7 @@ object EpicLibrary { sizeBytes = prefs.getLong("size_${game.appName}", 0L).takeIf { it > 0 } ?: game.installSize, storeUrl = "https://store.epicgames.com/en-US/browse?q=" + URLEncoder.encode(title, "UTF-8"), extra = mapOf("namespace" to game.namespace, "catalogItemId" to game.catalogItemId, "version" to game.version), + logoUrl = game.artLogo.ifEmpty { null }, ) } @@ -128,6 +132,7 @@ object EpicLibrary { releaseDate = pick("releaseDate", before?.releaseDate.orEmpty()), publisher = pick("publisher", before?.publisher.orEmpty()), isDlc = d.optBoolean("dlc", false), + artLogo = pick("logo", before?.artLogo.orEmpty()), ) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogBackend.kt b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogBackend.kt index 1ba78d7951..acb7333e82 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogBackend.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogBackend.kt @@ -11,10 +11,12 @@ import com.droiddeck.launcher.stores.StoreInstallRoot import com.droiddeck.launcher.stores.StoreInstalls import com.droiddeck.launcher.stores.StoreLanguage import com.droiddeck.launcher.stores.StoreLoginActivity +import com.droiddeck.launcher.stores.StoreNet import com.droiddeck.launcher.stores.StoresState import com.droiddeck.launcher.stores.download.DownloadEntry import com.droiddeck.launcher.stores.download.DownloadQueue import com.droiddeck.launcher.stores.download.DownloadStage +import org.json.JSONObject import java.io.File import java.util.concurrent.atomic.AtomicBoolean @@ -85,6 +87,13 @@ object GogBackend : StoreBackend { override fun uninstall(context: Context, game: InstalledStoreGame) {} + private fun fetchLogo(id: String): String? = + runCatching { StoreNet.get("https://api.gog.com/v2/games/$id?locale=en-US")?.let { logoOf(JSONObject(it)) } }.getOrNull() + + /** `images.logo2x` from the products API is an opaque banner, not a logo; the v2 `logo` link is a transparent PNG. */ + internal fun logoOf(v2: JSONObject): String? = + GogStoreCatalog.absolutize(v2.optJSONObject("_links")?.optJSONObject("logo")?.optString("href")).takeIf { it.startsWith("https://") } + private class InstallJob(val app: Context, val game: GogGame, val item: CatalogItem, val folder: File) : DownloadQueue.DownloadJob { private val cancelled = AtomicBoolean(false) @@ -118,6 +127,7 @@ object GogBackend : StoreBackend { Store.GOG, game.gameId, game.title, exe = result.exeRelative.ifEmpty { "" }, installVersion = result.buildId, installedAt = System.currentTimeMillis(), cover = item.tallImageUrl ?: item.imageUrl, hero = item.imageUrl, + logo = item.logoUrl ?: fetchLogo(game.gameId), extra = mapOf(com.droiddeck.launcher.frontend.WinCompSources.GOG_DEPENDENCIES to result.dependencies.joinToString(",")) + (if (result.dependenciesRead) mapOf(com.droiddeck.launcher.frontend.WinCompSources.LIST_READ to "1") else emptyMap()) + mapOf(StoreLanguage.EXTRA to installedLanguage), diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxBackend.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxBackend.kt index 24d7ff622b..9121a35c9b 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxBackend.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxBackend.kt @@ -53,7 +53,7 @@ object XboxBackend : StoreBackend { else StoresState.status.remove(store) } } - if (cached != null && !cached.needsRefresh(force)) return@Thread + if (cached != null && !cached.needsRefresh(force)) { XboxGamertag.ensure(app); return@Thread } val response = Xodus.run(app, listOf("library", "--json", "--market", market)) val licenses = XboxCatalog.access(response, account, market, report = { StoresState.logLine("Xbox: $it") }) val products = XboxCatalog.rawProducts(licenses.keys.toList(), market) @@ -73,6 +73,7 @@ object XboxBackend : StoreBackend { StoresState.problems.remove(store) } } + if (current == generation) XboxGamertag.ensure(app) } catch (e: Exception) { StoresState.post { if (current == generation) { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCredentials.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCredentials.kt index 40cd28225b..ffe4b9de6b 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCredentials.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCredentials.kt @@ -29,10 +29,16 @@ internal class XboxCredentials(private val app: Context, expectedGeneration: Str } private fun rejected(reason: String): Boolean { - android.util.Log.w("XboxCredentials", "Rejected credential peer: $reason") + note("Rejected credential peer: $reason") return false } + /** Also written to the stores log: sign-in runs in its own process, where only that file reaches a shared log. */ + private fun note(text: String) { + android.util.Log.w("XboxCredentials", text) + com.droiddeck.launcher.stores.StoreLogFiles.stamped(app, "Xbox credentials: $text") + } + private fun authorized(pid: Int): Boolean { if (!bound.await(5, java.util.concurrent.TimeUnit.SECONDS) || closed) return rejected("unbound") val process = backend ?: return rejected("missing-child") @@ -88,7 +94,7 @@ internal class XboxCredentials(private val app: Context, expectedGeneration: Str answer(request) } }.getOrElse { - android.util.Log.w("XboxCredentials", "Credential request rejected: ${it.javaClass.simpleName}") + note("Credential request rejected: ${it.javaClass.simpleName}") JSONObject().put("ok", false) } runCatching { it.outputStream.write((reply.toString() + "\n").toByteArray()) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxGamertag.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxGamertag.kt new file mode 100644 index 0000000000..b065e8bafe --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxGamertag.kt @@ -0,0 +1,51 @@ +package com.droiddeck.launcher.stores.xbox + +import android.content.Context +import com.droiddeck.launcher.stores.Store +import com.droiddeck.launcher.stores.StoreAccounts +import com.droiddeck.launcher.stores.StoresState +/** Keeps the account's Xbox gamertag in its record so the Stores page can show it instead of the sign-in email. */ +internal object XboxGamertag { + /** `xodus-cli profile` allows itself 45 s, and starting it through PRoot adds to that. */ + private const val TIMEOUT_SECONDS = 75L + private val triedGeneration = java.util.concurrent.atomic.AtomicReference(null) + + internal fun valid(value: String): Boolean = value.isNotEmpty() && value.length <= 64 && value.none { it.isISOControl() } + + /** Reads the gamertag with `xodus-cli profile` and stores it; false when Xbox didn't return one. */ + fun refresh(app: Context, credentialGeneration: String? = null): Boolean = try { + val gamertag = Xodus.run(app, listOf("profile", "--json"), timeout = TIMEOUT_SECONDS, credentialGeneration = credentialGeneration) + .optString("gamertag").trim() + require(valid(gamertag)) + XboxCredentials.lifecycle(app, credentialGeneration) { + val record = StoreAccounts.read(app, Store.XBOX) ?: error("Xbox credentials missing") + record.put("gamertag", gamertag) + StoreAccounts.write(app, Store.XBOX, record) + } + StoresState.logLine("Xbox: gamertag read") + true + } catch (e: Exception) { + StoresState.logLine("Xbox: gamertag unavailable (${XboxLoginActivity.failure(e)})") + false + } + + /** Fetches a missing gamertag once per signed-in account, on its own thread so it never holds up a library sync. */ + fun ensure(app: Context) { + Thread({ + runCatching { + val generation = XboxCredentials.lifecycle(app) { it } + if (!StoreAccounts.read(app, Store.XBOX)?.optString("gamertag").isNullOrBlank()) return@runCatching + if (!shouldTryRefresh(generation)) return@runCatching + if (refresh(app, generation)) StoresState.refresh(app) + }.onFailure { StoresState.logLine("Xbox: gamertag check failed (${it.javaClass.simpleName})") } + }, "xbox-gamertag").start() + } + + internal fun shouldTryRefresh(generation: String): Boolean { + while (true) { + val previous = triedGeneration.get() + if (previous == generation) return false + if (triedGeneration.compareAndSet(previous, generation)) return true + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxLoginActivity.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxLoginActivity.kt index 01e19158f1..bdfb27d09a 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxLoginActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxLoginActivity.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.graphics.Color import android.net.Uri import android.os.Bundle +import android.util.Log import android.webkit.CookieManager import android.webkit.WebResourceRequest import android.webkit.WebView @@ -14,8 +15,11 @@ import android.widget.TextView import androidx.activity.ComponentActivity import androidx.webkit.WebViewCompat import androidx.webkit.WebViewFeature +import com.droiddeck.launcher.core.AddonPack import com.droiddeck.launcher.stores.Store import com.droiddeck.launcher.stores.StoreAccounts +import com.droiddeck.launcher.stores.StoreLogFiles +import com.droiddeck.launcher.stores.StoreLog import org.json.JSONObject import java.util.concurrent.TimeUnit @@ -26,6 +30,7 @@ class XboxLoginActivity : ComponentActivity() { @Volatile private var child: Xodus.Child? = null @Volatile private var session = 0L @Volatile private var closed = false + @Volatile private var step = "starting" @SuppressLint("SetJavaScriptEnabled") override fun onCreate(savedInstanceState: Bundle?) { @@ -49,10 +54,18 @@ class XboxLoginActivity : ComponentActivity() { if (closed) return@Thread try { val accountGeneration = XboxCredentials.lifecycle(applicationContext) { it } + progress("downloading the Xbox components", "Downloading Xbox components…") + check(AddonPack.XBOX.await(applicationContext, { !closed }) { state -> + if (state is AddonPack.State.Downloading) show("Downloading Xbox components… ${(state.progress * 100).toInt()}%") + }) { "Couldn't download the Xbox components. Check your connection and try again." } + if (closed) return@Thread + progress("starting the Xbox helper", "Starting the Xbox helper…") Xodus.start(applicationContext, listOf("--external-webview-stdio", "login"), credentialGeneration = accountGeneration).use { process -> child = process if (closed) return@use - Xodus.diagnostics(process) + // StoresState.logLine writes no file in this process, so the reason would miss the shared log. + Xodus.diagnostics(process) { logStep(it) } + progress("waiting for the Xbox helper", "Waiting for the Xbox helper…") val timer = Thread({ runCatching { if (!process.process.waitFor(10, TimeUnit.MINUTES)) process.process.destroy() } }, "xbox-login-timeout").apply { start() } @@ -68,16 +81,19 @@ class XboxLoginActivity : ComponentActivity() { check(!ready && frame.getInt("version") == 1) ready = true process.send(JSONObject().put("type", "hello").put("version", 1)) + progress("waiting for Microsoft's sign-in page", "Opening Microsoft sign-in…") } "open" -> { val next = frame.getLong("session") check(ready && next > latest && next <= 32 && trusted(frame.getString("url"))) latest = next; session = next + step = "loading Microsoft's sign-in page" runOnUiThread { if (!closed) open(frame) } } "close" -> { check(frame.getLong("session") == session) session = 0L + step = "completing the sign-in" runOnUiThread { disposeView(); status.text = "Completing Microsoft sign-in…" } } "context" -> { @@ -95,26 +111,52 @@ class XboxLoginActivity : ComponentActivity() { else -> error("Unsupported Xbox sign-in response") } } - check(process.process.waitFor(5, TimeUnit.SECONDS) && process.process.exitValue() == 0 && ready && latest > 0 && session == 0L) + if (closed) return@use + check(process.process.waitFor(5, TimeUnit.SECONDS)) { "the Xbox helper did not exit" } + val exit = process.process.exitValue() + check(exit == 0) { "the Xbox helper stopped with exit code $exit" } + check(ready) { "the Xbox helper never became ready" } + check(latest > 0) { "Microsoft's sign-in page was never requested" } + check(session == 0L) { "the sign-in page was closed before Microsoft finished" } timer.interrupt() } child = null if (closed) return@Thread + step = "saving the account" val account = Xodus.run(applicationContext, listOf("account", "--json"), credentialGeneration = accountGeneration) - check(account.optBoolean("stored")) + check(account.optBoolean("stored")) { "Xbox did not save the account" } XboxCredentials.lifecycle(this, accountGeneration) { val record = StoreAccounts.read(this, Store.XBOX) ?: error("Xbox credentials missing") record.put("username", account.getString("username")) StoreAccounts.write(this, Store.XBOX, record) } + logStep("signed in") runOnUiThread { finish() } } catch (e: Exception) { child = null - if (!closed) runOnUiThread { disposeView(); status.text = "Microsoft sign-in did not complete. Close this window and try again." } + if (closed) return@Thread + val failed = step + val reason = failure(e) + logStep("failed while $failed: $reason") + runOnUiThread { + disposeView() + status.text = "Microsoft sign-in did not complete.\nFailed while $failed: $reason\nClose this window and try again." + } } }, "xbox-login").start() } + private fun show(text: String) = runOnUiThread { if (!closed && view == null) status.text = text } + + private fun progress(name: String, text: String) { step = name; show(text) } + + /** Written to the stores log, which the shared log zip carries; the main process's log helpers don't run in this process. */ + private fun logStep(line: String) { + val text = StoreLog.redactLine("Xbox sign-in: $line") + Log.i(TAG, text) + StoreLogFiles.stamped(applicationContext, text) + } + @SuppressLint("SetJavaScriptEnabled") private fun open(frame: JSONObject) { disposeView() @@ -172,6 +214,15 @@ class XboxLoginActivity : ComponentActivity() { } companion object { + private const val TAG = "XboxLogin" + + /** Our own check messages are safe to show; anything else is named by its type, never its text, which may hold sign-in data. */ + internal fun failure(e: Exception): String { + val message = e.message.orEmpty() + return if (e is IllegalStateException && message.isNotBlank() && message != "Check failed." && message.length <= 160) message + else e.javaClass.simpleName.ifBlank { "error" } + } + private val hosts = setOf("login.live.com", "account.live.com", "login.microsoftonline.com", "login.microsoft.com", "account.microsoft.com", "sisu.xboxlive.com") private val origins = hosts.map { "https://$it" }.toSet() private val allowedHeaders = setOf("cxh-capabilities", "cxh-correlationid", "cxh-msabinaryversion", "cxh-identityclientbinaryversion", "cxh-osversioninfo", "cxh-platform", "cxh-protocol", "cxh-source", "hostapp") 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 6e7c30df84..fde5b0650c 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 @@ -133,11 +133,12 @@ internal object Xodus { } } - fun diagnostics(child: Child): Thread = Thread({ + /** Passes the backend's known stderr diagnostics to [report]; other stderr text never leaves the process. */ + fun diagnostics(child: Child, report: (String) -> Unit = { com.droiddeck.launcher.stores.StoresState.logLine("Xbox: $it") }): Thread = Thread({ runCatching { child.process.errorStream.bufferedReader().useLines { lines -> lines.forEach { line -> - if (line.matches(Regex("NEXUS_CREDENTIAL_ERROR_V1 [a-z-]{1,48}|NEXUS_LIBRARY_DIAGNOSTIC_V1 [a-z-]{1,48} [0-9]{1,3} [0-9]{1,6}|NEXUS_SESSION_DIAGNOSTIC_V1 [a-z-]{1,64}|Account library unavailable \\([a-z-]{1,64}\\); credentials and installed games are unchanged\\.|Account library timed out; installed games are unchanged\\."))) - com.droiddeck.launcher.stores.StoresState.logLine("Xbox: $line") + if (line.matches(Regex("NEXUS_CREDENTIAL_ERROR_V1 [a-z-]{1,48}|NEXUS_LIBRARY_DIAGNOSTIC_V1 [a-z-]{1,48} [0-9]{1,3} [0-9]{1,6}|NEXUS_SESSION_DIAGNOSTIC_V1 [a-z-]{1,64}|Account library unavailable \\([a-z-]{1,64}\\); credentials and installed games are unchanged\\.|Account library timed out; installed games are unchanged\\.|Xbox profile is temporarily unavailable \\([a-z-]{1,48}\\); stored account is unchanged\\.|Xbox profile request timed out; stored account is unchanged\\."))) + report(line) } } } }, "xbox-diagnostics").apply { start() } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndGames.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndGames.kt index dcb5eece6d..c7b78ee05c 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndGames.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndGames.kt @@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll @@ -341,11 +342,24 @@ private fun ColumnScope.GameHeroCopy(g: Library.SteamGame, titleSize: androidx.c maxLines = 1, overflow = TextOverflow.Ellipsis, ) } - Text( + GameTitle(g, titleSize) + Spacer(Modifier.height(8.dp)) +} + +@Composable +private fun GameTitle(g: Library.SteamGame, titleSize: androidx.compose.ui.unit.TextUnit) { + val logo = g.logo + var failed by remember(logo) { androidx.compose.runtime.mutableStateOf(false) } + if (logo != null && !failed) { + AsyncImage( + model = logo, contentDescription = g.name, contentScale = ContentScale.Fit, alignment = Alignment.CenterStart, + onError = { failed = true }, + modifier = Modifier.padding(vertical = 4.dp).height((titleSize.value * 2.2f).dp).widthIn(max = (titleSize.value * 9f).dp).testTag("game-logo"), + ) + } else Text( g.name, fontSize = titleSize, lineHeight = titleSize * 1.15f, fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis, ) - Spacer(Modifier.height(8.dp)) } @Composable diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt index 778673e92d..a444f37115 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt @@ -65,8 +65,6 @@ class ModeSettings( val touchMode: String, val suspendPolicy: String, val steamDownloadsInBackground: Boolean = false, - val zramCompression: Boolean? = null, - val zramSupported: Boolean? = null, val pipSupported: Boolean = false, val pipAutoEnter: Boolean = false, val oscMode: String?, @@ -121,7 +119,6 @@ class ModeSettingsActions( val onTouch: (String) -> Unit, val onSuspendPolicy: (String) -> Unit, val onSteamDownloadsInBackground: (Boolean) -> Unit = {}, - val onZramCompression: (Boolean) -> Unit = {}, val onPipAutoEnter: (Boolean) -> Unit = {}, val onOsc: (String) -> Unit, val onBackActionsInverted: (Boolean) -> Unit = {}, @@ -333,12 +330,6 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: stringResource(R.string.mode_background_downloads_hint), s.steamDownloadsInBackground, onChange = a.onSteamDownloadsInBackground, ) - if (s.zramCompression != null) ToggleRow( - host, "zram", stringResource(R.string.mode_zram), - stringResource(if (s.zramSupported == false) R.string.mode_zram_unsupported else R.string.mode_zram_hint), - s.zramCompression && s.zramSupported != false, enabled = s.zramSupported == true, - onChange = a.onZramCompression, - ) if (s.syncBackend != null) ChoiceRow( host, "sync", stringResource(R.string.sync_backend_title), stringResource(R.string.sync_backend_hint), listOf( diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index d60a59fb94..7001fa9167 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -287,9 +287,6 @@ «تلقائي» يوقف مؤقتًا ويستأنف عند الظهور. «أصلي» يجهّز Steam للسكون أولًا. «يدوي» ينتظر الضغط على «استئناف». «أبدًا» يُبقيه قيد التشغيل. مواصلة التنزيلات تأخير التعليق في الخلفية أثناء قيام Steam بالتنزيل. - ضغط zRAM - أثناء تشغيل اللعبة يتم ضغط ذاكرة عميل Steam إلى zram في الجهاز، فتحصل اللعبة على ذاكرة RAM أكبر. يسري عند تشغيل Steam في المرة القادمة. - غير متاح: لا يحتوي هذا الجهاز على zram أو swap، أو أن النواة أقدم من 5.4. «تلقائي» يوقف مؤقتًا في الخلفية ويستأنف عند الظهور. «يدوي» ينتظر الضغط على «استئناف». «أبدًا» يُبقيه قيد التشغيل. بدء التشغيل تشغيل Steam مع DroidDeck diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index b924266f43..16db21a9b9 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -287,9 +287,6 @@ Auto pausa y reanuda al mostrarse. Nativo prepara Steam para la suspensión primero. Manual espera a Reanudar. Nunca sigue ejecutándose. Mantener las descargas activas Retrasa la suspensión en segundo plano mientras Steam esté descargando. - Compresión zRAM - Mientras se ejecuta un juego, la memoria del cliente de Steam se comprime en la zram del dispositivo, lo que deja más RAM para el juego. Se aplica la próxima vez que se inicie Steam. - No disponible: este dispositivo no tiene swap activo, o su kernel es anterior a la 5.4. Auto pausa en segundo plano y reanuda al mostrarse. Manual espera a Reanudar. Nunca sigue ejecutándose. Inicio Iniciar Steam con DroidDeck diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index f6d820e9e4..9dcc424a11 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -287,9 +287,6 @@ Автоматично поставя на пауза и продължава, когато се покаже отново. Системно подготвя Steam за заспиване първо. Ръчно изчаква „Продължи“. Никога продължава да работи. Продължаване на изтеглянията Отлага фоновото спиране, докато Steam активно изтегля. - zRAM компресия - Докато играта работи, паметта на Steam клиента се компресира в zram на устройството, така че играта получава повече RAM. Важи при следващото стартиране на Steam. - Недостъпно: устройството няма zram или swap, или ядрото е по-старо от 5.4. Автоматично поставя на пауза във фонов режим и продължава при показване. Ръчно изчаква „Продължи“. Никога продължава да работи. Стартиране Стартиране на Steam заедно с DroidDeck diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 74c7e327f9..97e6799605 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -287,9 +287,6 @@ Automaticky pozastaví relaci a obnoví ji při zobrazení. Nativně nejprve připraví Steam na spánek. Manuálně čeká na Obnovit. Nikdy běh nezastavuje. Nechat stahování běžet Oddálí pozastavení na pozadí, pokud Steam aktivně stahuje. - Komprese zRAM - Během hraní se paměť klienta Steam komprimuje do zram zařízení, takže hra má víc RAM. Platí při příštím spuštění Steamu. - Není k dispozici: zařízení nemá zram ani swap, nebo je jádro starší než 5.4. Automaticky pozastaví na pozadí a obnoví při zobrazení. Manuálně čeká na Obnovit. Nikdy běh nezastavuje. Spouštění Spustit Steam s DroidDeck diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 062bcb4b54..0c2bc230b3 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -287,9 +287,6 @@ Auto sætter på pause og genoptager, når den vises. Native forbereder Steam til dvale først. Manuel venter på Genoptag. Aldrig fortsætter med at køre. Fortsæt downloads Udskyder baggrundspause, mens Steam aktivt downloader. - zRAM-komprimering - Mens et spil kører, komprimeres Steam-klientens hukommelse til enhedens zram, så spillet får mere RAM. Gælder næste gang Steam starter. - Ikke tilgængeligt: enheden har ingen zram eller swap, eller kernen er ældre end 5.4. Auto sætter på pause i baggrunden og genoptager, når den vises. Manuel venter på Genoptag. Aldrig fortsætter med at køre. Opstart Start Steam med DroidDeck diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index d46e0c5758..c09e49dd7e 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -2529,9 +2529,6 @@ Komplettierer %1$s Std. %1$d Min. - zRAM-Komprimierung - Während ein Spiel läuft, wird der Arbeitsspeicher des Steam-Clients in das zram des Geräts komprimiert, sodass mehr RAM für das Spiel bleibt. Wird beim nächsten Start von Steam angewendet. - Nicht verfügbar: Dieses Gerät hat kein zram oder keinen Swap, oder sein Kernel ist älter als 5.4. Alle Einstellungen zurücksetzen Alle Einstellungen zurücksetzen? Anzeige-, Leistungs-, Controller-, Design-, Sprach- und Launcher-Einstellungen werden auf ihre Standardwerte zurückgesetzt. Deine Spiele, die Steam-Anmeldung, Shop-Konten, heruntergeladene Treiber und Speicherordner bleiben erhalten. diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index dd6458776e..181822f35e 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -287,9 +287,6 @@ Το Αυτόματο θέτει σε παύση και συνεχίζει όταν εμφανίζεται. Το Εγγενής προετοιμάζει πρώτα το Steam για αδρανοποίηση. Το Μη αυτόματο περιμένει το Συνέχιση. Το Ποτέ συνεχίζει να εκτελείται. Διατήρηση των λήψεων σε εξέλιξη Καθυστερεί την αναστολή παρασκηνίου όσο το Steam κάνει ενεργά λήψη. - Συμπίεση zRAM - Όσο τρέχει ένα παιχνίδι, η μνήμη του Steam συμπιέζεται στο zram της συσκευής, ώστε το παιχνίδι να έχει περισσότερη RAM. Ισχύει την επόμενη φορά που θα ξεκινήσει το Steam. - Μη διαθέσιμο: η συσκευή δεν έχει zram ή swap, ή ο πυρήνας είναι παλαιότερος από 5.4. Το Αυτόματο θέτει σε παύση στο παρασκήνιο και συνεχίζει όταν εμφανίζεται. Το Μη αυτόματο περιμένει το Συνέχιση. Το Ποτέ συνεχίζει να εκτελείται. Εκκίνηση Εκκίνηση του Steam με το DroidDeck diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 9060bac1e7..ec99ab7198 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -2564,9 +2564,6 @@ Lo usa el cliente de Steam x86-64 Esta copia está en el cliente de Steam x86-64. Elige x86-64 en Cliente de Steam y desinstálala aquí. Esta copia está en el cliente de Steam ARM64. Elige ARM64 en Cliente de Steam y desinstálala aquí. - Compresión zRAM - Mientras se ejecuta un juego, la memoria del cliente de Steam se comprime en la zram del dispositivo, lo que deja más RAM para el juego. Se aplica la próxima vez que se inicie Steam. - No disponible: este dispositivo no tiene swap activo, o su kernel es anterior a la 5.4. No hay suficiente espacio libre: se necesitan %1$s y solo hay %2$s libres Espacio insuficiente (%1$s libres, se necesitan %2$s) Espacio libre desconocido diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index a6e7493725..ac12cc7e89 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -287,9 +287,6 @@ Automaattinen keskeyttää ja jatkaa, kun sovellus tulee näkyviin. Natiivi valmistelee Steamin lepotilaan ensin. Manuaalinen odottaa Jatka-painiketta. Ei koskaan pitää sovelluksen aina käynnissä. Pidä lataukset käynnissä Viivästytä taustakeskeytystä, kun Steam lataa aktiivisesti. - zRAM-pakkaus - Pelin pyöriessä Steam-asiakkaan muisti pakataan laitteen zramiin, jolloin pelille jää enemmän RAM-muistia. Astuu voimaan, kun Steam käynnistetään seuraavan kerran. - Ei käytettävissä: laitteessa ei ole zramia tai swappia, tai ydin on vanhempi kuin 5.4. Automaattinen keskeyttää taustalla ja jatkaa, kun sovellus tulee näkyviin. Manuaalinen odottaa Jatka-painiketta. Ei koskaan pitää sovelluksen aina käynnissä. Käynnistys Käynnistä Steam DroidDeckin kanssa diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9e7d00dcc7..143d11449b 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -2564,9 +2564,6 @@ Télécharger des composants Les téléchargements sont partagés avec la page « Composants ». Choisissez une version téléchargée ci-dessus pour l\'utiliser au prochain lancement du jeu. Choisissez une version à télécharger - Compression zRAM - Pendant qu\'un jeu tourne, la mémoire du client Steam est compressée dans la zram de l\'appareil, ce qui laisse plus de RAM au jeu. S\'applique au prochain démarrage de Steam. - Indisponible : cet appareil n\'a pas de swap actif, ou son noyau est antérieur à la version 5.4. Espace libre insuffisant : %1$s nécessaires, seulement %2$s libres Espace insuffisant (%1$s libres, %2$s nécessaires) Espace libre inconnu diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index c7d0f6005e..1135072324 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -287,9 +287,6 @@ ऑटो दिखने पर रुकता है और फिर से शुरू होता है। नेटिव पहले Steam को स्लीप के लिए तैयार करता है। मैनुअल फिर से शुरू करें का इंतज़ार करता है। कभी नहीं वाला चलता रहता है। डाउनलोड चलते रहने दें Steam के सक्रिय रूप से डाउनलोड करते समय बैकग्राउंड सस्पेंशन को टालें। - zRAM कम्प्रेशन - गेम चलने के दौरान Steam क्लाइंट की मेमोरी डिवाइस के zram में कम्प्रेस होती है, जिससे गेम को ज़्यादा RAM मिलती है। अगली बार Steam शुरू होने पर लागू होगा। - उपलब्ध नहीं: इस डिवाइस में zram या swap नहीं है, या कर्नेल 5.4 से पुराना है। ऑटो बैकग्राउंड में रुकता है और दिखने पर फिर से शुरू होता है। मैनुअल फिर से शुरू करें का इंतज़ार करता है। कभी नहीं वाला चलता रहता है। स्टार्टअप DroidDeck के साथ Steam शुरू करें diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index c146857a5e..a1638350ab 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -287,9 +287,6 @@ Az Automatikus szüneteltet, és megjelenéskor folytatja. A Natív előbb felkészíti a Steamet az altatásra. A Manuális megvárja a Folytatást. A Soha mindig futva tartja. Letöltések futtatásának fenntartása Elhalasztja a háttérbeli felfüggesztést, amíg a Steam aktívan letölt. - zRAM-tömörítés - Játék közben a Steam kliens memóriája a készülék zramjába tömörül, így a játéknak több RAM jut. A Steam következő indításakor lép életbe. - Nem elérhető: a készüléken nincs zram vagy swap, vagy a kernel régebbi az 5.4-nél. Az Automatikus szüneteltet a háttérben, és megjelenéskor folytatja. A Manuális megvárja a Folytatást. A Soha mindig futva tartja. Indítás Steam indítása a DroidDeckkel diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 8208d2fa3c..61bb207a00 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -287,9 +287,6 @@ Otomatis menjeda dan melanjutkan saat ditampilkan. Native menyiapkan Steam untuk tidur terlebih dahulu. Manual menunggu Lanjutkan. Tidak pernah terus berjalan. Pertahankan unduhan tetap berjalan Menunda penjedaan latar belakang saat Steam sedang aktif mengunduh. - Kompresi zRAM - Saat bermain, memori klien Steam dipadatkan ke zram perangkat sehingga gim mendapat lebih banyak RAM. Berlaku saat Steam dijalankan berikutnya. - Tidak tersedia: perangkat ini tidak punya zram atau swap, atau kernelnya lebih lama dari 5.4. Otomatis menjeda di latar belakang dan melanjutkan saat ditampilkan. Manual menunggu Lanjutkan. Tidak pernah terus berjalan. Mulai Mulai Steam bersama DroidDeck diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 75e4645136..0d8fd58828 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -2554,9 +2554,6 @@ Completista %1$s h %1$d min - Compressione zRAM - Mentre un gioco è in esecuzione, la memoria del client Steam viene compressa nella zram del dispositivo, lasciando più RAM al gioco. Si applica al prossimo avvio di Steam. - Non disponibile: questo dispositivo non ha zram o swap, oppure il suo kernel è precedente alla 5.4. Ripristina tutte le impostazioni Ripristinare tutte le impostazioni? Le impostazioni di schermo, prestazioni, controller, tema, lingua e launcher tornano ai valori predefiniti. Giochi, accesso a Steam, account degli store, driver scaricati e cartelle di archiviazione vengono mantenuti. diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index f1e78ddb83..7b719791fd 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -287,9 +287,6 @@ 自動では一時停止し、表示すると再開します。ネイティブでは先にSteamをスリープに備えさせます。手動では「再開」をタップするまで待機します。「しない」では実行し続けます。 ダウンロードを継続 Steamがダウンロード中は、バックグラウンドでの一時停止を遅らせます。 - zRAM 圧縮 - ゲームの実行中、Steam クライアントのメモリがデバイスの zram に圧縮され、ゲーム用のメモリが増えます。次回 Steam を起動したときに反映されます。 - 使用できません:このデバイスに zram もしくは swap がないか、カーネルが 5.4 未満です。 自動ではバックグラウンドで一時停止し、表示すると再開します。手動では「再開」をタップするまで待機します。「しない」では実行し続けます。 起動 DroidDeck起動時にSteamを起動 diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 6b7efb33ad..0ea3c7b1be 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -287,9 +287,6 @@ 자동: 일시 중지되고 다시 표시되면 재개됩니다. 네이티브: 먼저 Steam을 절전에 대비시킵니다. 수동: \"재개\"를 탭할 때까지 기다립니다. 안 함: 계속 실행됩니다. 다운로드 계속 진행 Steam이 다운로드 중일 때는 백그라운드 일시 중지를 미룹니다. - zRAM 압축 - 게임을 실행하는 동안 Steam 클라이언트의 메모리가 기기의 zram으로 압축되어 게임에 더 많은 메모리가 남습니다. 다음에 Steam을 시작할 때 적용됩니다. - 사용할 수 없음: 이 기기에 zram 또는 swap이 없거나 커널이 5.4 미만입니다. 자동: 백그라운드에서 일시 중지되고 다시 표시되면 재개됩니다. 수동: \"재개\"를 탭할 때까지 기다립니다. 안 함: 계속 실행됩니다. 시작 DroidDeck을 열 때 Steam 시작 diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index ef8c7d5f22..2e3eb1205d 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -287,9 +287,6 @@ Auto menjeda dan menyambung semula apabila dipaparkan. Asli menyediakan Steam untuk tidur dahulu. Manual menunggu Sambung. Jangan sekali-kali terus berjalan. Teruskan muat turun Lambatkan penjedaan latar belakang semasa Steam aktif memuat turun. - Pemampatan zRAM - Semasa bermain, memori klien Steam dimampatkan ke zram peranti supaya permainan mendapat lebih RAM. Berkuat kuasa pada permulaan Steam seterusnya. - Tidak tersedia: peranti ini tiada zram atau swap, atau kernelnya lebih lama daripada 5.4. Auto menjeda di latar belakang dan menyambung semula apabila dipaparkan. Manual menunggu Sambung. Jangan sekali-kali terus berjalan. Permulaan Mulakan Steam bersama DroidDeck diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 5dc36a00c5..e0ee85176d 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -287,9 +287,6 @@ Auto setter på pause og gjenopptar når den vises. Nativ forbereder Steam på hvilemodus først. Manuell venter på Gjenoppta. Aldri lar den fortsette å kjøre. La nedlastinger fortsette Utsetter bakgrunnspause mens Steam laster aktivt ned. - zRAM-komprimering - Mens et spill kjører, komprimeres minnet til Steam-klienten til enhetens zram, slik at spillet får mer RAM. Gjelder neste gang Steam starter. - Ikke tilgjengelig: enheten har ingen zram eller swap, eller kjernen er eldre enn 5.4. Auto setter på pause i bakgrunnen og gjenopptar når den vises. Manuell venter på Gjenoppta. Aldri lar den fortsette å kjøre. Oppstart Start Steam med DroidDeck diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 02b1493d52..93b6ab06fc 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -287,9 +287,6 @@ Automatisch pauzeert en hervat zodra de app weer zichtbaar is. Systeemeigen maakt Steam eerst klaar voor de slaapstand. Handmatig wacht op Hervatten. Nooit laat alles doorlopen. Downloads laten doorlopen Stel onderbreken op de achtergrond uit zolang Steam actief downloadt. - zRAM-compressie - Terwijl een game draait wordt het geheugen van de Steam-client gecomprimeerd naar de zram van het apparaat, zodat de game meer RAM heeft. Geldt de volgende keer dat Steam start. - Niet beschikbaar: dit apparaat heeft geen zram of swap, of de kernel is ouder dan 5.4. Automatisch pauzeert op de achtergrond en hervat zodra de app weer zichtbaar is. Handmatig wacht op Hervatten. Nooit laat alles doorlopen. Opstarten Steam starten met DroidDeck diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index a135e012d7..288e644bae 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -287,9 +287,6 @@ „Auto” wstrzymuje i wznawia po powrocie. „Natywnie” najpierw przygotowuje Steam do uśpienia. „Ręcznie” czeka na „Wznów”. „Nigdy” nie przerywa działania. Nie przerywaj pobierania Opóźnia wstrzymanie w tle, gdy Steam aktywnie pobiera. - Kompresja zRAM - Gdy gra działa, pamięć klienta Steam jest kompresowana do zram urządzenia, więc gra ma więcej RAM-u. Zadziała przy następnym uruchomieniu Steam. - Niedostępne: to urządzenie nie ma zram ani swapu, albo jądro jest starsze niż 5.4. „Auto” wstrzymuje w tle i wznawia po powrocie. „Ręcznie” czeka na „Wznów”. „Nigdy” nie przerywa działania. Uruchamianie Uruchamiaj Steam z DroidDeck diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index b29e753e2d..91e75d38fc 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -2562,9 +2562,6 @@ Repor Repor também os perfis de jogo (Proton, FEX, componentes e ambiente de cada jogo e o ambiente do perfil Padrão) Termine a sessão antes de repor as definições. - Compressão zRAM - Indisponível: este dispositivo não tem swap ativo ou o kernel é anterior à versão 5.4. - Enquanto um jogo está a correr, a memória do cliente Steam é comprimida na zram do dispositivo, deixando mais RAM para o jogo. Aplica-se a partir da próxima vez que o Steam iniciar. Espaço insuficiente (%1$s livres, são necessários %2$s) Espaço livre insuficiente: são necessários %1$s, só há %2$s livres Espaço livre desconhecido diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 79239e0c5a..45bd06550c 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -2554,9 +2554,6 @@ Completista %1$s h %1$d min - Compressão zRAM - Enquanto um jogo roda, a memória do cliente Steam é comprimida na zram do dispositivo, deixando mais RAM para o jogo. Vale a partir da próxima vez que a Steam iniciar. - Indisponível: este dispositivo não tem swap ativo, ou o kernel é anterior à versão 5.4. Redefinir todas as configurações Redefinir todas as configurações? As configurações de tela, desempenho, controle, tema, idioma e inicializador voltam ao padrão. Seus jogos, o login da Steam, as contas das lojas, os drivers baixados e as pastas de armazenamento são mantidos. diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index c0736cfe0c..4b434247a5 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -287,9 +287,6 @@ Automat pune pe pauză și reia atunci când este afișată. Nativ pregătește Steam pentru repaus mai întâi. Manual așteaptă Reluare. Niciodată continuă să ruleze. Continuă descărcările Întârzie suspendarea în fundal cât timp Steam descarcă activ. - Compresie zRAM - În timpul jocului, memoria clientului Steam este comprimată în zram-ul dispozitivului, astfel încât jocul primește mai mult RAM. Se aplică la următoarea pornire a Steam. - Indisponibil: dispozitivul nu are zram sau swap, ori kernelul e mai vechi decât 5.4. Automat pune pe pauză în fundal și reia atunci când este afișată. Manual așteaptă Reluare. Niciodată continuă să ruleze. Pornire Pornește Steam odată cu DroidDeck diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 6e4145bb3a..592685d837 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -2589,9 +2589,6 @@ Скачать компоненты Загрузки общие со страницей «Компоненты». Выберите выше скачанную версию, чтобы использовать её при следующем запуске игры. Выберите версию для скачивания - Сжатие zRAM - Пока идёт игра, память клиента Steam сжимается в zram устройства, и игре остаётся больше ОЗУ. Применяется при следующем запуске Steam. - Недоступно: на устройстве нет zram или swap, либо его ядро старше 5.4. Недостаточно свободного места: нужно %1$s, свободно только %2$s Недостаточно места (свободно %1$s, нужно %2$s) Свободное место неизвестно diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 1da71dc1cb..5f75e21777 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -287,9 +287,6 @@ Auto pausar och återupptar när den visas. Inbyggd förbereder Steam för vila först. Manuell väntar på Återuppta. Aldrig fortsätter köra. Håll nedladdningar igång Skjut upp bakgrundspausning medan Steam aktivt laddar ned. - zRAM-komprimering - Medan ett spel körs komprimeras Steam-klientens minne till enhetens zram så att spelet får mer RAM. Gäller nästa gång Steam startar. - Inte tillgängligt: enheten har ingen zram eller swap, eller så är kärnan äldre än 5.4. Auto pausar i bakgrunden och återupptar när den visas. Manuell väntar på Återuppta. Aldrig fortsätter köra. Uppstart Starta Steam med DroidDeck diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 75dc4f5726..d2c04317c6 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -287,9 +287,6 @@ อัตโนมัติจะหยุดชั่วคราวและดำเนินการต่อเมื่อแสดงผล ดั้งเดิมเตรียม Steam เข้าสู่โหมดพักก่อน กำหนดเองรอการกดดำเนินการต่อ ไม่มีวันทำงานต่อเนื่องตลอด ให้การดาวน์โหลดทำงานต่อไป เลื่อนการหยุดพื้นหลังชั่วคราวออกไปขณะ Steam กำลังดาวน์โหลดอยู่ - การบีบอัด zRAM - ระหว่างเล่นเกม หน่วยความจำของไคลเอนต์ Steam จะถูกบีบอัดลง zram ของอุปกรณ์ ทำให้เกมได้ RAM มากขึ้น มีผลเมื่อเริ่ม Steam ครั้งถัดไป - ใช้ไม่ได้: อุปกรณ์นี้ไม่มี zram หรือ swap หรือเคอร์เนลเก่ากว่า 5.4 อัตโนมัติจะหยุดชั่วคราวเมื่ออยู่ในพื้นหลังและดำเนินการต่อเมื่อแสดงผล กำหนดเองรอการกดดำเนินการต่อ ไม่มีวันทำงานต่อเนื่องตลอด การเริ่มทำงาน เริ่ม Steam พร้อมกับ DroidDeck diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index da288eb3ee..24fc12e92d 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -2531,9 +2531,6 @@ Tamamlayıcı %1$s sa %1$d dk - zRAM sıkıştırma - Bir oyun çalışırken Steam istemcisinin belleği cihazın zram\'ına sıkıştırılır ve oyuna daha fazla RAM kalır. Steam\'in bir sonraki başlatılışında uygulanır. - Kullanılamıyor: bu cihazda zram veya swap yok ya da çekirdeği 5.4\'ten eski. Tüm ayarları sıfırla Tüm ayarlar sıfırlansın mı? Ekran, performans, denetleyici, tema, dil ve başlatıcı ayarları varsayılanlarına döner. Oyunlarınız, Steam oturum bilgileriniz, mağaza hesaplarınız, indirilen sürücüler ve depolama klasörleriniz korunur. diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 002514a82a..0fe47636a7 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -287,9 +287,6 @@ «Авто» призупиняє сеанс і відновлює його, коли додаток знову на екрані. «Нативний» спершу готує Steam до сну. «Вручну» чекає на «Відновити». «Ніколи» — сеанс працює далі. Не переривати завантаження Відкладає призупинення у фоні, поки Steam активно щось завантажує. - Стиснення zRAM - Під час гри пам\'ять клієнта Steam стискається в zram пристрою, тож гра отримує більше RAM. Застосується під час наступного запуску Steam. - Недоступно: на пристрої немає zram або swap, чи ядро старіше за 5.4. «Авто» призупиняє сеанс у фоні й відновлює, коли додаток знову на екрані. «Вручну» чекає на «Відновити». «Ніколи» — сеанс працює далі. Запуск Запускати Steam разом із DroidDeck diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 14e1ffd7e4..c7e88e0653 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -287,9 +287,6 @@ Tự động tạm dừng và tiếp tục khi được hiển thị lại. Gốc chuẩn bị Steam để ngủ trước. Thủ công chờ nhấn Tiếp tục. Không bao giờ giữ nó luôn chạy. Giữ tải xuống tiếp tục chạy Trì hoãn tạm dừng nền khi Steam đang tải xuống. - Nén zRAM - Khi chơi, bộ nhớ của ứng dụng Steam được nén vào zram của thiết bị để game có thêm RAM. Áp dụng từ lần khởi động Steam tiếp theo. - Không khả dụng: thiết bị không có zram hoặc swap, hoặc nhân cũ hơn 5.4. Tự động tạm dừng ở nền và tiếp tục khi hiển thị lại. Thủ công chờ nhấn Tiếp tục. Không bao giờ giữ nó luôn chạy. Khởi động Khởi động Steam cùng DroidDeck diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index f95690ecf1..68d927ebb2 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -287,9 +287,6 @@ 自动会暂停并在显示时恢复。原生会先让 Steam 做好睡眠准备。手动会等待点按恢复。“从不”则保持运行。 后台继续下载 Steam 正在下载时推迟后台暂停。 - zRAM 压缩 - 游戏运行时,Steam 客户端的内存会压缩进设备的 zram,为游戏留出更多内存。下次启动 Steam 时生效。 - 不可用:此设备没有 zram 或 swap,或其内核低于 5.4。 自动会在后台暂停并在显示时恢复。手动会等待点按恢复。“从不”则保持运行。 启动 随 DroidDeck 启动 Steam diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index eab8f68379..a39c7b101d 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -287,9 +287,6 @@ 「自動」會暫停,並在重新顯示時繼續;「原生」會先讓 Steam 準備好休眠;「手動」會等你按「繼續」;「從不」會保持執行。 保持下載進行 Steam 正在下載時,延遲在背景暫停。 - zRAM 壓縮 - 遊戲運行時,Steam 用戶端的記憶體會壓縮進裝置的 zram,為遊戲騰出更多記憶體。下次啟動 Steam 時生效。 - 無法使用:此裝置沒有 zram 或 swap,或核心版本低於 5.4。 「自動」會在背景時暫停,並在重新顯示時繼續;「手動」會等你按「繼續」;「從不」會保持執行。 啟動 隨 DroidDeck 啟動 Steam diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index af4ac4b745..d29f3cef46 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -287,9 +287,6 @@ 「自動」會暫停,並在重新顯示時繼續。「原生」會先讓 Steam 做好睡眠準備。「手動」會等你點擊「繼續」。「從不」則會持續執行。 讓下載持續進行 Steam 正在下載時,延後在背景暫停。 - zRAM 壓縮 - 遊戲執行時,Steam 用戶端記憶體會壓縮進裝置的 zram,為遊戲騰出更多記憶體。下次啟動 Steam 時生效。 - 無法使用:此裝置沒有 zram 或 swap,或核心版本低於 5.4。 「自動」會在背景時暫停,並在重新顯示時繼續。「手動」會等你點擊「繼續」。「從不」則會持續執行。 啟動 隨 DroidDeck 啟動 Steam diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 312dcd2c79..c449a05be5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -292,9 +292,6 @@ Auto pauses and resumes when shown. Native prepares Steam for sleep first. Manual waits for Resume. Never keeps running. Keep downloads running Delay background suspension while Steam is actively downloading. - zRAM compression - While a game runs, the Steam client\'s memory is compressed into the device\'s zram, leaving more RAM for the game. Applies the next time Steam starts. - Unavailable: this device has no zram or swap, or its kernel is older than 5.4. Auto pauses in the background and resumes when shown. Manual waits for Resume. Never keeps running. Startup Start Steam with DroidDeck diff --git a/app/src/main/rust/stores/src/amazon/library.rs b/app/src/main/rust/stores/src/amazon/library.rs index ec9ba55f86..46360a907b 100644 --- a/app/src/main/rust/stores/src/amazon/library.rs +++ b/app/src/main/rust/stores/src/amazon/library.rs @@ -21,6 +21,7 @@ pub struct Game { pub parent_product_id: String, pub art: String, pub hero: String, + pub logo: String, pub developer: String, pub publisher: String, } @@ -39,6 +40,7 @@ impl Game { "sku": self.sku, "art": self.art, "hero": self.hero, + "logo": self.logo, "developer": self.developer, "publisher": self.publisher, "dlc": self.is_dlc(), @@ -83,6 +85,7 @@ pub fn read_entitlement(e: &Value) -> Option { ], ) .to_string(), + logo: str_at(product, &["productDetail", "details", "logoUrl"]).to_string(), developer: str_at(product, &["productDetail", "details", "developer"]).to_string(), publisher: str_at(product, &["productDetail", "details", "publisher"]).to_string(), }) @@ -178,17 +181,20 @@ mod tests { fn entitlement_fields_and_fallbacks() { let e = json!({"id":"ent-1","product":{"id":"amzn1.adg.product.x","title":"Game","sku":"SKU1", "productDetail":{"iconUrl":"","details":{"pgCrownImageUrl":"crown","backgroundUrl1":"bg1", - "developer":"Dev","publisher":"Pub","productType":"GAME"}}}}); + "logoUrl":"logo","developer":"Dev","publisher":"Pub","productType":"GAME"}}}}); let g = read_entitlement(&e).unwrap(); assert_eq!(g.entitlement_id, "ent-1"); assert_eq!(g.art, "crown"); assert_eq!(g.hero, "bg1"); + assert_eq!(g.logo, "logo"); + assert_eq!(g.to_json()["logo"], "logo"); assert_eq!(g.product_type, "GAME"); assert!(!g.is_dlc()); let untitled = read_entitlement(&json!({"product":{"id":"p","type":"DLC","baseProductId":"q"}})).unwrap(); assert_eq!(untitled.title, "Unknown"); assert_eq!(untitled.entitlement_id, ""); assert_eq!(untitled.parent_product_id, "q"); + assert_eq!(untitled.logo, ""); assert!(untitled.is_dlc()); assert!(read_entitlement(&json!({"id":"x"})).is_none()); assert!(read_entitlement(&json!({"id":"x","product":{"id":""}})).is_none()); diff --git a/app/src/main/rust/stores/src/epic/catalog.rs b/app/src/main/rust/stores/src/epic/catalog.rs index 4589ce276b..420d656e80 100644 --- a/app/src/main/rust/stores/src/epic/catalog.rs +++ b/app/src/main/rust/stores/src/epic/catalog.rs @@ -71,6 +71,7 @@ pub fn details_of(entry: &Value) -> Value { "releaseDate": release, "tall": image(entry, &["DieselGameBoxTall"]), "wide": image(entry, &["DieselGameBox", "Thumbnail"]), + "logo": image(entry, &["DieselGameBoxLogo"]), "canRunOffline": offline, "dlc": main_game.is_some_and(|m| !m.is_null()), "mainGameId": main_game.map(|m| net::str_of(m, "id")).unwrap_or(""), @@ -102,7 +103,8 @@ mod tests { "keyImages": [ {"type": "Thumbnail", "url": "thumb"}, {"type": "DieselGameBox", "url": ""}, - {"type": "DieselGameBoxTall", "url": "tall"} + {"type": "DieselGameBoxTall", "url": "tall"}, + {"type": "DieselGameBoxLogo", "url": "logo"} ], "customAttributes": {"CanRunOffline": {"value": "FALSE"}, "publisherName": {"value": " Pub "}}, "seller": {"name": "Seller"}, @@ -113,6 +115,7 @@ mod tests { assert_eq!(d["title"], "Game"); assert_eq!(d["tall"], "tall"); assert_eq!(d["wide"], "thumb"); + assert_eq!(d["logo"], "logo"); assert_eq!(d["publisher"], "Pub"); assert_eq!(d["canRunOffline"], false); assert_eq!(d["releaseDate"], "2020-01-01T00:00:00.000Z"); @@ -123,6 +126,7 @@ mod tests { assert_eq!(dlc["publisher"], "S"); assert_eq!(dlc["releaseDate"], "v"); assert_eq!(dlc["canRunOffline"], true); + assert_eq!(dlc["logo"], ""); assert_eq!(pick_entry(&json!({"x": {"title": "Only"}}), "y").unwrap()["title"], "Only"); } } diff --git a/app/src/test/java/com/droiddeck/launcher/core/ZramSupportTest.kt b/app/src/test/java/com/droiddeck/launcher/core/ZramSupportTest.kt index 056e3a0553..033efb578d 100644 --- a/app/src/test/java/com/droiddeck/launcher/core/ZramSupportTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/core/ZramSupportTest.kt @@ -14,20 +14,6 @@ class ZramSupportTest { assertFalse(ZramSupport.kernelAtLeast("", 5, 4)) } - @Test - fun underTwelveGbFromAdvertisedOrTotalMemory() { - val gb = 1_000_000_000L - val gib = 1L shl 30 - assertTrue(ZramSupport.belowTwelveGb(8 * gb, 0)) - assertTrue(ZramSupport.belowTwelveGb(8 * gib, 0)) - assertFalse(ZramSupport.belowTwelveGb(12 * gb, 0)) - assertFalse(ZramSupport.belowTwelveGb(12 * gib, 0)) - assertTrue(ZramSupport.belowTwelveGb(0, 7_400_000L * 1024)) - assertTrue(ZramSupport.belowTwelveGb(0, 9_300_000L * 1024)) - assertFalse(ZramSupport.belowTwelveGb(0, 11_100_000L * 1024)) - assertFalse(ZramSupport.belowTwelveGb(0, 15_600_380L * 1024)) - } - @Test fun swapTotalComesFromMeminfo() { assertEquals(12582908L, ZramSupport.swapTotalKb(listOf("MemTotal: 15600380 kB", "SwapTotal: 12582908 kB"))) diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/AddedGameArtFillTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGameArtFillTest.kt new file mode 100644 index 0000000000..473c43922a --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/frontend/AddedGameArtFillTest.kt @@ -0,0 +1,163 @@ +package com.droiddeck.launcher.frontend + +import com.droiddeck.launcher.frontend.AddedGameArt.Slot +import com.droiddeck.launcher.session.SessionPrefs +import org.junit.Assert.assertArrayEquals +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Assert.fail +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33]) +class AddedGameArtFillTest { + private val app get() = RuntimeEnvironment.getApplication() + @get:Rule val tmp = TemporaryFolder() + + private val coverBytes = byteArrayOf(9, 9, 9) + + private fun game(name: String, appId: Long, cover: Boolean = true, source: String = Library.ADDED): AddedGames.Game { + val dir = tmp.newFolder(name) + File(dir, "steam_appid.txt").writeText("504230") + if (cover) File(dir, "cover.jpg").writeBytes(coverBytes) + val exe = File(dir, "$name.exe").apply { writeText("x") } + return AddedGames.Game(dir, name, exe, "/g/$name.exe", "/g", appId, appId, emptyList(), source = source) + } + + private class Calls { + val steam = ArrayList>() + val sgdb = ArrayList>() + var lookups = 0 + var store = 0 + } + + private val steamNames = mapOf(Slot.COVER to "p.jpg", Slot.WIDE to "header.jpg", Slot.BACKGROUND to "hero.jpg", Slot.LOGO to "logo.png") + + private fun sources( + calls: Calls, steamHas: Set = emptySet(), sgdbHas: Set = emptySet(), + storeHas: Boolean = false, sgdbFails: Boolean = false, + ) = AddedGameArt.Sources( + storeLogo = { g -> + calls.store++ + if (storeHas) File(g.folder, "logo.png").writeBytes(byteArrayOf(4)) + storeHas + }, + steamSearch = { fail("searched although the game names its appid"); null }, + steam = { id, cache, slots -> + assertEquals("504230", id) + calls.steam += slots + (slots intersect steamHas).onEach { File(cache, steamNames.getValue(it)).writeBytes(byteArrayOf(1)) }.isNotEmpty() + }, + sgdbGame = { _, steamId, _ -> + calls.lookups++ + assertEquals(504230, steamId) + 77 + }, + sgdb = { _, id, cache, slots -> + assertEquals(77, id) + if (sgdbFails) throw SteamGridDb.Failed(SteamGridDb.Status.OFFLINE) + calls.sgdb += slots + (slots intersect sgdbHas).onEach { File(cache, SteamGridDb.cacheName(it)).writeBytes(byteArrayOf(2)) }.isNotEmpty() + }, + ) + + @Test fun aGameWithItsOwnCoverStillGetsItsLogoAndIcon() { + val g = game("Celeste", 0x81000001L) + val calls = Calls() + assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls, steamHas = setOf(Slot.LOGO), sgdbHas = setOf(Slot.ICON)))) + assertEquals(listOf(setOf(Slot.LOGO)), calls.steam) + assertEquals(listOf(setOf(Slot.ICON)), calls.sgdb) + assertEquals(0, calls.store) + val cache = AddedGameArt.cacheDir(app, g) + assertFalse(File(cache, "p.jpg").exists()) + assertArrayEquals(coverBytes, File(g.folder, "cover.jpg").readBytes()) + val art = AddedGameArt.resolve(app, g) + assertEquals(File(g.folder, "cover.jpg"), art.portrait) + assertEquals(File(cache, "logo.png"), art.logo) + assertEquals(File(cache, "icon-sgdb.png"), art.icon) + assertFalse(File(cache, AddedGameArt.EXTRAS_TRIED).exists()) + } + + @Test fun filledOrChosenSlotsAreNeverAskedFor() { + val g = game("Hades", 0x81000002L) + File(g.folder, "logo.png").writeBytes(byteArrayOf(5)) + val picked = File(tmp.root, "mine.png").apply { writeBytes(byteArrayOf(6)) } + assertTrue(AddedGameArt.store(AddedGameArt.cacheDir(app, g), Slot.ICON, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path))) + val calls = Calls() + assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls, steamHas = Slot.values().toSet(), sgdbHas = Slot.values().toSet()))) + assertTrue(calls.steam.isEmpty() && calls.sgdb.isEmpty() && calls.lookups == 0) + assertArrayEquals(byteArrayOf(5), File(g.folder, "logo.png").readBytes()) + } + + @Test fun withoutAKeyAMissingIconAloneAsksNothing() { + val g = game("Inside", 0x81000003L) + File(g.folder, "logo.png").writeBytes(byteArrayOf(5)) + val calls = Calls() + assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "", sources(calls))) + assertTrue(calls.steam.isEmpty() && calls.sgdb.isEmpty() && calls.lookups == 0) + assertFalse(AddedGameArt.cacheDir(app, g).exists()) + } + + @Test fun aMissIsAskedAgainOnlyAfterAWeek() { + val g = game("Limbo", 0x81000004L) + val calls = Calls() + assertFalse(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls))) + assertEquals(listOf(setOf(Slot.LOGO)), calls.steam) + assertEquals(listOf(setOf(Slot.LOGO, Slot.ICON)), calls.sgdb) + AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls)) + assertEquals(1, calls.steam.size) + assertEquals(1, calls.sgdb.size) + val tried = File(AddedGameArt.cacheDir(app, g), AddedGameArt.EXTRAS_TRIED) + assertTrue(tried.setLastModified(System.currentTimeMillis() - 8L * 24 * 3600 * 1000)) + assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls, steamHas = setOf(Slot.LOGO), sgdbHas = setOf(Slot.ICON)))) + assertEquals(2, calls.steam.size) + assertEquals(setOf(Slot.ICON), calls.sgdb.last()) + assertFalse(tried.exists()) + } + + @Test fun theStoresOwnLogoComesFirst() { + val g = game("Metalstorm", 0x81000005L, source = "gog") + val calls = Calls() + assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "key", sources(calls, storeHas = true, steamHas = setOf(Slot.LOGO), sgdbHas = setOf(Slot.ICON)))) + assertEquals(1, calls.store) + assertTrue(calls.steam.isEmpty()) + assertEquals(listOf(setOf(Slot.ICON)), calls.sgdb) + assertEquals(File(g.folder, "logo.png"), AddedGameArt.resolve(app, g).logo) + } + + @Test fun aGameWithoutACoverStillGetsEverySlot() { + val g = game("Tunic", 0x81000006L, cover = false) + val calls = Calls() + assertTrue(AddedGameArt.fetchMissing(app, listOf(g), "key", + sources(calls, steamHas = setOf(Slot.COVER, Slot.WIDE, Slot.BACKGROUND), sgdbHas = setOf(Slot.LOGO, Slot.ICON)))) + assertEquals(listOf(setOf(Slot.COVER, Slot.WIDE, Slot.BACKGROUND, Slot.LOGO)), calls.steam) + assertEquals(listOf(setOf(Slot.LOGO, Slot.ICON)), calls.sgdb) + assertTrue(AddedGameArt.missing(app, g).isEmpty()) + } + + @Test fun aSteamGridDbFailureIsNotRememberedAndStopsThePass() { + val first = game("Gris", 0x81000007L) + val second = game("Hollow", 0x81000008L) + val calls = Calls() + AddedGameArt.fetchMissing(app, listOf(first, second), "key", sources(calls, sgdbFails = true)) + assertEquals(2, calls.steam.size) + assertEquals(1, calls.lookups) + assertFalse(File(AddedGameArt.cacheDir(app, first), AddedGameArt.EXTRAS_TRIED).exists()) + assertFalse(File(AddedGameArt.cacheDir(app, second), AddedGameArt.EXTRAS_TRIED).exists()) + } + + @Test fun nothingIsFetchedWhenArtIsOff() { + SessionPrefs.setAddedGamesArt(app, false) + val calls = Calls() + assertFalse(AddedGameArt.fetchMissing(app, listOf(game("Off", 0x81000009L)), "key", sources(calls))) + assertTrue(calls.steam.isEmpty()) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/GameLaunchLinkTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/GameLaunchLinkTest.kt index 9493a630b4..1fbd8c4914 100644 --- a/app/src/test/java/com/droiddeck/launcher/frontend/GameLaunchLinkTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/frontend/GameLaunchLinkTest.kt @@ -4,7 +4,7 @@ import android.content.Intent import android.net.Uri import android.app.Activity import com.droiddeck.launcher.LauncherIcon -import com.droiddeck.launcher.MainActivity +import com.droiddeck.launcher.FrontEndActivity import com.droiddeck.launcher.frontend.Library import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull @@ -54,7 +54,7 @@ class GameShortcutIntentTest { assertEquals(Intent.ACTION_VIEW, intent.action) assertEquals(Uri.parse("droiddeck://game/$id"), intent.data) - assertEquals(MainActivity::class.java.name, intent.component?.className) + assertEquals(FrontEndActivity::class.java.name, intent.component?.className) assertEquals(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP or android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP, intent.flags) } @@ -69,8 +69,8 @@ class GameShortcutIntentTest { val launch = requireNotNull(shortcut.intent) assertEquals("game:8400", shortcut.id) assertEquals("Geometry Wars: Retro Evolved", shortcut.shortLabel.toString()) - assertEquals("com.droiddeck.launcher.LauncherDark", shortcut.activity?.className) - assertEquals(MainActivity::class.java.name, launch.component?.className) + assertEquals("com.droiddeck.launcher.MainActivity", shortcut.activity?.className) + assertEquals(FrontEndActivity::class.java.name, launch.component?.className) assertEquals(Intent.ACTION_VIEW, launch.action) assertEquals(Uri.parse("droiddeck://game/8400"), launch.data) assertEquals(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP, launch.flags) @@ -93,4 +93,38 @@ class GameShortcutIntentTest { assertNotNull(GameShortcuts.result(activity, game)) } + + @Test fun theDefaultLauncherEntryKeepsTheMainActivityName() { + val activity = Robolectric.buildActivity(Activity::class.java).setup().get() + val launchers = activity.packageManager.queryIntentActivities( + Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setPackage(activity.packageName), 0) + + assertEquals(listOf("com.droiddeck.launcher.MainActivity"), launchers.map { it.activityInfo.name }) + assertEquals(android.content.ComponentName(activity, "com.droiddeck.launcher.MainActivity"), LauncherIcon.activity(activity)) + } + + @Test fun repairDropsTheDefaultIconLeftBesideAChosenLightIcon() { + val activity = Robolectric.buildActivity(Activity::class.java).setup().get() + val pm = activity.packageManager + pm.setComponentEnabledSetting(android.content.ComponentName(activity, "com.droiddeck.launcher.LauncherLight"), + android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED, android.content.pm.PackageManager.DONT_KILL_APP) + val dark = android.content.ComponentName(activity, "com.droiddeck.launcher.MainActivity") + + LauncherIcon.repair(activity, dark) + assertEquals(android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, pm.getComponentEnabledSetting(dark)) + + LauncherIcon.repair(activity, android.content.ComponentName(activity, "com.droiddeck.launcher.LauncherLight")) + assertEquals(android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED, pm.getComponentEnabledSetting(dark)) + assertEquals(LauncherIcon.LIGHT, LauncherIcon.current(activity)) + } + + @Test fun repairLeavesASingleIconAlone() { + val activity = Robolectric.buildActivity(Activity::class.java).setup().get() + val dark = android.content.ComponentName(activity, "com.droiddeck.launcher.MainActivity") + + LauncherIcon.repair(activity, null) + + assertEquals(android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, activity.packageManager.getComponentEnabledSetting(dark)) + assertEquals(LauncherIcon.DARK, LauncherIcon.current(activity)) + } } diff --git a/app/src/test/java/com/droiddeck/launcher/frontend/GameLogoTest.kt b/app/src/test/java/com/droiddeck/launcher/frontend/GameLogoTest.kt new file mode 100644 index 0000000000..5a577f5b37 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/frontend/GameLogoTest.kt @@ -0,0 +1,80 @@ +package com.droiddeck.launcher.frontend + +import com.droiddeck.launcher.session.SessionPrefs +import org.json.JSONArray +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33]) +class GameLogoTest { + private val app get() = RuntimeEnvironment.getApplication() + @get:Rule val tmp = TemporaryFolder() + + @Before fun noGamesFolders() { + AddedGamesPublisher.now = true + SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") + SessionPrefs.setAddedGamesDirs(app, emptyList()) + } + + private fun image(name: String) = File(tmp.root, name).apply { parentFile?.mkdirs(); writeBytes(ByteArray(8) { 1 }) } + + @Test fun steamsCachedLogoIsFoundInTheAppFolderOrAHashedOne() { + val cache = tmp.newFolder("librarycache") + val logo = File(cache, "620/3f1c/logo.png").apply { parentFile?.mkdirs(); writeBytes(ByteArray(4) { 1 }) } + assertEquals(logo, Library.steamCacheImage(cache, 620, Library.STEAM_LOGOS)) + File(cache, "730").mkdirs() + File(cache, "730/logo.png").writeBytes(ByteArray(0)) + assertNull(Library.steamCacheImage(cache, 730, Library.STEAM_LOGOS)) + } + + @Test fun aChosenLogoWinsOverSteamsAndKeepsTheRest() { + val stock = image("logo.png") + val game = Library.SteamGame(620, "Portal 2", null, "Steam library", logo = stock) + assertTrue(SteamGameArt.withOverrides(app, game) === game) + val picked = image("mine.png") + assertTrue(SteamGameArt.choose(app, game, AddedGameArt.Slot.LOGO, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path))) + val shown = SteamGameArt.withOverrides(app, game) + assertTrue(shown.logo!!.name.startsWith("chosen-logo")) + assertNull(shown.art) + SteamGameArt.reset(app, game, AddedGameArt.Slot.LOGO) + assertEquals(stock, SteamGameArt.withOverrides(app, game).logo) + } + + @Test fun anAddedGameShowsItsFolderLogoUnlessOneWasChosen() { + val dir = tmp.newFolder("Celeste") + val own = File(dir, "logo.png").apply { writeBytes(ByteArray(4) { 1 }) } + val exe = File(dir, "Celeste.exe").apply { writeText("x") } + val g = AddedGames.Game(dir, "Celeste", exe, "/g/Celeste.exe", "/g", 0x82000001L, 0x82000001L, emptyList(), source = "gog") + assertEquals(own, Library.addedGame(app, g, emptyList()).logo) + val picked = image("pick.png") + assertTrue(AddedGameArt.choose(app, g, AddedGameArt.Slot.LOGO, AddedGameArt.Option(AddedGameArt.FILE, picked.path, picked.path))) + assertTrue(Library.addedGame(app, g, emptyList()).logo!!.name.startsWith("chosen-logo")) + val bare = AddedGames.Game(tmp.newFolder("Bare"), "Bare", exe, "/g/Bare.exe", "/g", 0x82000002L, 0x82000002L, emptyList()) + assertNull(Library.addedGame(app, bare, emptyList()).logo) + } + + @Test fun theLibraryCacheKeepsTheLogoAndReadsOlderEntries() { + val logo = image("logo.png") + val game = Library.SteamGame(620, "Portal 2", null, "Steam library", logo = logo) + LibraryCache.save(app, listOf(game, Library.SteamGame(730, "CS2", null, "Steam library"))) + val back = LibraryCache.load(app) + assertEquals(logo, back[0].logo) + assertNull(back[1].logo) + assertEquals(logo, game.withArt(null, null, null).logo) + val file = File(app.filesDir, "library-cache.json") + file.writeText(JSONArray().put(JSONObject().put("appId", 1).put("name", "Old").put("library", "x").put("gameId", 1L)).toString()) + assertNull(LibraryCache.load(app).single().logo) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionSleepRequestTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionSleepRequestTest.kt new file mode 100644 index 0000000000..b136d5fd01 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionSleepRequestTest.kt @@ -0,0 +1,77 @@ +package com.droiddeck.launcher.session + +import android.os.Looper +import java.util.concurrent.AbstractExecutorService +import java.util.concurrent.TimeUnit +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.Robolectric +import org.robolectric.RobolectricTestRunner +import org.robolectric.Shadows.shadowOf +import org.robolectric.annotation.Config +import org.robolectric.annotation.LooperMode +import org.robolectric.util.ReflectionHelpers + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33]) +@LooperMode(LooperMode.Mode.PAUSED) +class SessionSleepRequestTest { + private lateinit var service: SessionService + private val work = ArrayDeque() + private val executor = object : AbstractExecutorService() { + override fun execute(command: Runnable) { work.addLast(command) } + override fun shutdown() {} + override fun shutdownNow(): MutableList = mutableListOf() + override fun isShutdown() = false + override fun isTerminated() = false + override fun awaitTermination(timeout: Long, unit: TimeUnit) = false + } + + @Before fun setUp() { + service = Robolectric.buildService(SessionService::class.java).get() + SessionState.running = true + SessionState.suspended = false + SessionState.mode = SessionService.MODE_RUN + ReflectionHelpers.setField(service, "suspendPolicy", SessionPrefs.SUSPEND_NEVER) + ReflectionHelpers.setField(service, "suspendController", SessionSuspendController( + sessionRoot = { -1 }, helperRoots = { emptyList() }, + suspendAudio = {}, resumeAudio = {}, executor = executor, + )) + } + + @After fun tearDown() { + SessionState.running = false + SessionState.suspended = false + SessionState.mode = SessionService.MODE_STEAM + shadowOf(Looper.getMainLooper()).idle() + work.clear() + } + + @Test fun cancelledFreezePreservesAndRetriesANewerSteamRequest() { + ReflectionHelpers.setField(service, "steamSleepToken", "old-request") + ReflectionHelpers.callInstanceMethod(service, "updateSuspendPolicy") + assertEquals(1, work.size) + ReflectionHelpers.setField(service, "freezeCancelled", true) + ReflectionHelpers.setField(service, "steamSleepToken", "new-request") + work.removeFirst().run() + shadowOf(Looper.getMainLooper()).idle() + assertEquals("new-request", ReflectionHelpers.getField(service, "steamSleepToken")) + assertEquals(1, work.size) + assertFalse(ReflectionHelpers.getField(service, "suspendAttemptFailed")) + } + + @Test fun cancelledFreezeCompletesItsOwnRequestWithoutRetryingIt() { + ReflectionHelpers.setField(service, "steamSleepToken", "old-request") + ReflectionHelpers.callInstanceMethod(service, "updateSuspendPolicy") + ReflectionHelpers.setField(service, "freezeCancelled", true) + work.removeFirst().run() + shadowOf(Looper.getMainLooper()).idle() + assertEquals(null, ReflectionHelpers.getField(service, "steamSleepToken")) + assertEquals(0, work.size) + assertFalse(ReflectionHelpers.getField(service, "suspendAttemptFailed")) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionSuspendControllerTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionSuspendControllerTest.kt index 61e95da495..02b38143ee 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionSuspendControllerTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionSuspendControllerTest.kt @@ -26,6 +26,66 @@ class SessionSuspendControllerTest { } } + @Test fun pageOutRunsInPreloadedGuestsBeforeTheyStop() { + val fixture = fixture(17) + fixture.control.writeText("0") + fixture.controller.freeze(pageOut = true) { assertTrue(it) } + val urgent = fixture.signals.filter { it.signal == URG } + assertEquals(listOf(GAME), urgent.map { it.pid }) + assertTrue(fixture.signals.indexOfFirst { it.signal == URG } < fixture.signals.indexOfFirst { it.signal == STOP }) + assertEquals("1", fixture.control.readText()) + assertEquals(listOf(Triple(1, 1_000_000L, 3_000_000L)), fixture.pagedOut) + assertEquals(0, fixture.unacknowledged) + assertTrue(fixture.game.threads.all { it.state == 't' }) + assertFalse(File(fixture.control.parentFile, ".bl-zram.ack.$GAME").exists()) + } + + @Test fun unchangedSwapIsNotTakenForAFinishedPageOut() { + val fixture = fixture(17) + fixture.control.writeText("0") + fixture.handlerStalls = true + var stoppedEarly = false + fixture.afterSleep = { + if (fixture.now == 3000L) fixture.handlerStalls = false + if (fixture.handlerStalls && fixture.signals.any { it.signal == STOP }) stoppedEarly = true + } + fixture.controller.freeze(pageOut = true) { assertTrue(it) } + assertFalse(stoppedEarly) + assertEquals(0, fixture.unacknowledged) + } + + @Test fun replacedHandlerIsNotWaitedForPastTheStartWindow() { + val fixture = fixture(17) + fixture.control.writeText("0") + fixture.handlerReplaced = true + fixture.controller.freeze(pageOut = true) { assertTrue(it) } + assertEquals(1, fixture.unacknowledged) + assertTrue(fixture.now in 2000L..3000L) + } + + @Test fun cancelledFreezeRollsBackWithoutStopping() { + val fixture = fixture(17) + fixture.control.writeText("0") + fixture.handlerStalls = true + fixture.afterSleep = { if (fixture.now >= 500) fixture.controller.cancelFreeze() } + fixture.controller.freeze(pageOut = true) { assertFalse(it) } + assertFalse(fixture.signals.any { it.signal == STOP }) + assertTrue(fixture.game.threads.all { it.state == 'S' }) + assertEquals(1, fixture.audioResumes) + } + + @Test fun noPageOutWithoutTheRequestOrTheControlFile() { + val visible = fixture(17) + visible.control.writeText("0") + visible.controller.freeze { assertTrue(it) } + assertFalse(visible.signals.any { it.signal == URG }) + assertEquals("0", visible.control.readText()) + val disabled = fixture(17) + disabled.controller.freeze(pageOut = true) { assertTrue(it) } + assertFalse(disabled.signals.any { it.signal == URG }) + assertTrue(disabled.pagedOut.isEmpty()) + } + @Test fun cpuMustBeStableAcrossTwoCompleteSnapshots() { val fixture = fixture(17) var changes = 0 @@ -253,13 +313,13 @@ class SessionSuspendControllerTest { } private fun fixture(count: Int, executor: QueueExecutor = InlineExecutor()) = - Fixture(temporary.newFolder(), count, executor) + Fixture(temporary.newFolder(), temporary.newFolder(), count, executor) private data class Task(val tid: Int, var started: Long, var state: Char, var cpu: Long = 0) private data class Group(val pid: Int, var parent: Int, var tracer: Int, val threads: MutableList) private data class SentSignal(val pid: Int, val signal: Int) - private class Fixture(val proc: File, count: Int, executor: QueueExecutor) { + private class Fixture(val proc: File, tmp: File, count: Int, executor: QueueExecutor) { val root = Group(ROOT, 9000, 0, mutableListOf(Task(ROOT, 1000, 'S'))) val game = Group(GAME, ROOT, ROOT, MutableList(count) { Task(GAME + it, 2000L + it, 'S') }) val groups = mutableListOf(root, game) @@ -276,10 +336,23 @@ class SessionSuspendControllerTest { var emptyGameTasks = false var rootGone = false var afterSleep: (() -> Unit)? = null + val control = File(tmp, ".bl-zram") + val pagedOut = mutableListOf>() + private var gameResidentKb = 4_000_000L + private var gameSwapKb = 0L + private var pagingOut = false + var unacknowledged = -1 + var handlerStalls = false + var handlerReplaced = false private var continuing = false val controller = SessionSuspendController( { rootPid }, { helpers }, { audioSuspends++ }, { audioResumes++ }, proc, ::signal, ::threadSignal, ::sleep, { now }, executor, + zramControl = control, + pagedOut = { processes, unacknowledged, resident, swap, _, _ -> + pagedOut += Triple(processes, resident, swap) + this.unacknowledged = unacknowledged + }, ) init { sync() } @@ -293,6 +366,8 @@ class SessionSuspendControllerTest { else group.threads.firstOrNull { it.state !in listOf('T', 't', 'Z', 'X') && !(neverStop && it == game.threads.last()) }?.state = 't' + } else if (signal == URG) { + pagingOut = true } else if (signal == CONT) { continuing = true if (!(pid == GAME && blockGameContinue)) group.threads.forEach { if (it.state != 'Z') it.state = 'S' } @@ -311,6 +386,18 @@ class SessionSuspendControllerTest { private fun sleep(millis: Long) { now += millis + if (pagingOut && !handlerReplaced) { + File(control.parentFile, "${control.name}.ack.$GAME").apply { if (!exists()) writeText("") } + } + if (pagingOut && !handlerStalls && !handlerReplaced) { + if (gameResidentKb > 1_000_000L) { + gameResidentKb -= 1_000_000L + gameSwapKb += 1_000_000L + } else { + File(control.parentFile, "${control.name}.ack.$GAME").writeText("1") + pagingOut = false + } + } if (root.threads.first().state != 'T' && !continuing) game.threads.forEach { if (it.state != 'Z') { it.state = 'S'; it.cpu++ } } @@ -326,7 +413,11 @@ class SessionSuspendControllerTest { val stat = File(dir, "stat") if (group == game && missingGameStat) stat.delete() else stat.writeText(stat(group, group.threads.first())) - File(dir, "status").writeText("TracerPid: ${group.tracer}\n") + File(dir, "status").writeText( + "TracerPid: ${group.tracer}\n" + + if (group == game) "VmRSS:\t$gameResidentKb kB\nVmSwap:\t$gameSwapKb kB\n" else "", + ) + if (group == game) File(dir, "maps").writeText("7f00000000-7f00001000 r-xp 00000000 fe:05 42 /usr/local/lib/libblsession.so\n") val taskDir = File(dir, "task") if (group == game && missingGameTasks) { taskDir.deleteRecursively(); continue } taskDir.mkdirs() @@ -375,5 +466,6 @@ class SessionSuspendControllerTest { const val GAME = 200 const val STOP = 19 const val CONT = 18 + const val URG = 23 } } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/StoreAccountsCipherTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/StoreAccountsCipherTest.kt index e0c657a147..2dde17cab1 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/StoreAccountsCipherTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/StoreAccountsCipherTest.kt @@ -131,6 +131,25 @@ class StoreAccountsCipherTest { assertEquals("test@example.test", StoreAccounts.signedInAs(app, Store.XBOX)) } + @Test fun xboxShowsTheGamertagElseAMaskedEmail() { + StoreAccounts.write(app, Store.XBOX, JSONObject().put("username", "player@example.test")) + assertEquals("p•••@example.test", StoreAccounts.displayName(app, Store.XBOX)) + StoreAccounts.write(app, Store.XBOX, JSONObject().put("username", "player@example.test").put("gamertag", "Some Gamertag")) + assertEquals("Some Gamertag", StoreAccounts.displayName(app, Store.XBOX)) + assertEquals("player@example.test", StoreAccounts.signedInAs(app, Store.XBOX)) + StoreAccounts.write(app, Store.EPIC, creds) + assertEquals("Someone", StoreAccounts.displayName(app, Store.EPIC)) + assertEquals("n•••", StoreAccounts.maskEmail("nickname")) + } + + @Test fun xboxDisplayNameDoesNotRevealEmailWhenCredentialsAreTemporarilyUnavailable() { + StoreAccounts.write(app, Store.XBOX, JSONObject().put("username", "player@example.test")) + StoreAccounts.keys = Flaky(key, 1) { java.security.ProviderException("busy") } + assertEquals(Store.XBOX.label, StoreAccounts.displayName(app, Store.XBOX)) + assertTrue(StoreAccounts.isUnavailable(Store.XBOX)) + assertTrue(file(Store.XBOX).exists()) + } + @Test fun signOutRemovesTheFile() { StoreAccounts.write(app, Store.GOG, creds) StoreAccounts.clear(app, Store.GOG) diff --git a/app/src/test/java/com/droiddeck/launcher/stores/StoreGameSidecarTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/StoreGameSidecarTest.kt index 213cbf9a14..b7ad90b56d 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/StoreGameSidecarTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/StoreGameSidecarTest.kt @@ -34,6 +34,17 @@ class StoreGameSidecarTest { assertEquals("ns", back.extra["namespace"]) } + @Test fun theStoreLogoRoundTripsAndOlderFilesHaveNone() { + val withLogo = sample.copy(logo = "https://x/logo.png") + val back = StoreGameSidecar.parse(withLogo.toJson().toString())!! + assertEquals("https://x/logo.png", back.logo) + assertEquals("https://x/logo.png", back.copy(state = StoreGameSidecar.STATE_UPDATING).logo) + assertFalse(sample.toJson().has("logo")) + assertNull(StoreGameSidecar.parse(sample.toJson().toString())!!.logo) + assertNull(StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"game.exe","cover":"c","hero":"h"}""")!!.logo) + assertNull(StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"game.exe","logo":""}""")!!.logo) + } + @Test fun defaultsWhenFieldsAreAbsent() { val back = StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"bin\\game.exe","addToSteam":false}""")!! assertEquals("bin/game.exe", back.exe) diff --git a/app/src/test/java/com/droiddeck/launcher/stores/StoreLogoTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/StoreLogoTest.kt new file mode 100644 index 0000000000..71a6c1d8e7 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/stores/StoreLogoTest.kt @@ -0,0 +1,88 @@ +package com.droiddeck.launcher.stores + +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Color +import com.droiddeck.launcher.stores.amazon.AmazonLibrary +import com.droiddeck.launcher.stores.gog.GogBackend +import org.json.JSONObject +import org.junit.Assert.assertArrayEquals +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode +import java.io.ByteArrayOutputStream +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33]) +@GraphicsMode(GraphicsMode.Mode.NATIVE) +class StoreLogoTest { + @get:Rule val tmp = TemporaryFolder() + + private fun encoded(format: Bitmap.CompressFormat): ByteArray { + val bmp = Bitmap.createBitmap(8, 4, Bitmap.Config.ARGB_8888) + bmp.eraseColor(Color.TRANSPARENT) + bmp.setPixel(1, 1, Color.RED) + return ByteArrayOutputStream().also { bmp.compress(format, 100, it) }.toByteArray() + } + + @Test fun aPngLogoIsKeptAsItCameWithItsTransparency() { + val png = encoded(Bitmap.CompressFormat.PNG) + val dst = File(tmp.root, StoreArt.LOGO) + assertTrue(StoreArt.writeLogo(png, dst)) + assertArrayEquals(png, dst.readBytes()) + val back = BitmapFactory.decodeFile(dst.path) + assertEquals(0, Color.alpha(back.getPixel(0, 0))) + assertEquals(Color.RED, back.getPixel(1, 1)) + assertFalse(File(dst.path + ".tmp").exists()) + } + + @Test fun anotherImageFormatIsStoredAsPng() { + val dst = File(tmp.root, StoreArt.LOGO) + assertTrue(StoreArt.writeLogo(encoded(Bitmap.CompressFormat.JPEG), dst)) + val head = dst.readBytes().take(4) + assertEquals(listOf(0x89.toByte(), 'P'.code.toByte(), 'N'.code.toByte(), 'G'.code.toByte()), head) + assertEquals(8, BitmapFactory.decodeFile(dst.path).width) + } + + @Test fun whatIsNotAnImageIsRefusedAndAnExistingLogoStays() { + val dst = File(tmp.root, StoreArt.LOGO) + assertFalse(StoreArt.writeLogo("not found".toByteArray(), dst)) + assertFalse(dst.exists()) + dst.writeBytes(byteArrayOf(1, 2, 3)) + assertTrue(StoreArt.writeLogo(encoded(Bitmap.CompressFormat.PNG), dst)) + assertArrayEquals(byteArrayOf(1, 2, 3), dst.readBytes()) + assertTrue(StoreArt.fetchLogo(tmp.root, "https://invalid.example/logo.png")) + } + + @Test fun gogTakesTheV2LogoLinkOnly() { + val v2 = JSONObject("""{"_links":{"logo":{"href":"https://images.gog-statics.com/abc_logo.png"},"galaxyBackgroundImage":{"href":"https://x/bg.jpg"}}}""") + assertEquals("https://images.gog-statics.com/abc_logo.png", GogBackend.logoOf(v2)) + assertEquals("https://images.gog-statics.com/rel.png", GogBackend.logoOf(JSONObject("""{"_links":{"logo":{"href":"//images.gog-statics.com/rel.png"}}}"""))) + assertNull(GogBackend.logoOf(JSONObject("""{"_links":{}}"""))) + assertNull(GogBackend.logoOf(JSONObject("""{"images":{"logo2x":"https://x/glx_logo_2x.jpg"}}"""))) + assertNull(GogBackend.logoOf(JSONObject("""{"_links":{"logo":{"href":"http://x/logo.png"}}}"""))) + } + + @Test fun amazonKeepsTheLogoFromTheLibraryAndItsCache() { + val app = RuntimeEnvironment.getApplication() + val fresh = AmazonLibrary.gameFrom(JSONObject().put("productId", "p").put("title", "Game").put("logo", "https://m/logo.png"), null) + assertEquals("https://m/logo.png", fresh.logoUrl) + assertEquals("https://m/logo.png", AmazonLibrary.toCatalogItem(app, fresh).logoUrl) + assertEquals(listOf(fresh), AmazonLibrary.fromCacheJson(AmazonLibrary.toCacheJson(listOf(fresh)))) + val kept = AmazonLibrary.gameFrom(JSONObject().put("productId", "p").put("title", "Game"), fresh) + assertEquals("https://m/logo.png", kept.logoUrl) + val none = AmazonLibrary.gameFrom(JSONObject().put("productId", "q").put("title", "Other"), null) + assertNull(AmazonLibrary.toCatalogItem(app, none).logoUrl) + assertEquals("", AmazonLibrary.fromCacheJson("""[{"productId":"old","title":"Old"}]""").single().logoUrl) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicLibraryTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicLibraryTest.kt index 4eb819043a..a3f156e1b0 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicLibraryTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/epic/EpicLibraryTest.kt @@ -83,6 +83,18 @@ class EpicLibraryTest { assertEquals("Fig", EpicLibrary.gameFrom(record, null, null).title) } + @Test fun theCatalogLogoIsKeptInTheCacheAndHandedToTheInstall() { + val record = JSONObject().put("appName", "Fig").put("namespace", "ns").put("catalogItemId", "cat") + val fresh = EpicLibrary.gameFrom(record, JSONObject().put("logo", "https://e/logo.png"), null) + assertEquals("https://e/logo.png", fresh.artLogo) + assertEquals("https://e/logo.png", EpicLibrary.gameFrom(record, JSONObject().put("title", "Fig"), fresh).artLogo) + assertEquals(listOf(fresh), EpicLibrary.fromCacheJson(EpicLibrary.toCacheJson(listOf(fresh)))) + assertEquals("https://e/logo.png", EpicLibrary.toCatalogItem(app, fresh).logoUrl) + val plain = EpicGame("Old", "ns", "c", "Old") + assertFalse(JSONArray(EpicLibrary.toCacheJson(listOf(plain))).getJSONObject(0).has("artLogo")) + assertEquals(null, EpicLibrary.toCatalogItem(app, plain).logoUrl) + } + @Test fun signOutForgetsOnlyTheLibrary() { EpicPrefs.get(app).edit().putString(EpicLibrary.KEY_CACHE, "[]").putLong(EpicLibrary.KEY_SYNCED_AT, 1L) .putString("cloud_template_Fig", "{AppData}/x").commit() diff --git a/app/src/test/java/com/droiddeck/launcher/stores/xbox/XboxSignInMessagesTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/xbox/XboxSignInMessagesTest.kt new file mode 100644 index 0000000000..7726ca42fe --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/stores/xbox/XboxSignInMessagesTest.kt @@ -0,0 +1,33 @@ +package com.droiddeck.launcher.stores.xbox + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class) +@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class) +class XboxSignInMessagesTest { + @Test fun ownCheckMessagesAreShownAndOtherTextIsNot() { + assertEquals("the Xbox helper stopped with exit code 3", XboxLoginActivity.failure(IllegalStateException("the Xbox helper stopped with exit code 3"))) + assertEquals("IllegalStateException", XboxLoginActivity.failure(IllegalStateException("Check failed."))) + assertEquals("JSONException", XboxLoginActivity.failure(org.json.JSONException("token=secret-value"))) + assertEquals("IllegalArgumentException", XboxLoginActivity.failure(IllegalArgumentException("secret-value"))) + } + + @Test fun gamertagMustBeShortPrintableText() { + assertTrue(XboxGamertag.valid("Some Gamertag")) + assertFalse(XboxGamertag.valid("")) + assertFalse(XboxGamertag.valid("a\nb")) + assertFalse(XboxGamertag.valid("x".repeat(65))) + } + + @Test fun gamertagRefreshIsOncePerAccountGeneration() { + val first = "account-generation-one-${System.nanoTime()}" + val second = "account-generation-two-${System.nanoTime()}" + assertTrue(XboxGamertag.shouldTryRefresh(first)) + assertFalse(XboxGamertag.shouldTryRefresh(first)) + assertTrue(XboxGamertag.shouldTryRefresh(second)) + assertFalse(XboxGamertag.shouldTryRefresh(second)) + } +} diff --git a/docs/releases/0.6.0.md b/docs/releases/0.6.0.md new file mode 100644 index 0000000000..c14bda97c3 --- /dev/null +++ b/docs/releases/0.6.0.md @@ -0,0 +1,172 @@ +# DroidDeck 0.6.0 + +

Join the DroidDeck Discord

+ + + +> **DroidDeck is 100% open source. No ads. No telemetry. No source withheld.** +> +> DroidDeck is a community project in the truest sense. Because all of its code is public, the people who use it can read it, fix it and improve it, and in 0.6.0 you all sure did: +> +> **153 pull requests · 23 contributors · 10 first-timers · 73% of the pull requests came from the community.** +> +> Thank you to everyone who sent code, translations, device testing and bug reports. Here’s everything we did together for this release: + +### Features + + +The Epic library switching from cards to the capsule view, the Xbox library, an itch.io store search, then an installed game's page with its Play button. Account names are blurred + +- Added experimental **Xbox and PC Game Pass** as a store. Sign in with your Microsoft account to see your owned and Game Pass games, then download them with pause and resume, update, verify and manage add-on content. Games launch through Proton or FEX from the Games tab or straight from Steam. Search results open with their artwork and details, and Game Pass titles you have not installed yet can be installed from their page. (@xXJSONDeruloXx, @moronigranja, [#1156](https://github.com/Droid-Deck/DroidDeck/pull/1156), [#1164](https://github.com/Droid-Deck/DroidDeck/pull/1164), [#1170](https://github.com/Droid-Deck/DroidDeck/pull/1170), [#1193](https://github.com/Droid-Deck/DroidDeck/pull/1193), [#1279](https://github.com/Droid-Deck/DroidDeck/pull/1279)) +- Added an **itch.io** store. Sign in with your itch.io API key to see your library, then search the store or browse the newest, on-sale, free and top-rated shelves. DRM-free Windows builds install and launch through Steam like games from the other stores. (@kingokksa, [#1064](https://github.com/Droid-Deck/DroidDeck/pull/1064)) +- **Redesigned store pages.** Each store has **Library** and **Store** tabs, and the library lists installed games first. A new **capsule view** shows portrait DVD-case art in every store. LB and RB switch between stores, and installed games get a **Play** button on their page. You can reorder and hide store tabs in the stores settings, and stores you are not signed in to are dimmed. (@xXJSONDeruloXx, @kingokksa, [#1116](https://github.com/Droid-Deck/DroidDeck/pull/1116), [#1117](https://github.com/Droid-Deck/DroidDeck/pull/1117), [#1121](https://github.com/Droid-Deck/DroidDeck/pull/1121), [#1125](https://github.com/Droid-Deck/DroidDeck/pull/1125), [#1236](https://github.com/Droid-Deck/DroidDeck/pull/1236)) + + +Setting Touch to Gestures, going through the one-, two- and three-finger tabs and the searchable action picker, turning on Show recognized gesture, then two-finger drags moving through the Steam library and a pinch zoom, each gesture named at the top + +- Added configurable **touchscreen gestures**: taps, double taps, holds, one-, two- and three-finger drags and pinch zoom. Each one can be mapped to an action from a searchable list, with defaults and per-game overrides. (@Nightwalker743, @kingokksa, [#940](https://github.com/Droid-Deck/DroidDeck/pull/940), [#1214](https://github.com/Droid-Deck/DroidDeck/pull/1214)) +- **Steam Remote Play from DroidDeck** now streams video as well as audio and input. The picture is captured through PipeWire, as on SteamOS, and encoded by the phone's hardware encoder. On a Thor that takes 7.3–8.0 ms per frame, down from 50–90 ms with software encoding. Touch on the client can tap and drag, and games are heard on the stream. (@xXJSONDeruloXx, [#1139](https://github.com/Droid-Deck/DroidDeck/pull/1139)) + + + Remote Play encode time per frame on an AYN Thor: 50 to 90 ms with software x264, 7.3 to 8.0 ms with the hardware encoder. + + +Opening SteamDeckRepo, filtering to Steam Deck and Most liked, installing Handheld History by KnightMD and pressing Use, then starting Steam with the new boot movie. Waits are cut + +- **Boot movies from SteamDeckRepo.** Search SteamDeckRepo, filter by device and browse the Trending, Most downloaded, Most liked and Newest tabs, then install a movie and use it. Installed movies are listed with covers. Imported movies go into Steam's own movie folder, and the sound has volume and length sliders. (@FX192, [#1036](https://github.com/Droid-Deck/DroidDeck/pull/1036), [#1229](https://github.com/Droid-Deck/DroidDeck/pull/1229)) + + +In Valheim's intro, turning on the battery temperature and the frame-time graph, picking the Amber color and raising the opacity, then a close-up of the HUD over the game + +- The **performance HUD** can show a colored frame-time graph and the battery temperature. Each part can be shown or hidden, and its colors and opacity can be changed. (@0x1Nawaf, [#1256](https://github.com/Droid-Deck/DroidDeck/pull/1256)) + + +Choosing the Gradient theme, dragging the primary color around the wheel, typing a hex code for the secondary color, then the Games and Steam tabs in the new colors + +- Added a custom **Gradient theme**, with primary and secondary colors chosen from a color wheel, sliders or a hex code, and a **light app icon** option. (@FX192, @xXJSONDeruloXx, [#1309](https://github.com/Droid-Deck/DroidDeck/pull/1309), [#1104](https://github.com/Droid-Deck/DroidDeck/pull/1104)) +- **SteamVR controller types.** Without VR controllers, the gamepad can act as Valve Index controllers (the default), Meta Quest 3 Touch Plus, HTC Vive wands, or a regular gamepad. The sticks move you in the game by default, and pressing both sticks switches them to moving the hands. The type can be changed while SteamVR runs. With glasses, the phone becomes a control panel with Recenter, the SteamVR menu, the keyboard, brightness and battery. Flat games started from VR open as a SteamVR panel. (@xXJSONDeruloXx, [#1268](https://github.com/Droid-Deck/DroidDeck/pull/1268)) +- Added **Rokid Max and Air** glasses, with 3DoF head tracking, SBS modes, 120 Hz on the Max and brightness control, and experimental head tracking for **VITURE Pro 2** without the vendor SDK. (@xXJSONDeruloXx, @informalTechCode, @kingokksa, [#1266](https://github.com/Droid-Deck/DroidDeck/pull/1266), [#1115](https://github.com/Droid-Deck/DroidDeck/pull/1115)) +- **Easy Anti-Cheat games with an offline mode** start without the anti-cheat bootstrapper. This is on by default and can be turned off per game. Online modes that need Easy Anti-Cheat stay unavailable. (@xXJSONDeruloXx, [#1039](https://github.com/Droid-Deck/DroidDeck/pull/1039)) +- The **built-in controller can be turned off** (Steam settings > Controller > None), so a connected controller becomes player 1 for games that only read the first pad. (@kingokksa, [#1207](https://github.com/Droid-Deck/DroidDeck/pull/1207), [#1304](https://github.com/Droid-Deck/DroidDeck/pull/1304)) +- On foldables, the **unfolded controls can stay while a controller is connected**, for players who use a telescopic controller and still want the trackpads and back buttons. (@ovurrsl, [#996](https://github.com/Droid-Deck/DroidDeck/pull/996)) +- The component manager offers **nightly DXVK, VKD3D-Proton and FEX builds** from DroidDeck-Components, with a **Stable | Nightly** switch on each row. (@The412Banner, [#1284](https://github.com/Droid-Deck/DroidDeck/pull/1284)) +- When a game started from the Games tab closes, DroidDeck **returns you to where you launched it** instead of leaving you in Big Picture. (@The412Banner, [#395](https://github.com/Droid-Deck/DroidDeck/pull/395)) +- **Decky Loader** installs from the upstream SteamDeckHomebrew release, has a Stable or Prerelease update channel, and shows Decky's own third-party warning before a plugin ZIP is installed. (@xXJSONDeruloXx, [#1090](https://github.com/Droid-Deck/DroidDeck/pull/1090), [#1263](https://github.com/Droid-Deck/DroidDeck/pull/1263), [#1264](https://github.com/Droid-Deck/DroidDeck/pull/1264)) +- **Desktop mode can be uninstalled** from beside Open desktop, including a desktop install that was interrupted. Games, Steam, added apps and settings are kept. (@xXJSONDeruloXx, [#1311](https://github.com/Droid-Deck/DroidDeck/pull/1311)) +- **GOG and Epic installs can use your language.** The install dialog has a **Game language** choice, which follows the app's language by default, and the stores settings can pin a default. GOG games no longer download only their English files. (@LooLL, [#1199](https://github.com/Droid-Deck/DroidDeck/pull/1199)) +- Games can be **uninstalled or removed from their page in the Games tab**. Store games use their store's uninstaller. Steam games delete their install but keep their saves and Proton prefix. Added games only lose their shortcut, so their files stay. (@kingokksa, [#1190](https://github.com/Droid-Deck/DroidDeck/pull/1190)) + +### Improvements + +- **Performance** + - **Faster games and session starts on Adreno.** Games now use Turnip's tile rendering while the Steam interface keeps system memory. In PEAK on an Adreno 840 tablet, the frame rate rose 11.7% and frames slower than 25 ms dropped by 26%. Steam is ready 35.9% sooner after a session starts (5.57 s to 3.57 s). (@maxjivi05, [#1188](https://github.com/Droid-Deck/DroidDeck/pull/1188)) + + + PEAK on an Adreno 840 tablet: 46.8 fps before and 52.3 fps in 0.6.0 (+11.7%). Frames shown for longer than 25 ms fall from 12.90% to 9.53%. Steam is ready 5.57 s after session start before and 3.57 s in 0.6.0 (-35.9%). + - **Faster game launches.** Steam's install-script step is skipped once it has finished for a game. In testing, Moonlighter went from 10.5 s to 7.7 s from Play to the game window. FEX's file lookups skip proot, so Graveyard Keeper reaches its first scene 0.57 s sooner with 48% fewer proot stops. (@maxjivi05, [#1273](https://github.com/Droid-Deck/DroidDeck/pull/1273), [#1283](https://github.com/Droid-Deck/DroidDeck/pull/1283)) + - **Games on an SD card library load far faster.** proot's fast path now names files and follows links inside a library the same way proot does, instead of handing every lookup back to proot. In testing, Red Dead Redemption 2's Story mode went from still loading after 16 minutes to the opening scene in about 2 minutes 10 seconds. (@maxjivi05, [#1331](https://github.com/Droid-Deck/DroidDeck/pull/1331)) + - **Less overhead from the performance overlay.** gamescope's CPU use dropped from about 12.9% to 7.7% of a core with the overlay hidden, and a 60 fps game on a 120 Hz panel no longer gets extra composites while the overlay is shown. Wine's network queries also cost less. (@maxjivi05, [#1272](https://github.com/Droid-Deck/DroidDeck/pull/1272), [#1274](https://github.com/Droid-Deck/DroidDeck/pull/1274), [#1275](https://github.com/Droid-Deck/DroidDeck/pull/1275)) + + + Moonlighter from Play to game window: 10.5 s before, 7.7 s in 0.6.0. Graveyard Keeper to its first scene: 9.70 s before, 9.13 s in 0.6.0. Red Dead Redemption 2 Story mode from an SD card library: still loading after 16 minutes before (a lower bound), about 2 minutes 10 seconds in 0.6.0. gamescope CPU with Moonlighter at 120 fps: 12.85% of a core before and 7.65% in 0.6.0 with the overlay hidden, 19.05% and 10.35% with it visible. + - The **Steam client responds sooner**: it paces itself to the panel's real refresh rate, and its interface sounds no longer queue about 112 ms of audio. The DirectAudio sink is now built from @The412Banner's [DirectAudio](https://github.com/The412Banner/directaudio) source. (@maxjivi05, [#1094](https://github.com/Droid-Deck/DroidDeck/pull/1094)) + + + Steam client on a REDMAGIC Astra: per-run median press-to-response 41.0 to 41.2 ms before and 28.5 to 33.0 ms in 0.6.0. The interface frame interval falls from 10.8 ms (about 92 fps) to 8.3 ms (120 fps), and the interface sound queue from 105 to 120 ms to 28 to 45 ms. + - The **GOG tab opens in seconds**, because the whole library comes from one listing instead of a request per game. (@kingokksa, [#786](https://github.com/Droid-Deck/DroidDeck/pull/786)) +- **Reduced the APK size** from 124.4 MB to 66.4 MB. (@xXJSONDeruloXx, [#1198](https://github.com/Droid-Deck/DroidDeck/pull/1198), [#1204](https://github.com/Droid-Deck/DroidDeck/pull/1204), [#1265](https://github.com/Droid-Deck/DroidDeck/pull/1265)) +- **Better battery life while a session is suspended.** The device can now really sleep: every guest thread stops and the audio stream is stopped. Before, a Thor did not suspend once in 13 minutes. Steam downloads keep running with the Manual policy, including downloads to SD-card libraries, and a switched-off Steam Controller no longer wakes Bluetooth all night. (@xXJSONDeruloXx, @Detinator10, [#1220](https://github.com/Droid-Deck/DroidDeck/pull/1220), [#1262](https://github.com/Droid-Deck/DroidDeck/pull/1262), [#1312](https://github.com/Droid-Deck/DroidDeck/pull/1312)) +- **zRAM is always on** where supported, and a session is paged out to zRAM before it is suspended, so Android is less likely to close it overnight. In testing, Bulletstorm's resident memory went from 1,886 MB to 318 MB while suspended, with the rest moved to zRAM. The zRAM setting has been removed. (@xXJSONDeruloXx, [#1317](https://github.com/Droid-Deck/DroidDeck/pull/1317)) + + + On an AYN Thor, guest threads still running while suspended: Steam 59 of 72 and gamescope 8 of 15 before, none in 0.6.0. Bulletstorm's resident memory while suspended falls from 1,886 MB to 318 MB, with 1,570 MB moved to zRAM. +- Sessions on an **external display or DeX** keep running while the phone's screen is off. (@maxjivi05, @xXJSONDeruloXx, [#1211](https://github.com/Droid-Deck/DroidDeck/pull/1211), [#1320](https://github.com/Droid-Deck/DroidDeck/pull/1320)) +- **Game cores** now apply to games started with **Linux x86 (FEX)** too. (@coffeemeist3r, [#1294](https://github.com/Droid-Deck/DroidDeck/pull/1294)) +- **GPU drivers:** Auto's picks come from a manifest in Drivers-CI, so a default can change without an app update. The Snapdragon SM8975 is recognized and Adreno 850 support is marked experimental. A trial driver that crashes at startup now rolls back automatically. (@xXJSONDeruloXx, @Danbro007, @ovurrsl, [#977](https://github.com/Droid-Deck/DroidDeck/pull/977), [#1249](https://github.com/Droid-Deck/DroidDeck/pull/1249), [#1031](https://github.com/Droid-Deck/DroidDeck/pull/1031)) +- The KDE desktop is updated to **KWin 6.8.0**. (@xXJSONDeruloXx, [#1328](https://github.com/Droid-Deck/DroidDeck/pull/1328), [#1330](https://github.com/Droid-Deck/DroidDeck/pull/1330)) +- New sessions default to **landscape**, and the Deck controls open on **both trackpads**. (@xXJSONDeruloXx, [#1287](https://github.com/Droid-Deck/DroidDeck/pull/1287), [#1295](https://github.com/Droid-Deck/DroidDeck/pull/1295)) +- **Accessibility:** buttons, tiles and list rows are announced as buttons by screen readers, the Electric theme's buttons meet WCAG contrast, and section headings are capitalized correctly in the app's language. (@ovurrsl, [#891](https://github.com/Droid-Deck/DroidDeck/pull/891), [#1149](https://github.com/Droid-Deck/DroidDeck/pull/1149), [#1145](https://github.com/Droid-Deck/DroidDeck/pull/1145), [#1148](https://github.com/Droid-Deck/DroidDeck/pull/1148)) +- **Translations:** Turkish covers every new screen, every language has the plural forms it needs, and English left in the translations is translated. New features in this release ship in all 32 languages. The KDE desktop's translations are now built as per-language packs, ready for a translated desktop. (@ovurrsl, @maxjivi05, @kingokksa, [#989](https://github.com/Droid-Deck/DroidDeck/pull/989), [#1102](https://github.com/Droid-Deck/DroidDeck/pull/1102), [#942](https://github.com/Droid-Deck/DroidDeck/pull/942)) +- **Building and testing DroidDeck yourself** is easier: local builds find Java 17 installed with mise, reuse add-on packs a CI build installed, and `tools/device-smoke.sh` checks a build on a real device over plain adb. Session logs time each setup step to the millisecond. (@ugreg, @xXJSONDeruloXx, @ovurrsl, @maxjivi05, [#1231](https://github.com/Droid-Deck/DroidDeck/pull/1231), [#1265](https://github.com/Droid-Deck/DroidDeck/pull/1265), [#911](https://github.com/Droid-Deck/DroidDeck/pull/911), [#993](https://github.com/Droid-Deck/DroidDeck/pull/993), [#1091](https://github.com/Droid-Deck/DroidDeck/pull/1091), [#1151](https://github.com/Droid-Deck/DroidDeck/pull/1151)) + +### Fixed + +- Fixed **Ubisoft games** stopping with "Error at hooking API" (for example Immortals Fenyx Rising), and other programs that patch their own code under FEX. (@maxjivi05, [#1163](https://github.com/Droid-Deck/DroidDeck/pull/1163)) +- Fixed **Steam going back to sleep** right after a long-paused session resumed. (@maxjivi05, [#1162](https://github.com/Droid-Deck/DroidDeck/pull/1162)) +- Fixed **controllers in Rewired (Unity) games** such as Drova and Graveyard Keeper, and in **Factorio**'s ARM64 build. (@Delete228, @maxjivi05, [#1195](https://github.com/Droid-Deck/DroidDeck/pull/1195), [#1222](https://github.com/Droid-Deck/DroidDeck/pull/1222), [#1227](https://github.com/Droid-Deck/DroidDeck/pull/1227)) +- Fixed **Linux games under FEX**: games such as Stardew Valley start again, have sound, find OpenSSL 3 and reach FEXServer. CJK text shows in x86 apps such as the Epic Games Launcher, and clearing a game's compatibility tool in Steam keeps its Linux build. x86 Proton runs in the Steam runtime it requires. (@maxjivi05, @xXJSONDeruloXx, [#1100](https://github.com/Droid-Deck/DroidDeck/pull/1100), [#1166](https://github.com/Droid-Deck/DroidDeck/pull/1166), [#1167](https://github.com/Droid-Deck/DroidDeck/pull/1167), [#1213](https://github.com/Droid-Deck/DroidDeck/pull/1213), [#1168](https://github.com/Droid-Deck/DroidDeck/pull/1168), [#1250](https://github.com/Droid-Deck/DroidDeck/pull/1250), [#1034](https://github.com/Droid-Deck/DroidDeck/pull/1034)) +- Fixed the **x86-64 Steam client** staying on a blank screen, asking for the password again and listing games twice. (@maxjivi05, [#1096](https://github.com/Droid-Deck/DroidDeck/pull/1096)) +- Fixed **garbled Chinese, Japanese and Korean text** in Steam's interface. (@zooluis, @xXJSONDeruloXx, [#1319](https://github.com/Droid-Deck/DroidDeck/pull/1319)) +- Fixed **flicker and green flashes on Samsung One UI devices with a Snapdragon 8 Gen 2** (Galaxy S23 series, Tab S9). (@xXJSONDeruloXx, [#1128](https://github.com/Droid-Deck/DroidDeck/pull/1128)) +- Fixed the **GPU load reading 0%** in the performance overlay on Adreno phones. (@angelrenefm, @xXJSONDeruloXx, [#1326](https://github.com/Droid-Deck/DroidDeck/pull/1326), [#1327](https://github.com/Droid-Deck/DroidDeck/pull/1327)) +- Fixed gamescope running out of file handles in long sessions with lots of touch input. (@asdf17128, [#1189](https://github.com/Droid-Deck/DroidDeck/pull/1189)) +- Fixed **GOG games missing their registry entries**, such as Fallout: New Vegas saying it is not installed, and the "already installed" markers of Windows redistributables never reaching the user registry. (@maxjivi05, @kaosjammo, [#1159](https://github.com/Droid-Deck/DroidDeck/pull/1159), [#1286](https://github.com/Droid-Deck/DroidDeck/pull/1286)) +- Fixed a store game's **first launch missing its cloud saves**, and manual cloud-save Upload and Download reporting success when nothing was synced. (@maxjivi05, @ovurrsl, [#1215](https://github.com/Droid-Deck/DroidDeck/pull/1215), [#1068](https://github.com/Droid-Deck/DroidDeck/pull/1068)) +- Fixed the **on-screen pad covering Steam's keyboard** and DroidDeck's PC keyboard. (@maxjivi05, @ovurrsl, [#1217](https://github.com/Droid-Deck/DroidDeck/pull/1217), [#956](https://github.com/Droid-Deck/DroidDeck/pull/956), [#1221](https://github.com/Droid-Deck/DroidDeck/pull/1221)) +- Fixed **Steam touch layouts**: third-party and added games load their own layout, layouts of non-Steam shortcuts such as the Epic Games Launcher can be edited and saved, and held controls stay pressed across action-set and layer changes. Labels with quotes no longer break the config. (@kingokksa, @maxjivi05, @ovurrsl, [#1058](https://github.com/Droid-Deck/DroidDeck/pull/1058), [#1171](https://github.com/Droid-Deck/DroidDeck/pull/1171), [#1143](https://github.com/Droid-Deck/DroidDeck/pull/1143), [#1017](https://github.com/Droid-Deck/DroidDeck/pull/1017)) +- Fixed touch input: long-press right-click in Direct touch, the saved touch mode coming back when Steam Touch is turned off, and the touchpad cursor jumping after a two-finger scroll. (@xXJSONDeruloXx, @ovurrsl, [#677](https://github.com/Droid-Deck/DroidDeck/pull/677), [#1142](https://github.com/Droid-Deck/DroidDeck/pull/1142)) +- Fixed controller input: moving a stick no longer releases a held D-pad direction or trigger, Xiaomi HyperOS's virtual input device no longer takes player 1, and back-to-back reports to a Bluetooth Steam Controller are no longer dropped. (@ovurrsl, [#1060](https://github.com/Droid-Deck/DroidDeck/pull/1060), [#954](https://github.com/Droid-Deck/DroidDeck/pull/954), [#1032](https://github.com/Droid-Deck/DroidDeck/pull/1032)) +- Fixed Steam's **"Steam Controller detected!" tour** opening at every start, and the emulated Steam Controller looking out of date to Steam. (@xXJSONDeruloXx, [#1321](https://github.com/Droid-Deck/DroidDeck/pull/1321), [#1323](https://github.com/Droid-Deck/DroidDeck/pull/1323)) +- Fixed **SteamVR starting in a normal Steam session** after a VR session had been used. (@xXJSONDeruloXx, [#1137](https://github.com/Droid-Deck/DroidDeck/pull/1137)) +- Fixed **adding games from an SD card**, both a whole games folder and a single EXE, and adding a game whose folder sits inside another added game's folder. (@The412Banner, @maxjivi05, [#1153](https://github.com/Droid-Deck/DroidDeck/pull/1153), [#1173](https://github.com/Droid-Deck/DroidDeck/pull/1173), [#1155](https://github.com/Droid-Deck/DroidDeck/pull/1155)) +- Fixed the games-folder scan hiding games such as Reach, Breach, Crashday and Observer, and Unreal Engine games being named "BootstrapPackagedGame". (@ovurrsl, @charan-rathore, [#1023](https://github.com/Droid-Deck/DroidDeck/pull/1023), [#1020](https://github.com/Droid-Deck/DroidDeck/pull/1020)) +- Added games start sooner on large Steam libraries, and game files keep the full game name. (@ovurrsl, @maxjivi05, [#994](https://github.com/Droid-Deck/DroidDeck/pull/994), [#1230](https://github.com/Droid-Deck/DroidDeck/pull/1230)) +- Fixed a game's **Components** button opening the default profile instead of the game's own. (@jmarti326, [#1146](https://github.com/Droid-Deck/DroidDeck/pull/1146)) +- Fixed **desktop apps and emulators**: RPCS3 opens from the emulator rail, RetroArch fills the screen, Chromium browsers start, browsers added as non-Steam games show their window, Flatpak apps open in the renamed app variants, user apps open at the Desktop's resolution, and programs that need an executable stack start. Apps started from the front end show their own cursor, and Steam shortcuts are kept out of the desktop's controls. (@maxjivi05, @Delete228, @xXJSONDeruloXx, [#1191](https://github.com/Droid-Deck/DroidDeck/pull/1191), [#1194](https://github.com/Droid-Deck/DroidDeck/pull/1194), [#1280](https://github.com/Droid-Deck/DroidDeck/pull/1280), [#1243](https://github.com/Droid-Deck/DroidDeck/pull/1243), [#1192](https://github.com/Droid-Deck/DroidDeck/pull/1192), [#1172](https://github.com/Droid-Deck/DroidDeck/pull/1172), [#1208](https://github.com/Droid-Deck/DroidDeck/pull/1208), [#1154](https://github.com/Droid-Deck/DroidDeck/pull/1154), [#1318](https://github.com/Droid-Deck/DroidDeck/pull/1318)) +- Fixed **store sign-in**: GOG lets you sign in with a different account, and one failing image or script no longer replaces the Epic sign-in page with an SSL error. (@maxjivi05, [#1235](https://github.com/Droid-Deck/DroidDeck/pull/1235), [#1238](https://github.com/Droid-Deck/DroidDeck/pull/1238)) +- Fixed the **file manager**: copy and move keep symbolic links, Cancel really stops a paste, a double tap no longer starts two pastes, selection follows the search filter, and a slow folder no longer replaces the one you moved to. (@ovurrsl, [#1027](https://github.com/Droid-Deck/DroidDeck/pull/1027), [#1029](https://github.com/Droid-Deck/DroidDeck/pull/1029), [#1025](https://github.com/Droid-Deck/DroidDeck/pull/1025), [#1021](https://github.com/Droid-Deck/DroidDeck/pull/1021), [#1028](https://github.com/Droid-Deck/DroidDeck/pull/1028)) +- Fixed an interrupted desktop or package install breaking the Linux runtime, which used to need an app reinstall. (@xXJSONDeruloXx, [#1078](https://github.com/Droid-Deck/DroidDeck/pull/1078)) +- A failed Steam client download now says your network or VPN may be blocking Steam and offers Retry, instead of silently ending the session. (@ovurrsl, [#997](https://github.com/Droid-Deck/DroidDeck/pull/997)) +- Fixed **in-app updates on Android 9 and 10**. (@ovurrsl, [#1066](https://github.com/Droid-Deck/DroidDeck/pull/1066)) +- Fixed crashes with a full disk while fetching cover art and with an empty App ID in the game environment editor. (@ovurrsl, [#1030](https://github.com/Droid-Deck/DroidDeck/pull/1030), [#1014](https://github.com/Droid-Deck/DroidDeck/pull/1014)) +- Fixed DirectAudio setup changing a game's audio choice during Steam's path queries and install scripts. (@xXJSONDeruloXx, [#1044](https://github.com/Droid-Deck/DroidDeck/pull/1044), [#1046](https://github.com/Droid-Deck/DroidDeck/pull/1046)) +- Hidden and private Steam games no longer show on the Steam home art wall. (@xXJSONDeruloXx, [#1097](https://github.com/Droid-Deck/DroidDeck/pull/1097)) +- Storage asks before bulk-removing unused components, and store search no longer reopens the keyboard when you scroll back up. (@ovurrsl, [#1140](https://github.com/Droid-Deck/DroidDeck/pull/1140), [#1141](https://github.com/Droid-Deck/DroidDeck/pull/1141)) +- Moving a mouse no longer redraws the whole session overlay. (@maxjivi05, [#1253](https://github.com/Droid-Deck/DroidDeck/pull/1253)) + +### Community + +DroidDeck is built in the open by the people who use it. These are everyone whose code is in 0.6.0: + +| Contributor | Pull requests | +|---|---| +| @xXJSONDeruloXx | 48: Xbox and Game Pass, store redesign, Remote Play, add-on packs, SteamVR controller types, Rokid glasses, suspend and zRAM, Decky, KWin 6.8 and more | +| @maxjivi05 | 41: performance, FEX and Linux games, Steam client, Ubisoft and GOG fixes, Rewired pads, desktop apps and emulators | +| @ovurrsl | 33: file manager, controller and touch fixes, security, accessibility, Turkish, cloud saves, device smoke tests | +| @kingokksa | 10: itch.io store, uninstall from Games, store tab order, controller off, GOG speed-up, Steam touch layouts | +| @The412Banner | 3: return to launcher, SD-card games folders, nightly components (and the DirectAudio sink) | +| @FX192 | 3: SteamDeckRepo boot movies, Gradient theme | +| @Nightwalker743 | [#940](https://github.com/Droid-Deck/DroidDeck/pull/940): touchscreen gestures | +| @0x1Nawaf | [#1256](https://github.com/Droid-Deck/DroidDeck/pull/1256): performance HUD graph and options | +| @LooLL | [#1199](https://github.com/Droid-Deck/DroidDeck/pull/1199): game language for GOG and Epic | +| @moronigranja | [#1279](https://github.com/Droid-Deck/DroidDeck/pull/1279): Xbox search results and Game Pass installs | +| @informalTechCode | [#1115](https://github.com/Droid-Deck/DroidDeck/pull/1115): VITURE Pro 2 head tracking | +| @Delete228 | [#1195](https://github.com/Droid-Deck/DroidDeck/pull/1195), [#1318](https://github.com/Droid-Deck/DroidDeck/pull/1318): Factorio controller input, second-screen controls in the desktop | +| @Danbro007 | [#1249](https://github.com/Droid-Deck/DroidDeck/pull/1249): SM8975 and Adreno 850 detection | +| @coffeemeist3r | [#1294](https://github.com/Droid-Deck/DroidDeck/pull/1294): Game cores for FEX games | +| @angelrenefm | [#1326](https://github.com/Droid-Deck/DroidDeck/pull/1326): GPU load in the overlay | +| @asdf17128 | [#1189](https://github.com/Droid-Deck/DroidDeck/pull/1189): gamescope cursor buffer leak | +| @kaosjammo | [#1286](https://github.com/Droid-Deck/DroidDeck/pull/1286): Windows redistributable registry markers | +| @jmarti326 | [#1146](https://github.com/Droid-Deck/DroidDeck/pull/1146): Components opens the game's profile | +| @charan-rathore | [#1020](https://github.com/Droid-Deck/DroidDeck/pull/1020): Unreal Engine game names | +| @wallentx | [#1063](https://github.com/Droid-Deck/DroidDeck/pull/1063): readable library names in logs | +| @ugreg | [#1231](https://github.com/Droid-Deck/DroidDeck/pull/1231): Java 17 through mise for local builds | +| @zooluis | [#1319](https://github.com/Droid-Deck/DroidDeck/pull/1319): CJK fonts in Steam | +| @Detinator10 | [#1220](https://github.com/Droid-Deck/DroidDeck/pull/1220): full session freeze for sleep | + + + +### New contributors + +- @Nightwalker743 made their first contribution in [#940](https://github.com/Droid-Deck/DroidDeck/pull/940). +- @charan-rathore made their first contribution in [#1020](https://github.com/Droid-Deck/DroidDeck/pull/1020). +- @Delete228 made their first contribution in [#1195](https://github.com/Droid-Deck/DroidDeck/pull/1195). +- @LooLL made their first contribution in [#1199](https://github.com/Droid-Deck/DroidDeck/pull/1199). +- @Detinator10 made their first contribution in [#1220](https://github.com/Droid-Deck/DroidDeck/pull/1220). +- @ugreg made their first contribution in [#1231](https://github.com/Droid-Deck/DroidDeck/pull/1231). +- @Danbro007 made their first contribution in [#1249](https://github.com/Droid-Deck/DroidDeck/pull/1249). +- @moronigranja made their first contribution in [#1279](https://github.com/Droid-Deck/DroidDeck/pull/1279). +- @coffeemeist3r made their first contribution in [#1294](https://github.com/Droid-Deck/DroidDeck/pull/1294). +- @zooluis made their first contribution in [#1319](https://github.com/Droid-Deck/DroidDeck/pull/1319). + +[Full changelog](https://github.com/Droid-Deck/DroidDeck/compare/0.5.0...0.6.0) diff --git a/docs/releases/media/0.6.0/adreno-peak-and-steam-start.png b/docs/releases/media/0.6.0/adreno-peak-and-steam-start.png new file mode 100644 index 0000000000..89de2c6ee2 Binary files /dev/null and b/docs/releases/media/0.6.0/adreno-peak-and-steam-start.png differ diff --git a/docs/releases/media/0.6.0/boot-movies.gif b/docs/releases/media/0.6.0/boot-movies.gif new file mode 100644 index 0000000000..da773d55be Binary files /dev/null and b/docs/releases/media/0.6.0/boot-movies.gif differ diff --git a/docs/releases/media/0.6.0/gradient-theme.gif b/docs/releases/media/0.6.0/gradient-theme.gif new file mode 100644 index 0000000000..5d0f975522 Binary files /dev/null and b/docs/releases/media/0.6.0/gradient-theme.gif differ diff --git a/docs/releases/media/0.6.0/performance-hud.gif b/docs/releases/media/0.6.0/performance-hud.gif new file mode 100644 index 0000000000..0ee90601cf Binary files /dev/null and b/docs/releases/media/0.6.0/performance-hud.gif differ diff --git a/docs/releases/media/0.6.0/remote-play-encode.png b/docs/releases/media/0.6.0/remote-play-encode.png new file mode 100644 index 0000000000..8088bbf2e7 Binary files /dev/null and b/docs/releases/media/0.6.0/remote-play-encode.png differ diff --git a/docs/releases/media/0.6.0/speed-launch-load-overlay.png b/docs/releases/media/0.6.0/speed-launch-load-overlay.png new file mode 100644 index 0000000000..9936c139e1 Binary files /dev/null and b/docs/releases/media/0.6.0/speed-launch-load-overlay.png differ diff --git a/docs/releases/media/0.6.0/steam-client-responsiveness.png b/docs/releases/media/0.6.0/steam-client-responsiveness.png new file mode 100644 index 0000000000..a31314d2f4 Binary files /dev/null and b/docs/releases/media/0.6.0/steam-client-responsiveness.png differ diff --git a/docs/releases/media/0.6.0/stores-capsules.gif b/docs/releases/media/0.6.0/stores-capsules.gif new file mode 100644 index 0000000000..4c5726b2d6 Binary files /dev/null and b/docs/releases/media/0.6.0/stores-capsules.gif differ diff --git a/docs/releases/media/0.6.0/suspend-sleep-and-memory.png b/docs/releases/media/0.6.0/suspend-sleep-and-memory.png new file mode 100644 index 0000000000..b1d42ea092 Binary files /dev/null and b/docs/releases/media/0.6.0/suspend-sleep-and-memory.png differ diff --git a/docs/releases/media/0.6.0/touch-gestures.gif b/docs/releases/media/0.6.0/touch-gestures.gif new file mode 100644 index 0000000000..dedfce85f9 Binary files /dev/null and b/docs/releases/media/0.6.0/touch-gestures.gif differ diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-pipewire b/tools/linuxfs/overlay/usr/local/bin/droiddeck-pipewire index 11ed41fb23..2677599bf0 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-pipewire +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-pipewire @@ -21,6 +21,30 @@ unpack() { { rm -rf "$dir.new"; echo "droiddeck-pipewire: could not unpack $bundle" >&2; return 1; } } +access_config() { + mkdir -p "$dir/share/pipewire/pipewire.conf.d" "$dir/share/wireplumber/wireplumber.conf.d" || return 1 + cat > "$dir/share/pipewire/pipewire.conf.d/droiddeck-access.conf" <<'EOF' || return 1 +context.properties = { + module.access = false +} +context.modules = [ + { name = libpipewire-module-access + args = { + access.socket = { pipewire-0 = "unrestricted", pipewire-0-manager = "unrestricted" } + } + } +] +EOF + cat > "$dir/share/wireplumber/wireplumber.conf.d/droiddeck-access.conf" <<'EOF' || return 1 +access.rules = [ + { + matches = [ { pipewire.access = "unrestricted" } ] + actions = { update-props = { default_permissions = "all" } } + } +] +EOF +} + stop() { for pid in $(cat "$state/pids" 2>/dev/null); do kill "$pid" 2>/dev/null; done rm -f "$state/pids" @@ -32,6 +56,7 @@ env) ;; start) unpack || exit 1 + access_config || { echo "droiddeck-pipewire: could not write the access settings" >&2; exit 1; } stop mkdir -p "$state" eval "$(client_env)" diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 632c87ea14..8bd91bde76 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -60,6 +60,9 @@ clear_stale_tmp() { return 0 } [ -z "${BL_INSIDE:-}" ] && clear_stale_tmp +if [ -z "${BL_INSIDE:-}" ]; then + if [ "${BL_ZRAM:-0}" = 1 ]; then printf 0 > /tmp/.bl-zram; else rm -f /tmp/.bl-zram; fi +fi steam_update_stuck() { [ "$1" -lt 60 ] || steam_updates=0 @@ -443,7 +446,6 @@ case $mode in step "client cores: $BL_CLIENT_CPUS" fi if [ "${BL_ZRAM:-0}" = 1 ]; then - printf 0 > /tmp/.bl-zram step "zRAM compression: on" ( bl_zram_scan() { @@ -492,8 +494,6 @@ case $mode in nap 5 done ) & - else - rm -f /tmp/.bl-zram fi if [ "${BL_LAUNCHER_CORES:-1}" != 0 ] && [ -n "${BL_LAUNCH_DIR:-}" ] && [ -z "${BL_DESKTOP:-}" ] \ && [ "${BL_STEAM_UI:-}" != desktop ] && [ -x /usr/local/bin/droiddeck-launcher-cores ]; then diff --git a/tools/linuxfs/preload/netif.c b/tools/linuxfs/preload/netif.c index 91ce93a067..1782d0f0d1 100644 --- a/tools/linuxfs/preload/netif.c +++ b/tools/linuxfs/preload/netif.c @@ -409,6 +409,8 @@ int bl_drm_gem_close(int fd, unsigned long request, void *arg, int *rc) __attrib int bl_venc_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden"))); int bl_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request, void *arg, void *caller, int *rc) __attribute__((visibility("hidden"))); +int bl_writewatch_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request, void *arg, + int *rc) __attribute__((visibility("hidden"))); int ioctl(int fd, unsigned long request, ...) { typedef int (*ioctl_fn)(int, unsigned long, void *); @@ -424,6 +426,7 @@ int ioctl(int fd, unsigned long request, ...) { if (bl_drm_gem_close(fd, request, arg, &rc)) return rc; if (real == NULL) real = (ioctl_fn) dlsym(RTLD_NEXT, "ioctl"); if (bl_winebus_rumble_ioctl(real, fd, request, arg, __builtin_return_address(0), &rc)) return rc; + if (bl_writewatch_ioctl(real, fd, request, arg, &rc)) return rc; if (!bl_kgsl_poll(real, fd, request, arg, &rc)) rc = quest_kgsl_ioctl(real, fd, request, arg); bl_kgsl_chip_id_fixup(request, arg, rc); if (arg == NULL || !is_link_query(request)) return rc; diff --git a/tools/linuxfs/preload/robust.c b/tools/linuxfs/preload/robust.c index 81bf5d8cc2..e156e82c54 100644 --- a/tools/linuxfs/preload/robust.c +++ b/tools/linuxfs/preload/robust.c @@ -329,6 +329,8 @@ static int execveat_is_execve(const long *args) { return path[0] == '/' || (int)args[0] == AT_FDCWD; } +int bl_writewatch_syscall(long number, const long *args, long (*real)(long, ...), long *rc) __attribute__((visibility("hidden"))); + long syscall(long number, ...) { va_list ap; long args[6]; @@ -354,6 +356,9 @@ long syscall(long number, ...) { if (!real_syscall) { real_syscall = (long (*)(long, ...)) dlsym(RTLD_NEXT, "syscall"); } + if (bl_writewatch_syscall(number, args, real_syscall, &handled)) { + return handled; + } if (number == SYS_openat2) { if (!__atomic_load_n(&openat2_missing, __ATOMIC_RELAXED)) { long fd = real_syscall(number, args[0], args[1], args[2], args[3]); diff --git a/tools/linuxfs/preload/tracer.c b/tools/linuxfs/preload/tracer.c index 7d8c741c47..572cf13e09 100644 --- a/tools/linuxfs/preload/tracer.c +++ b/tools/linuxfs/preload/tracer.c @@ -16,6 +16,8 @@ #define STATUS_MAX 16384 #define TRACER_FIELD "\nTracerPid:\t" +int bl_from_ntdll(const void *caller) __attribute__((visibility("hidden"))); + static const char *skip_digits(const char *s) { const char *end = s; while (isdigit((unsigned char)*end)) end++; @@ -77,7 +79,8 @@ __attribute__((visibility("hidden"))) int bl_status_without_tracer(const char *p int out = -1; long pid; - if ((flags & O_ACCMODE) != O_RDONLY || (pid = status_pid(path)) < 0 || is_web_helper(caller)) return -1; + if ((flags & O_ACCMODE) != O_RDONLY || (pid = status_pid(path)) < 0 || is_web_helper(caller) || bl_from_ntdll(caller)) + return -1; int in = (int)syscall(SYS_openat, AT_FDCWD, path, O_RDONLY | O_CLOEXEC); if (in < 0) goto done; for (;;) { diff --git a/tools/linuxfs/preload/usr2.c b/tools/linuxfs/preload/usr2.c new file mode 100644 index 0000000000..a7129fdc08 --- /dev/null +++ b/tools/linuxfs/preload/usr2.c @@ -0,0 +1,218 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static uintptr_t ntdll_lo, ntdll_hi; + +static int find_ntdll(struct dl_phdr_info *info, size_t size, void *data) { + (void)size; + (void)data; + const char *slash = strrchr(info->dlpi_name, '/'); + if (strcmp(slash ? slash + 1 : info->dlpi_name, "ntdll.so") != 0) return 0; + for (int i = 0; i < info->dlpi_phnum; i++) { + const ElfW(Phdr) *ph = &info->dlpi_phdr[i]; + if (ph->p_type != PT_LOAD || !(ph->p_flags & PF_X)) continue; + uintptr_t lo = info->dlpi_addr + ph->p_vaddr; + __atomic_store_n(&ntdll_hi, lo + ph->p_memsz, __ATOMIC_RELAXED); + __atomic_store_n(&ntdll_lo, lo, __ATOMIC_RELEASE); + return 1; + } + return 0; +} + +__attribute__((visibility("hidden"))) int bl_from_ntdll(const void *caller) { + uintptr_t pc = (uintptr_t)caller, lo = __atomic_load_n(&ntdll_lo, __ATOMIC_ACQUIRE); + if (!lo) { + dl_iterate_phdr(find_ntdll, NULL); + lo = __atomic_load_n(&ntdll_lo, __ATOMIC_ACQUIRE); + if (!lo) return 0; + } + return pc >= lo && pc < __atomic_load_n(&ntdll_hi, __ATOMIC_RELAXED); +} + +#if defined(__aarch64__) +#include +#include + +#define BL_STR2(x) #x +#define BL_STR(x) BL_STR2(x) + +#define BL_HWCAP_GCS (1UL << 32) +#define BL_FRAME_SIZE 4688 +#define BL_REGS 312 +#define BL_SP 560 +#define BL_PC 568 +#define BL_PSTATE 576 +#define BL_FPSIMD 592 + +struct bl_sigframe { + siginfo_t info; + ucontext_t uc; +}; + +struct bl_kernel_sigaction { + void (*handler)(int, siginfo_t *, void *); + unsigned long flags; + void *restorer; + uint64_t mask; +}; + +struct bl_usr2_call { + void (*handler)(int, siginfo_t *, void *); + uint64_t old_mask; +}; + +_Static_assert(sizeof(struct bl_sigframe) == BL_FRAME_SIZE, "rt_sigframe size"); +_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.regs) == BL_REGS, "regs offset"); +_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.sp) == BL_SP, "sp offset"); +_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.pc) == BL_PC, "pc offset"); +_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.pstate) == BL_PSTATE, "pstate offset"); +_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.__reserved) == BL_FPSIMD, "reserved offset"); +_Static_assert(sizeof(struct fpsimd_context) + sizeof(struct _aarch64_ctx) <= + sizeof(((mcontext_t *)0)->__reserved), "reserved space"); + +__attribute__((visibility("hidden"))) void bl_usr2_frame(struct bl_usr2_call *call); +__attribute__((visibility("hidden"), used)) void bl_usr2_run(struct bl_usr2_call *call, struct bl_sigframe *frame); + +__asm__(".text\n" + ".p2align 2\n" + ".type bl_usr2_frame, %function\n" + "bl_usr2_frame:\n" + " mov x16, #" BL_STR(BL_FRAME_SIZE) "\n" + " sub sp, sp, x16\n" + " add x17, sp, #" BL_STR(BL_REGS) "\n" + " stp x0, x1, [x17, #0]\n" + " stp x2, x3, [x17, #16]\n" + " stp x4, x5, [x17, #32]\n" + " stp x6, x7, [x17, #48]\n" + " stp x8, x9, [x17, #64]\n" + " stp x10, x11, [x17, #80]\n" + " stp x12, x13, [x17, #96]\n" + " stp x14, x15, [x17, #112]\n" + " stp xzr, xzr, [x17, #128]\n" + " stp x18, x19, [x17, #144]\n" + " stp x20, x21, [x17, #160]\n" + " stp x22, x23, [x17, #176]\n" + " stp x24, x25, [x17, #192]\n" + " stp x26, x27, [x17, #208]\n" + " stp x28, x29, [x17, #224]\n" + " str x30, [x17, #240]\n" + " str xzr, [x17, #0]\n" + " add x16, sp, x16\n" + " str x16, [sp, #" BL_STR(BL_SP) "]\n" + " adr x16, 1f\n" + " str x16, [sp, #" BL_STR(BL_PC) "]\n" + " mrs x16, nzcv\n" + " str x16, [sp, #" BL_STR(BL_PSTATE) "]\n" + " add x17, sp, #" BL_STR(BL_FPSIMD) "\n" + " mrs x16, fpsr\n" + " str w16, [x17, #8]\n" + " mrs x16, fpcr\n" + " str w16, [x17, #12]\n" + " stp q0, q1, [x17, #16]\n" + " stp q2, q3, [x17, #48]\n" + " stp q4, q5, [x17, #80]\n" + " stp q6, q7, [x17, #112]\n" + " stp q8, q9, [x17, #144]\n" + " stp q10, q11, [x17, #176]\n" + " stp q12, q13, [x17, #208]\n" + " stp q14, q15, [x17, #240]\n" + " stp q16, q17, [x17, #272]\n" + " stp q18, q19, [x17, #304]\n" + " stp q20, q21, [x17, #336]\n" + " stp q22, q23, [x17, #368]\n" + " stp q24, q25, [x17, #400]\n" + " stp q26, q27, [x17, #432]\n" + " stp q28, q29, [x17, #464]\n" + " stp q30, q31, [x17, #496]\n" + " mov x1, sp\n" + " bl bl_usr2_run\n" + " mov x8, #" BL_STR(__NR_rt_sigreturn) "\n" + " svc #0\n" + " brk #0\n" + "1:\n" + " ret\n" + ".size bl_usr2_frame, .-bl_usr2_frame\n"); + +static int (*usr2_real_raise)(int); + +static long usr2_sys(long nr, long a, long b, long c, long d) { + register long x8 __asm__("x8") = nr; + register long x0 __asm__("x0") = a; + register long x1 __asm__("x1") = b; + register long x2 __asm__("x2") = c; + register long x3 __asm__("x3") = d; + __asm__ volatile("svc #0" : "+r"(x0) : "r"(x8), "r"(x1), "r"(x2), "r"(x3) : "memory"); + return x0; +} + +static uint64_t usr2_ssbs(void) { + uint64_t value = 0; + if (getauxval(AT_HWCAP) & HWCAP_SSBS) __asm__ volatile("mrs %0, s3_3_c4_c2_6" : "=r"(value)); + return value & (1UL << 12); +} + +void bl_usr2_run(struct bl_usr2_call *call, struct bl_sigframe *frame) { + struct fpsimd_context *fp = (struct fpsimd_context *)frame->uc.uc_mcontext.__reserved; + struct _aarch64_ctx *end = (struct _aarch64_ctx *)(fp + 1); + + memset(&frame->info, 0, sizeof(frame->info)); + frame->info.si_signo = SIGUSR2; + frame->info.si_code = SI_TKILL; + frame->info.si_pid = (pid_t)usr2_sys(__NR_getpid, 0, 0, 0, 0); + frame->info.si_uid = (uid_t)usr2_sys(__NR_getuid, 0, 0, 0, 0); + frame->uc.uc_flags = 0; + frame->uc.uc_link = NULL; + if (usr2_sys(__NR_sigaltstack, 0, (long)&frame->uc.uc_stack, 0, 0) != 0) { + memset(&frame->uc.uc_stack, 0, sizeof(frame->uc.uc_stack)); + frame->uc.uc_stack.ss_flags = SS_DISABLE; + } + memset(&frame->uc.uc_sigmask, 0, sizeof(frame->uc.uc_sigmask)); + memcpy(&frame->uc.uc_sigmask, &call->old_mask, sizeof(call->old_mask)); + frame->uc.uc_mcontext.fault_address = 0; + frame->uc.uc_mcontext.pstate |= usr2_ssbs(); + fp->head.magic = FPSIMD_MAGIC; + fp->head.size = sizeof(*fp); + end->magic = 0; + end->size = 0; + call->handler(SIGUSR2, &frame->info, &frame->uc); +} + +int raise(int sig) { + int (*real)(int) = __atomic_load_n(&usr2_real_raise, __ATOMIC_ACQUIRE); + if (!real) { + real = (int (*)(int))dlsym(RTLD_NEXT, "raise"); + __atomic_store_n(&usr2_real_raise, real, __ATOMIC_RELEASE); + } + if (sig != SIGUSR2 || (getauxval(AT_HWCAP) & BL_HWCAP_GCS) || !bl_from_ntdll(__builtin_return_address(0))) { + return real(sig); + } + + struct bl_kernel_sigaction action; + if (usr2_sys(__NR_rt_sigaction, SIGUSR2, 0, (long)&action, sizeof(action.mask)) != 0) return real(sig); + if (!(action.flags & SA_SIGINFO) || (action.flags & SA_RESETHAND) || (uintptr_t)action.handler <= 1) { + return real(sig); + } + + uint64_t bit = 1ULL << (SIGUSR2 - 1); + uint64_t block = action.mask | ((action.flags & SA_NODEFER) ? 0 : bit); + struct bl_usr2_call call = {action.handler, 0}; + if (usr2_sys(__NR_rt_sigprocmask, SIG_BLOCK, (long)&block, (long)&call.old_mask, sizeof(block)) != 0) { + return real(sig); + } + if (call.old_mask & bit) { + usr2_sys(__NR_rt_sigprocmask, SIG_SETMASK, (long)&call.old_mask, 0, sizeof(call.old_mask)); + return real(sig); + } + bl_usr2_frame(&call); + return 0; +} +#endif diff --git a/tools/linuxfs/preload/writewatch.c b/tools/linuxfs/preload/writewatch.c new file mode 100644 index 0000000000..b804e3f39c --- /dev/null +++ b/tools/linuxfs/preload/writewatch.c @@ -0,0 +1,113 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +#define WINE_ARM64_USERFAULTFD 374 +#define PM_UFFD_WP (1ULL << 57) +#define PM_SWAP (1ULL << 62) +#define PM_PRESENT (1ULL << 63) + +#if defined(PAGEMAP_SCAN) && defined(UFFD_USER_MODE_ONLY) +static int ww_uffd = -1; +static int scan_blocked; +#endif + +__attribute__((visibility("hidden"))) int bl_writewatch_syscall(long number, const long *args, long (*real)(long, ...), long *rc) { +#if defined(__aarch64__) && defined(PAGEMAP_SCAN) && defined(UFFD_USER_MODE_ONLY) + if (number != WINE_ARM64_USERFAULTFD || (args[0] & ~(long)(O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY))) return 0; + *rc = real(SYS_userfaultfd, args[0]); + if (*rc >= 0) __atomic_store_n(&ww_uffd, (int)*rc, __ATOMIC_RELEASE); + return 1; +#else + (void)number; + (void)args; + (void)real; + (void)rc; + return 0; +#endif +} + +#if defined(PAGEMAP_SCAN) && defined(UFFD_USER_MODE_ONLY) +static int protect(int uffd, uint64_t start, uint64_t end) { + if (start == end) return 0; + struct uffdio_writeprotect wp = { .range = { start, end - start }, .mode = UFFDIO_WRITEPROTECT_MODE_WP }; + return ioctl(uffd, UFFDIO_WRITEPROTECT, &wp); +} + +static long emulate_scan(int fd, int uffd, struct pm_scan_arg *a) { + uint64_t page = (uint64_t)getpagesize(); + if (a->size < sizeof(*a) || (a->flags & ~(uint64_t)PM_SCAN_WP_MATCHING) || a->category_inverted || a->category_anyof_mask + || a->category_mask != PAGE_IS_WRITTEN || (a->return_mask & ~(uint64_t)PAGE_IS_WRITTEN) || a->end < a->start + || ((a->start | a->end) & (page - 1)) || (a->vec_len && !a->vec)) { + errno = EINVAL; + return -1; + } + struct page_region *vec = (struct page_region *)(uintptr_t)a->vec; + uint64_t regions = 0, pages = 0, addr = a->start, wp_start = 0, wp_end = 0; + uint64_t entries[512]; + int wp = (a->flags & PM_SCAN_WP_MATCHING) != 0; + while (addr < a->end) { + uint64_t want = (a->end - addr) / page; + if (want > 512) want = 512; + ssize_t got = pread(fd, entries, want * sizeof(entries[0]), (off_t)(addr / page * sizeof(entries[0]))); + if (got < 0) return -1; + if (got == 0) break; + for (uint64_t i = 0; i < (uint64_t)got / sizeof(entries[0]); i++, addr += page) { + uint64_t e = entries[i]; + if (!(e & (PM_PRESENT | PM_SWAP)) || (e & PM_UFFD_WP)) continue; + if (a->max_pages && pages >= a->max_pages) goto done; + if (a->vec_len) { + if (regions && vec[regions - 1].end == addr) { + vec[regions - 1].end += page; + } else { + if (regions == a->vec_len) goto done; + vec[regions].start = addr; + vec[regions].end = addr + page; + vec[regions].categories = PAGE_IS_WRITTEN & a->return_mask; + regions++; + } + } + pages++; + if (!wp) continue; + if (wp_end != addr) { + if (protect(uffd, wp_start, wp_end) < 0) return -1; + wp_start = addr; + } + wp_end = addr + page; + } + } +done: + if (wp && protect(uffd, wp_start, wp_end) < 0) return -1; + a->walk_end = addr < a->end ? addr : a->end; + return (long)regions; +} +#endif + +__attribute__((visibility("hidden"))) int bl_writewatch_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request, + void *arg, int *rc) { +#if defined(PAGEMAP_SCAN) && defined(UFFD_USER_MODE_ONLY) + if (request != PAGEMAP_SCAN) return 0; + int uffd = __atomic_load_n(&ww_uffd, __ATOMIC_ACQUIRE); + if (uffd < 0) return 0; + if (!__atomic_load_n(&scan_blocked, __ATOMIC_RELAXED)) { + *rc = real(fd, request, arg); + if (*rc >= 0 || errno != EACCES) return 1; + __atomic_store_n(&scan_blocked, 1, __ATOMIC_RELAXED); + } + *rc = (int)emulate_scan(fd, uffd, (struct pm_scan_arg *)arg); + return 1; +#else + (void)real; + (void)fd; + (void)request; + (void)arg; + (void)rc; + return 0; +#endif +} diff --git a/tools/linuxfs/preload/zram.c b/tools/linuxfs/preload/zram.c index 565e0f7dd0..8f31d19eb1 100644 --- a/tools/linuxfs/preload/zram.c +++ b/tools/linuxfs/preload/zram.c @@ -126,6 +126,25 @@ static void zr_walk(int compress) { zr_sys(SYS_close, maps); } +// Before it stops a session for suspend, the app waits for .ack. to appear (the handler +// runs here, not one a program installed over it) and then to hold a byte (the page-out finished). +static void zr_ack(int done) { + static const char suffix[] = ".ack."; + char path[sizeof(ZR_CTL) + sizeof(suffix) + 20]; + char digits[20]; + size_t n = 0, d = 0; + for (const char *p = ZR_CTL; *p; p++) path[n++] = *p; + for (const char *p = suffix; *p; p++) path[n++] = *p; + long pid = zr_sys(SYS_getpid); + do digits[d++] = (char)('0' + pid % 10); while ((pid /= 10) > 0); + while (d > 0) path[n++] = digits[--d]; + path[n] = 0; + int fd = (int)zr_sys(SYS_openat, AT_FDCWD, path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600); + if (fd < 0) return; + if (done) zr_sys(SYS_write, fd, "1", 1UL); + zr_sys(SYS_close, fd); +} + static void zr_handler(int sig, siginfo_t *info, void *context) { (void)sig; (void)context; @@ -136,7 +155,9 @@ static void zr_handler(int sig, siginfo_t *info, void *context) { && !__atomic_exchange_n(&zr_busy, 1, __ATOMIC_SEQ_CST)) { __atomic_store_n(&zr_pending, 0, __ATOMIC_SEQ_CST); int mode = zr_mode(); + if (mode == 1) zr_ack(0); if (mode >= 0) zr_walk(mode); + if (mode == 1) zr_ack(1); __atomic_store_n(&zr_busy, 0, __ATOMIC_SEQ_CST); } errno = saved; @@ -148,8 +169,6 @@ static void zr_child(void) { } __attribute__((constructor)) static void zr_init(void) { - const char *name = program_invocation_short_name; - if (strcmp(name, "steam") != 0 && strcmp(name, "steamwebhelper") != 0) return; void *libc = dlopen("libc.so.6", RTLD_LAZY | RTLD_NOLOAD); if (libc == NULL) return; zr_sys = (long (*)(long, ...))dlsym(libc, "syscall"); diff --git a/tools/msitools/packages.txt b/tools/msitools/packages.txt index 69a9dedba2..3d9637840f 100644 --- a/tools/msitools/packages.txt +++ b/tools/msitools/packages.txt @@ -2,4 +2,4 @@ 4028f44d83b2956ba2931d32aee8cceecbd6481e2febf86a3b6bfed69ef403d5 https://github.com/Droid-Deck/DroidDeck/releases/download/msitools-0.106-r1/libgsf-1.14.60-1-aarch64.pkg.tar.xz 3d7bd103313cb36d6cb703a5e583363e56ff255f105bcc0727916d195967976d https://github.com/Droid-Deck/DroidDeck/releases/download/msitools-0.106-r1/gcab-1.6-2-aarch64.pkg.tar.xz 87fe375a22de1519982234ce99f909ae13c06500784baaa1e8d7a0c0be0d14ee https://github.com/Droid-Deck/DroidDeck/releases/download/msitools-0.106-r1/cabextract-1.11-3-aarch64.pkg.tar.xz -e3bc83ac5960a4363f7ce05eb1d50b03d60d627a4a29f9b02c8e0466a5381b1f http://mirror.archlinuxarm.org/aarch64/extra/7zip-26.04-1-aarch64.pkg.tar.xz +e3bc83ac5960a4363f7ce05eb1d50b03d60d627a4a29f9b02c8e0466a5381b1f https://github.com/Droid-Deck/DroidDeck-Components/releases/download/build-dependency-7zip-26.04-r1/7zip-26.04-1-aarch64.pkg.tar.xz diff --git a/tools/proot/fastpath/fastpath.c b/tools/proot/fastpath/fastpath.c index 5056ec41ea..811b0057c8 100644 --- a/tools/proot/fastpath/fastpath.c +++ b/tools/proot/fastpath/fastpath.c @@ -337,34 +337,73 @@ static int to_guest(const char *h, char *g, size_t size) { return 0; } -static int guest_text(const char *h, char *g) { - int in = h[0] == '/' && under(h, root, rootlen); - for (int i = 0; h[0] == '/' && !in && i < nbinds; i++) { - int live = held(&binds[i]); - if (live < 0) return -1; - in = live && under(h, binds[i].host, binds[i].hlen); +static int host_order[MAX_BINDS + 1], norder, ordered; + +static int contains(const char *a, const char *b) { + size_t la = strlen(a); + return strlen(b) > la && under(b, a, la); +} + +static const char *side_of(int i, int host) { + return host ? (i < 0 ? root : binds[i].host) : (i < 0 ? "/" : binds[i].guest); +} + +static int insort(int *list, int m, int i, int host) { + const char *p = side_of(i, host); + int prev = -1; + for (int j = 0; j < m; j++) { + const char *q = side_of(list[j], host); + if (!strcmp(p, q) && !host) { + list[j] = i; + return m; + } + if (!strcmp(p, q) || contains(p, q)) prev = j; } - if (in) return to_guest(h, g, PATH_MAX); - memcpy(g, h, strlen(h) + 1); + memmove(list + prev + 2, list + prev + 1, (m - prev - 1) * sizeof *list); + list[prev + 1] = i; + return m + 1; +} + +static int order_binds(void) { + if (__atomic_load_n(&ordered, __ATOMIC_ACQUIRE)) return 0; + for (int i = 0; i < nbinds; i++) + if (held(&binds[i]) < 0) return -1; + if (pthread_mutex_trylock(&bind_lock) != 0) return -1; + if (!ordered) { + int pending[MAX_BINDS + 1], m = 1; + pending[0] = -1; + for (int i = 0; i < nbinds; i++) + if (!binds[i].dropped) m = insort(pending, m, i, 0); + norder = 0; + for (int j = m - 1; j >= 0; j--) norder = insort(host_order, norder, pending[j], 1); + __atomic_store_n(&ordered, 1, __ATOMIC_RELEASE); + } + pthread_mutex_unlock(&bind_lock); return 0; } static int host_bind(const char *h) { - int found = -1; - for (int i = 0; i < nbinds; i++) { - int live = held(&binds[i]); - if (live < 0) return -2; - if (!live || !under(h, binds[i].host, binds[i].hlen)) continue; - if (found < 0 || binds[i].hlen > binds[found].hlen) found = i; - else if (binds[i].hlen == binds[found].hlen && strcmp(binds[i].guest, binds[found].guest) != 0) found = -3; - } - return found == -3 ? -2 : found; + if (order_binds() < 0) return -2; + for (int j = 0; j < norder; j++) + if (host_order[j] >= 0 && under(h, binds[host_order[j]].host, binds[host_order[j]].hlen)) return host_order[j]; + return -1; +} + +static int guest_text(const char *h, char *g) { + if (h[0] == '/' && under(h, root, rootlen)) return to_guest(h, g, PATH_MAX); + int i = h[0] == '/' ? host_bind(h) : -1; + if (i == -2) return -1; + if (i >= 0) + return snprintf(g, PATH_MAX, "%s%s", binds[i].guest, h + binds[i].hlen) >= PATH_MAX || reserved(g) ? -1 : 0; + memcpy(g, h, strlen(h) + 1); + return 0; } static long detranslated(char *text, const char *at) { if (text[0] != '/') return 0; if (!under(at, root, rootlen) && !under(text, root, rootlen)) { int own = host_bind(at), to = host_bind(text); + if (to == -1) return 0; if (own == -2 || to == -2) return FP_SLOW; if (own >= 0 && to >= 0 && strcmp(binds[own].host, binds[to].host) == 0) { const struct bind *bd = &binds[to]; @@ -635,8 +674,9 @@ static long resolve_in(const char *base, const char *path, int follow, struct re char norm[PATH_MAX]; size_t o = 0; int dotdot = 0; - size_t plen = strlen(path); - int trailing = plen > 1 && path[plen - 1] == '/'; + size_t plen = strlen(path), end = plen; + while (end > 1 && path[end - 1] == '/') end--; + int trailing = (plen > 1 && path[plen - 1] == '/') || (end > 0 && path[end - 1] == '.' && (end == 1 || path[end - 2] == '/')); for (int part = base ? 0 : 1; part < 2; part++) { for (const char *c = part ? path : base; *c;) { while (*c == '/') c++; diff --git a/tools/release/authorship_hook.py b/tools/release/authorship_hook.py index 3129f76153..82d0842c91 100644 --- a/tools/release/authorship_hook.py +++ b/tools/release/authorship_hook.py @@ -4,7 +4,7 @@ from pathlib import Path import subprocess import sys -from check_authorship import BOT, COAUTHOR, check_revision +from check_authorship import COAUTHOR, check_revision, is_bot def main(): @@ -23,13 +23,13 @@ def main(): return 1 else: identity = subprocess.check_output(["git", "var", "GIT_AUTHOR_IDENT"], text=True) - if BOT.search(identity): + if is_bot(identity): print("Bot commit author is forbidden: " + identity.strip(), file=sys.stderr) return 1 message = Path(args[0]) original = message.read_text(encoding="utf-8") cleaned = "".join(line for line in original.splitlines(keepends=True) - if not (COAUTHOR.match(line) and BOT.search(line))) + if not (COAUTHOR.match(line) and is_bot(line))) if cleaned != original: message.write_text(cleaned, encoding="utf-8") print("Removed bot co-author trailers; human credits preserved.", file=sys.stderr) diff --git a/tools/release/check_authorship.py b/tools/release/check_authorship.py index 9d952acc0d..37e2a716a4 100644 --- a/tools/release/check_authorship.py +++ b/tools/release/check_authorship.py @@ -6,15 +6,34 @@ import re import subprocess import sys -BOT = re.compile( - r"Claude|Anthropic|OpenAI|ChatGPT|GPT|Copilot|Cursor|Gemini|Codex|Devin|" - r"Windsurf|Codeium|Amazon Q|Tabnine|Cody|\[bot\]|github-actions|" - r"dependabot|renovate(?:\[bot\])?", +PRODUCT = re.compile( + r"(?")[0].strip() + name = COAUTHOR.sub("", name).strip() + return bool(PRODUCT.search(name) or PRODUCT.search(email) or BOT_DOMAIN.search(email) + or ASSISTANT_ALONE.fullmatch(name) or ASSISTANT_PRODUCT.search(name)) + + def commit_violations(commit, raw): header, separator, message = raw.partition(b"\n\n") if not separator: @@ -24,10 +43,10 @@ def commit_violations(commit, raw): return [f"{commit}: expected one author"] identity = authors[0].decode("utf-8", errors="replace") errors = [] - if BOT.search(identity): + if is_bot(identity): errors.append(f"{commit}: bot author: {identity}") for line in message.decode("utf-8", errors="replace").splitlines(): - if COAUTHOR.match(line) and BOT.search(line): + if COAUTHOR.match(line) and is_bot(line): errors.append(f"{commit}: bot co-author: {line.strip()}") return errors @@ -36,11 +55,11 @@ def event_violations(event): pr = event.get("pull_request", {}) user = pr.get("user", {}) errors = [] - if user.get("type") == "Bot" or BOT.search(user.get("login", "")): + if user.get("type") == "Bot" or is_bot(user.get("login", "")): errors.append("pull request: bot authorship is forbidden") for field in ("title", "body"): for line in (pr.get(field) or "").splitlines(): - if COAUTHOR.match(line) and BOT.search(line): + if COAUTHOR.match(line) and is_bot(line): errors.append(f"pull request {field}: bot co-author trailer") return errors diff --git a/tools/tests/test_authorship.py b/tools/tests/test_authorship.py index 03d0003b04..6734eb92dc 100644 --- a/tools/tests/test_authorship.py +++ b/tools/tests/test_authorship.py @@ -40,6 +40,27 @@ class AuthorshipTest(unittest.TestCase): def test_bot_pr_author_is_rejected(self): self.assertTrue(check.event_violations({"pull_request": {"user": {"login": "service", "type": "Bot"}}})) + def test_people_named_like_assistants_are_not_bots(self): + for author in ("Claudemirovsky <63046606+Claudemirovsky@users.noreply.github.com>", + "Claude Monet ", "Devin Smith ", + "Cody Allen ", "Gemini Patel "): + with self.subTest(author=author): + self.assertEqual([], check.commit_violations("abc", self.commit(author=author))) + self.assertEqual([], check.event_violations({"pull_request": {"user": {"login": "Claudemirovsky", "type": "User"}}})) + + def test_assistant_identities_are_still_bots(self): + for author in ("Claude Opus 5.5 ", "Claude Code ", + "Cursor Agent ", + "Devin AI ", + "Gemini ", "GPT-5 "): + with self.subTest(author=author): + self.assertTrue(check.commit_violations("abc", self.commit(author=author))) + for login in ("chatgpt-codex-connector", "Copilot", "claude"): + with self.subTest(login=login): + self.assertTrue(check.event_violations({"pull_request": {"user": {"login": login, "type": "User"}}})) + message = "Fix\n\nCo-authored-by: Claude Opus 5.5 \n" + self.assertEqual(1, len(check.commit_violations("abc", self.commit(message=message)))) + def test_missing_author_fails_closed(self): self.assertTrue(check.commit_violations("abc", b"tree 000\n\nmessage\n")) diff --git a/tools/tests/test_fastpath_bind_names.py b/tools/tests/test_fastpath_bind_names.py new file mode 100644 index 0000000000..2e8a8b11f2 --- /dev/null +++ b/tools/tests/test_fastpath_bind_names.py @@ -0,0 +1,139 @@ +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + +FASTPATH = Path(__file__).resolve().parents[1] / "proot/fastpath/fastpath.c" + +PROGRAM = r""" +#include "FASTPATH" + +static long host_sys(long nr, long a, long b, long c, long d, long e, long f) { + long r = syscall(nr, a, b, c, d, e, f); + return r < 0 ? -errno : r; +} + +int main(int argc, char **argv) { + static char hosts[MAX_BINDS][PATH_MAX], guests[MAX_BINDS][512]; + fp_sys = host_sys; + snprintf(root, sizeof root, "%s", argv[1]); + rootlen = strlen(root); + int i = 2; + for (; i + 1 < argc && strcmp(argv[i], "--"); i += 2) { + struct bind *bd = &binds[nbinds]; + bd->host = hosts[nbinds]; + bd->guest = guests[nbinds]; + snprintf(bd->host, PATH_MAX, "%s", argv[i]); + snprintf(bd->guest, sizeof guests[0], "%s", argv[i + 1]); + bd->hlen = strlen(bd->host); + bd->glen = strlen(bd->guest); + nbinds++; + } + pthread_once(&init_once, fp_init); + fp_on = 1; + for (i++; i < argc; i++) { + char text[PATH_MAX]; + if (!strcmp(argv[i], "name")) { + if (guest_text(argv[++i], text) < 0) strcpy(text, "SLOW"); + puts(text); + } else if (!strcmp(argv[i], "link")) { + snprintf(text, sizeof text, "%s", argv[i + 2]); + if (detranslated(text, argv[i + 1]) == FP_SLOW) strcpy(text, "SLOW"); + i += 2; + puts(text); + } else if (!strcmp(argv[i], "lstat")) { + struct stat st; + long r = fstatat(AT_FDCWD, argv[++i], &st, AT_SYMLINK_NOFOLLOW); + puts(r < 0 ? "error" : S_ISDIR(st.st_mode) ? "dir" : S_ISLNK(st.st_mode) ? "link" : "other"); + } + } + return 0; +} +""" + + +class FastPathBindNamesTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + if shutil.which("gcc") is None: + raise unittest.SkipTest("gcc is not available") + cls.work = Path(tempfile.mkdtemp()) + source = cls.work / "names.c" + source.write_text(PROGRAM.replace("FASTPATH", str(FASTPATH))) + cls.program = cls.work / "names" + subprocess.run(["gcc", "-O1", "-w", "-pthread", "-o", str(cls.program), str(source), "-ldl"], check=True) + t = cls.work / "tree" + for d in ["root/etc", "root/mnt", "root/opt", "root/d/real", "lib/common/game", "fonts", "a", "b"]: + (t / d).mkdir(parents=True, exist_ok=True) + for f in ["root/etc/x", "lib/f", "lib/common/game/f", "fonts/f", "a/f", "b/f"]: + (t / f).touch() + os.symlink(t / "lib/f", t / "lib/l2") + os.symlink(t / "lib/common", t / "lib/l") + os.symlink("real", t / "root/d/link") + cls.tree = t + cls.binds = [ + (t / "lib", "/mnt/droiddeck-sd"), + (t / "lib", "/mnt/bannerlator-sd"), + (t / "lib", "/mnt/DroidDeck-SD"), + (t / "lib/common", "/opt/common"), + (t / "fonts", "/usr/share/fonts/android"), + (t / "a", "/opt/g"), + (t / "b", "/opt/g"), + (t / "fonts", "/mnt/x"), + ] + + @classmethod + def tearDownClass(cls): + shutil.rmtree(cls.work, ignore_errors=True) + + def ask(self, *queries): + argv = [str(self.program), str(self.tree / "root")] + for host, guest in self.binds: + argv += [str(host), guest] + argv.append("--") + for q in queries: + argv += [str(x) for x in q] + out = subprocess.run(argv, capture_output=True, text=True, timeout=20, check=True).stdout + return out.splitlines() + + def test_a_host_file_takes_the_name_proot_gives_it(self): + t = self.tree + self.assertEqual(self.ask( + ("name", t / "lib/f"), + ("name", t / "lib/common/game/f"), + ("name", t / "fonts/f"), + ("name", t / "b/f"), + ("name", t / "a/f"), + ("name", t / "root/etc/x"), + ), [ + "/mnt/droiddeck-sd/f", + "/opt/common/game/f", + "/usr/share/fonts/android/f", + "/opt/g/f", + str(t / "a/f"), + "/etc/x", + ]) + + def test_a_link_inside_a_library_reads_back_like_proot(self): + t = self.tree + self.assertEqual(self.ask( + ("link", t / "lib/l2", t / "lib/f"), + ("link", t / "lib/l", t / "lib/common"), + ), [ + "/mnt/droiddeck-sd/f", + str(t / "lib/common"), + ]) + + def test_a_final_dot_follows_the_link(self): + self.assertEqual(self.ask( + ("lstat", "/d/link"), + ("lstat", "/d/link/."), + ("lstat", "/d/link/./"), + ("lstat", "/d/link/"), + ), ["link", "dir", "dir", "dir"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_fsync_preload.py b/tools/tests/test_fsync_preload.py index c2242f4945..63007f3734 100644 --- a/tools/tests/test_fsync_preload.py +++ b/tools/tests/test_fsync_preload.py @@ -319,7 +319,7 @@ class FsyncPreloadTest(unittest.TestCase): source = base / "fsync-test.c" source.write_text(PROGRAM) subprocess.run(["cc", "-O2", "-Wall", "-fPIC", "-shared", "-pthread", "-o", str(cls.lib), - str(PRELOAD / "fsync.c"), str(PRELOAD / "robust.c"), str(PRELOAD / "noexec.c"), "-ldl"], check=True) + str(PRELOAD / "fsync.c"), str(PRELOAD / "robust.c"), str(PRELOAD / "noexec.c"), str(PRELOAD / "writewatch.c"), "-ldl"], check=True) subprocess.run(["cc", "-O2", "-Wall", "-pthread", "-o", str(cls.exe), str(source)], check=True) @classmethod diff --git a/tools/tests/test_noexec_preload.py b/tools/tests/test_noexec_preload.py index 0e563ec49a..20a437d4cb 100644 --- a/tools/tests/test_noexec_preload.py +++ b/tools/tests/test_noexec_preload.py @@ -43,7 +43,7 @@ class NoexecPreloadTest(unittest.TestCase): cls.tmp = Path(tempfile.mkdtemp()) cls.lib = cls.tmp / "libnoexec.so" subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-fPIC", "-shared", "-pthread", "-DNOEXEC_TEST", "-o", str(cls.lib), - str(PRELOAD / "noexec.c"), str(PRELOAD / "fsync.c"), str(PRELOAD / "robust.c"), "-ldl"], check=True) + str(PRELOAD / "noexec.c"), str(PRELOAD / "fsync.c"), str(PRELOAD / "robust.c"), str(PRELOAD / "writewatch.c"), "-ldl"], check=True) source = cls.tmp / "program.c" source.write_text(PROGRAM) for name in ("FEX", "game"): diff --git a/tools/tests/test_openat2_preload.py b/tools/tests/test_openat2_preload.py index a30aa74dda..eb27bcc7eb 100644 --- a/tools/tests/test_openat2_preload.py +++ b/tools/tests/test_openat2_preload.py @@ -230,7 +230,7 @@ class Openat2PreloadTest(unittest.TestCase): cls.tmp = Path(tempfile.mkdtemp()) cls.lib = cls.tmp / "libopenat2.so" subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-fPIC", "-shared", "-pthread", "-o", str(cls.lib), - str(PRELOAD / "robust.c"), str(PRELOAD / "fsync.c"), str(PRELOAD / "noexec.c"), "-ldl"], check=True) + str(PRELOAD / "robust.c"), str(PRELOAD / "fsync.c"), str(PRELOAD / "noexec.c"), str(PRELOAD / "writewatch.c"), "-ldl"], check=True) source = cls.tmp / "openat2.c" source.write_text(PROGRAM) subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-o", str(cls.tmp / "openat2"), str(source), "-ldl"], check=True) diff --git a/tools/tests/test_pipewire_helper.py b/tools/tests/test_pipewire_helper.py index e8abd59fcc..8e0c2343b3 100644 --- a/tools/tests/test_pipewire_helper.py +++ b/tools/tests/test_pipewire_helper.py @@ -74,6 +74,36 @@ class PipeWireHelperTest(unittest.TestCase): self.assertIn('did not open', result.stderr) self.assertFalse((self.runtime / 'droiddeck-pipewire/pids').exists()) + def test_clients_get_full_access_without_the_flatpak_check(self): + self.pack('python3 -c "import socket,sys; s=socket.socket(socket.AF_UNIX); s.bind(sys.argv[1]); ' + 'import time; time.sleep(30)" "$XDG_RUNTIME_DIR/pipewire-0"') + for _ in range(2): + result = self.run_helper('start') + self.assertEqual(result.returncode, 0, result.stderr) + daemon = (self.dir / 'share/pipewire/pipewire.conf.d/droiddeck-access.conf').read_text() + self.assertIn('module.access = false', daemon) + self.assertIn('name = libpipewire-module-access', daemon) + self.assertIn('access.socket = { pipewire-0 = "unrestricted", pipewire-0-manager = "unrestricted" }', + daemon) + self.assertNotIn('access.legacy', daemon) + manager = (self.dir / 'share/wireplumber/wireplumber.conf.d/droiddeck-access.conf').read_text() + self.assertIn('matches = [ { pipewire.access = "unrestricted" } ]', manager) + self.assertIn('default_permissions = "all"', manager) + + def test_start_fails_cleanly_when_the_access_settings_cannot_be_written(self): + self.pack('exec sleep 30') + self.run_helper('start') + self.run_helper('stop') + conf = self.dir / 'share/pipewire/pipewire.conf.d' + for child in conf.iterdir(): + child.unlink() + conf.rmdir() + conf.write_text('') + result = self.run_helper('start') + self.assertNotEqual(result.returncode, 0) + self.assertIn('could not write the access settings', result.stderr) + self.assertFalse((self.runtime / 'droiddeck-pipewire/pids').exists()) + def test_unchanged_bundle_is_not_unpacked_again(self): self.pack('exec sleep 30') self.run_helper('start') diff --git a/tools/tests/test_tracer_preload.py b/tools/tests/test_tracer_preload.py new file mode 100644 index 0000000000..90a4442248 --- /dev/null +++ b/tools/tests/test_tracer_preload.py @@ -0,0 +1,154 @@ +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + +PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload" + +NTDLL = r""" +#define _GNU_SOURCE +#include +#include +#include +#include + +__attribute__((noinline)) int ntdll_open(const char *path) { + int fd = open(path, O_RDONLY | O_CLOEXEC); + __asm__ volatile("" ::: "memory"); + return fd; +} + +__attribute__((noinline)) int ntdll_openat(const char *path) { + int fd = openat(AT_FDCWD, path, O_RDONLY | O_CLOEXEC); + __asm__ volatile("" ::: "memory"); + return fd; +} + +__attribute__((noinline)) FILE *ntdll_fopen(const char *path) { + FILE *f = fopen(path, "r"); + __asm__ volatile("" ::: "memory"); + return f; +} +""" + +PROGRAM = r""" +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +int ntdll_open(const char *path); +int ntdll_openat(const char *path); +FILE *ntdll_fopen(const char *path); + +static void report(const char *name, int fd) { + char link[64], target[256] = "", text[16384], *field; + ssize_t n; + long tracer = -1; + if (fd < 0) { + printf("%s failed\n", name); + return; + } + snprintf(link, sizeof(link), "/proc/self/fd/%d", fd); + n = readlink(link, target, sizeof(target) - 1); + target[n > 0 ? n : 0] = '\0'; + n = pread(fd, text, sizeof(text) - 1, 0); + text[n > 0 ? n : 0] = '\0'; + if ((field = strstr(text, "\nTracerPid:\t")) != NULL) tracer = strtol(field + 12, NULL, 10); + const char *kind = strncmp(target, "/proc/", 6) == 0 ? "proc" + : strncmp(target, "/memfd:", 7) == 0 ? "memfd" + : strncmp(target, "/tmp/.droiddeck-status-", 23) == 0 ? "copy" : target; + printf("%s kind=%s tracer=%s rdonly=%d vm=%d\n", name, kind, tracer == 0 ? "hidden" : tracer > 0 ? "shown" : "missing", + (fcntl(fd, F_GETFL) & O_ACCMODE) == O_RDONLY, strstr(text, "\nVmRSS:") != NULL); + close(fd); +} + +static void report_stream(const char *name, FILE *f) { + if (f == NULL) { + printf("%s failed\n", name); + return; + } + report(name, dup(fileno(f))); + fclose(f); +} + +int main(void) { + int ready[2]; + if (pipe(ready) != 0) return 1; + pid_t child = fork(); + if (child == 0) { + char ok = ptrace(PTRACE_TRACEME, 0, NULL, NULL) == 0; + if (write(ready[1], &ok, 1) != 1) _exit(1); + for (;;) pause(); + } + char ok = 0; + if (read(ready[0], &ok, 1) != 1 || !ok) { + kill(child, SIGKILL); + waitpid(child, NULL, 0); + puts("no ptrace"); + return 0; + } + char other[64], self[64]; + snprintf(other, sizeof(other), "/proc/%d/status", (int)child); + snprintf(self, sizeof(self), "/proc/%d/status", (int)getpid()); + report("main_other_open", open(other, O_RDONLY | O_CLOEXEC)); + report_stream("main_other_fopen", fopen(other, "r")); + report("main_self_open", open("/proc/self/status", O_RDONLY | O_CLOEXEC)); + report("ntdll_other_open", ntdll_open(other)); + report("ntdll_other_openat", ntdll_openat(other)); + report_stream("ntdll_other_fopen", ntdll_fopen(other)); + report_stream("ntdll_self_fopen", ntdll_fopen(self)); + kill(child, SIGKILL); + waitpid(child, NULL, 0); + return 0; +} +""" + + +class TracerPreloadTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + if not shutil.which("cc"): + raise unittest.SkipTest("no compiler") + cls.tmp = tempfile.TemporaryDirectory() + tmp = Path(cls.tmp.name) + (tmp / "ntdll.c").write_text(NTDLL) + (tmp / "prog.c").write_text(PROGRAM) + sources = sorted(str(p) for p in PRELOAD.glob("*.c")) + subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-Wall", "-pthread", "-o", str(tmp / "libblsession.so"), *sources, "-ldl"], + check=True) + subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-o", str(tmp / "ntdll.so"), str(tmp / "ntdll.c")], check=True) + subprocess.run(["cc", "-O1", "-o", str(tmp / "prog"), str(tmp / "prog.c"), str(tmp / "ntdll.so"), "-Wl,-rpath," + str(tmp)], + check=True) + env = dict(os.environ, LD_PRELOAD=str(tmp / "libblsession.so")) + out = subprocess.run([str(tmp / "prog")], env=env, capture_output=True, text=True, timeout=60) + if out.returncode != 0: + raise AssertionError(out.stdout + out.stderr) + if "no ptrace" in out.stdout: + raise unittest.SkipTest("ptrace not allowed") + cls.lines = dict(line.split(" ", 1) for line in out.stdout.splitlines()) + + @classmethod + def tearDownClass(cls): + cls.tmp.cleanup() + + def test_other_programs_still_see_no_tracer(self): + self.assertEqual(self.lines["main_other_open"], "kind=copy tracer=hidden rdonly=1 vm=1") + self.assertEqual(self.lines["main_other_fopen"], "kind=copy tracer=hidden rdonly=1 vm=1") + self.assertEqual(self.lines["main_self_open"], "kind=memfd tracer=hidden rdonly=0 vm=1") + + def test_wine_reads_the_real_status_file(self): + for name in ("ntdll_other_open", "ntdll_other_openat", "ntdll_other_fopen"): + self.assertEqual(self.lines[name], "kind=proc tracer=shown rdonly=1 vm=1", name) + self.assertEqual(self.lines["ntdll_self_fopen"], "kind=proc tracer=hidden rdonly=1 vm=1") + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_usr2_preload.py b/tools/tests/test_usr2_preload.py new file mode 100644 index 0000000000..4a180df393 --- /dev/null +++ b/tools/tests/test_usr2_preload.py @@ -0,0 +1,301 @@ +import ctypes +import os +from pathlib import Path +import platform +import shutil +import subprocess +import tempfile +import unittest + +PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload" + +NTDLL = r""" +#include +__attribute__((noinline)) void syscall_dispatcher_return_slowpath(void) { raise(SIGUSR2); } +void slowpath(void) { + syscall_dispatcher_return_slowpath(); + __asm__ volatile("" ::: "memory"); +} +void slowpath_other(int sig) { + raise(sig); + __asm__ volatile("" ::: "memory"); +} +""" + +PROGRAM = r""" +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void slowpath(void); +void slowpath_other(int sig); + +static char altstack[65536]; +static char landing_stack[65536] __attribute__((aligned(16))); +static volatile int mode; +static int calls; +static volatile int on_alt, usr2_blocked, usr1_blocked, code_ok, stack_ok; +static volatile long handler_sp; +static jmp_buf back; +static uint64_t saved[31]; +static unsigned __int128 saved_v[32]; +static uint32_t saved_fpsr; + +void landing(void); +__asm__(".text\n.globl landing\n.type landing, %function\nlanding:\n" + " sub sp, sp, #784\n" + " stp x0, x1, [sp, #0]\n stp x2, x3, [sp, #16]\n stp x4, x5, [sp, #32]\n stp x6, x7, [sp, #48]\n" + " stp x8, x9, [sp, #64]\n stp x10, x11, [sp, #80]\n stp x12, x13, [sp, #96]\n stp x14, x15, [sp, #112]\n" + " stp x16, x17, [sp, #128]\n stp x18, x19, [sp, #144]\n stp x20, x21, [sp, #160]\n stp x22, x23, [sp, #176]\n" + " stp x24, x25, [sp, #192]\n stp x26, x27, [sp, #208]\n stp x28, x29, [sp, #224]\n str x30, [sp, #240]\n" + " add x9, sp, #256\n" + " stp q0, q1, [x9, #0]\n stp q2, q3, [x9, #32]\n stp q4, q5, [x9, #64]\n stp q6, q7, [x9, #96]\n" + " stp q8, q9, [x9, #128]\n stp q10, q11, [x9, #160]\n stp q12, q13, [x9, #192]\n stp q14, q15, [x9, #224]\n" + " stp q16, q17, [x9, #256]\n stp q18, q19, [x9, #288]\n stp q20, q21, [x9, #320]\n stp q22, q23, [x9, #352]\n" + " stp q24, q25, [x9, #384]\n stp q26, q27, [x9, #416]\n stp q28, q29, [x9, #448]\n stp q30, q31, [x9, #480]\n" + " mrs x10, fpsr\n str w10, [sp, #768]\n" + " mov x0, sp\n bl landed\n brk #0\n"); + +void landed(uint64_t *regs) { + memcpy(saved, regs, sizeof(saved)); + memcpy(saved_v, regs + 32, sizeof(saved_v)); + saved_fpsr = *(uint32_t *)(regs + 96); + longjmp(back, 1); +} + +static struct fpsimd_context *fpsimd_of(ucontext_t *uc) { + struct _aarch64_ctx *c = (struct _aarch64_ctx *)uc->uc_mcontext.__reserved; + while (c->magic) { + if (c->magic == FPSIMD_MAGIC) return (struct fpsimd_context *)c; + c = (struct _aarch64_ctx *)((char *)c + c->size); + } + return NULL; +} + +static void handler(int sig, siginfo_t *info, void *ctx) { + ucontext_t *uc = ctx; + sigset_t now; + long sp = (long)&now; + __atomic_add_fetch(&calls, 1, __ATOMIC_RELAXED); + handler_sp = sp; + on_alt = sp >= (long)altstack && sp < (long)altstack + (long)sizeof(altstack); + pthread_sigmask(SIG_BLOCK, NULL, &now); + usr2_blocked = sigismember(&now, SIGUSR2); + usr1_blocked = sigismember(&now, SIGUSR1); + code_ok = sig == SIGUSR2 && info->si_signo == SIGUSR2 && info->si_code == SI_TKILL && info->si_pid == getpid(); + stack_ok = uc->uc_stack.ss_sp == altstack && uc->uc_stack.ss_size == sizeof(altstack) && !(uc->uc_stack.ss_flags & SS_DISABLE); + if (mode == 1) { + struct fpsimd_context *fp = fpsimd_of(uc); + for (int i = 0; i <= 28; i++) uc->uc_mcontext.regs[i] = 0x1000 + i; + uc->uc_mcontext.regs[29] = 0x2900; + uc->uc_mcontext.regs[30] = 0x3000; + uc->uc_mcontext.sp = (uint64_t)(landing_stack + sizeof(landing_stack)); + uc->uc_mcontext.pc = (uint64_t)landing; + uc->uc_mcontext.pstate = 0x60000000; + for (int i = 0; i < 32; i++) fp->vregs[i] = ((unsigned __int128)(0x7700 + i) << 64) | (0x5500 + i); + fp->fpsr = 0x8; + } +} + +static void usr1(int sig, siginfo_t *info, void *ctx) { + (void)sig; + (void)info; + (void)ctx; +} + +uint64_t kept_x[10]; +double kept_d[8]; + +static int keep_callee_saved(void) { + uint64_t *out = kept_x; + double *d = kept_d; + __asm__ volatile( + "mov x19, #19\n mov x20, #20\n mov x21, #21\n mov x22, #22\n mov x23, #23\n" + "mov x24, #24\n mov x25, #25\n mov x26, #26\n mov x27, #27\n mov x28, #28\n" + "fmov d8, #1.0\n fmov d9, #2.0\n fmov d10, #3.0\n fmov d11, #4.0\n" + "fmov d12, #5.0\n fmov d13, #6.0\n fmov d14, #7.0\n fmov d15, #8.0\n" + "bl slowpath\n" + "adrp x0, kept_x\n add x0, x0, :lo12:kept_x\n" + "stp x19, x20, [x0, #0]\n stp x21, x22, [x0, #16]\n stp x23, x24, [x0, #32]\n" + "stp x25, x26, [x0, #48]\n stp x27, x28, [x0, #64]\n" + "adrp x0, kept_d\n add x0, x0, :lo12:kept_d\n" + "stp d8, d9, [x0, #0]\n stp d10, d11, [x0, #16]\n stp d12, d13, [x0, #32]\n stp d14, d15, [x0, #48]\n" + : + : + : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", + "x16", "x17", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "x30", + "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", + "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", + "v31", "memory", "cc"); + for (int i = 0; i < 10; i++) + if (out[i] != (uint64_t)(19 + i)) return 0; + for (int i = 0; i < 8; i++) + if (d[i] != (double)(i + 1)) return 0; + return 1; +} + +static void *stress(void *arg) { + (void)arg; + for (int i = 0; i < 2000; i++) slowpath(); + return NULL; +} + +int main(int argc, char **argv) { + stack_t ss = {.ss_sp = altstack, .ss_size = sizeof(altstack), .ss_flags = 0}; + struct sigaction sa; + sigset_t mask, now; + sigaltstack(&ss, NULL); + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = handler; + sa.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGUSR1); + sigaction(SIGUSR2, &sa, NULL); + sa.sa_sigaction = usr1; + sigemptyset(&sa.sa_mask); + sigaction(SIGUSR1, &sa, NULL); + + if (argc > 1 && strcmp(argv[1], "bench") == 0) { + int n = argc > 2 ? atoi(argv[2]) : 20000; + struct timespec a, b; + clock_gettime(CLOCK_MONOTONIC, &a); + for (int i = 0; i < n; i++) slowpath(); + clock_gettime(CLOCK_MONOTONIC, &b); + printf("%.2f us per raise, alt %d\n", ((b.tv_sec - a.tv_sec) * 1e9 + (b.tv_nsec - a.tv_nsec)) / 1e3 / n, on_alt); + return 0; + } + + mode = 0; + calls = 0; + int kept = keep_callee_saved(); + pthread_sigmask(SIG_BLOCK, NULL, &now); + printf("returned calls=%d kept=%d usr2_blocked=%d usr1_blocked=%d code=%d stack=%d after_usr2=%d after_usr1=%d\n", + calls, kept, usr2_blocked, usr1_blocked, code_ok, stack_ok, sigismember(&now, SIGUSR2), + sigismember(&now, SIGUSR1)); + printf("path %s\n", on_alt ? "kernel" : "inline"); + + mode = 1; + calls = 0; + if (!setjmp(back)) { + slowpath(); + printf("redirect did not happen\n"); + } else { + int ok = 1; + for (int i = 0; i <= 28; i++) + if (saved[i] != (uint64_t)(0x1000 + i)) ok = 0; + if (saved[29] != 0x2900 || saved[30] != 0x3000) ok = 0; + for (int i = 0; i < 32; i++) + if (saved_v[i] != (((unsigned __int128)(0x7700 + i) << 64) | (0x5500 + i))) ok = 0; + printf("redirect calls=%d regs=%d fpsr=%u\n", calls, ok, saved_fpsr & 0x8); + } + mode = 0; + + sigemptyset(&mask); + sigaddset(&mask, SIGUSR2); + pthread_sigmask(SIG_BLOCK, &mask, NULL); + calls = 0; + slowpath(); + int while_blocked = calls; + pthread_sigmask(SIG_UNBLOCK, &mask, NULL); + printf("blocked during=%d after=%d\n", while_blocked, calls); + + calls = 0; + slowpath_other(SIGUSR1); + raise(SIGUSR2); + printf("other calls=%d main_path=%s\n", calls, on_alt ? "kernel" : "inline"); + + calls = 0; + pthread_t t[4]; + for (int i = 0; i < 4; i++) pthread_create(&t[i], NULL, stress, NULL); + for (int i = 0; i < 4; i++) pthread_join(t[i], NULL); + printf("threads calls=%d\n", calls); + return 0; +} +""" + + +def has_gcs_hwcap(): + try: + getauxval = ctypes.CDLL(None).getauxval + except (AttributeError, OSError): + return False + getauxval.restype = ctypes.c_ulong + getauxval.argtypes = [ctypes.c_ulong] + return bool(getauxval(16) & (1 << 32)) + + +def runner(): + if platform.machine() in ("aarch64", "arm64") and shutil.which("gcc") and not has_gcs_hwcap(): + return "gcc", [] + if shutil.which("aarch64-linux-gnu-gcc") and shutil.which("qemu-aarch64") and Path("/usr/aarch64-linux-gnu").is_dir(): + return "aarch64-linux-gnu-gcc", ["qemu-aarch64", "-cpu", "neoverse-n1", "-L", "/usr/aarch64-linux-gnu"] + return None, None + + +class Usr2PreloadTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.cc, cls.prefix = runner() + if cls.cc is None: + raise unittest.SkipTest("no aarch64 compiler and runner") + cls.tmp = tempfile.TemporaryDirectory() + tmp = Path(cls.tmp.name) + (tmp / "ntdll.c").write_text(NTDLL) + (tmp / "prog.c").write_text(PROGRAM) + sources = sorted(str(p) for p in PRELOAD.glob("*.c")) + subprocess.run([cls.cc, "-shared", "-fPIC", "-O2", "-Wall", "-pthread", "-o", str(tmp / "libblsession.so"), + *sources, "-ldl"], check=True) + subprocess.run([cls.cc, "-shared", "-fPIC", "-O2", "-o", str(tmp / "ntdll.so"), str(tmp / "ntdll.c")], check=True) + subprocess.run([cls.cc, "-O1", "-U_FORTIFY_SOURCE", "-pthread", "-o", str(tmp / "prog"), str(tmp / "prog.c"), str(tmp / "ntdll.so"), + "-Wl,-rpath," + str(tmp)], check=True) + cls.program = tmp / "prog" + cls.preload = tmp / "libblsession.so" + + @classmethod + def tearDownClass(cls): + cls.tmp.cleanup() + + def run_program(self, preload): + env = dict(os.environ) + env.pop("LD_PRELOAD", None) + cmd = list(self.prefix) + [str(self.program)] + if preload: + if self.prefix: + cmd = list(self.prefix) + ["-E", "LD_PRELOAD=" + str(self.preload), str(self.program)] + else: + env["LD_PRELOAD"] = str(self.preload) + out = subprocess.run(cmd, env=env, capture_output=True, text=True, timeout=120) + self.assertEqual(out.returncode, 0, out.stderr) + return out.stdout.splitlines() + + def test_a_ntdll_raise_runs_the_handler_without_a_kernel_signal(self): + lines = self.run_program(True) + self.assertIn("path inline", lines) + self.assertIn("returned calls=1 kept=1 usr2_blocked=1 usr1_blocked=1 code=1 stack=1 after_usr2=0 after_usr1=0", lines) + + def test_b_context_the_handler_writes_is_the_one_that_resumes(self): + self.assertIn("redirect calls=1 regs=1 fpsr=8", self.run_program(True)) + + def test_c_behaves_like_the_kernel_signal(self): + stock = [line for line in self.run_program(False) if not line.startswith("path ")] + inline = [line for line in self.run_program(True) if not line.startswith("path ")] + self.assertIn("returned calls=1 kept=1 usr2_blocked=1 usr1_blocked=1 code=1 stack=1 after_usr2=0 after_usr1=0", stock) + self.assertEqual(stock, inline) + + def test_d_blocked_other_signals_and_other_callers_use_the_kernel(self): + lines = self.run_program(True) + self.assertIn("blocked during=0 after=1", lines) + self.assertIn("other calls=1 main_path=kernel", lines) + self.assertIn("threads calls=8000", lines) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_vrclient_loader.py b/tools/tests/test_vrclient_loader.py index f468269925..fa1a778bf4 100644 --- a/tools/tests/test_vrclient_loader.py +++ b/tools/tests/test_vrclient_loader.py @@ -32,6 +32,7 @@ int probe(void) { #include #include int bl_fsync_syscall(long n, const long *a, long *r) { (void)n; (void)a; (void)r; return 0; } +int bl_writewatch_syscall(long n, const long *a, long (*real)(long, ...), long *r) { (void)n; (void)a; (void)real; (void)r; return 0; } #include """ + '"' + robust.as_posix() + '"' + r""" int main(int argc, char **argv) { assert(argc == 3); diff --git a/tools/tests/test_writewatch_preload.py b/tools/tests/test_writewatch_preload.py new file mode 100644 index 0000000000..38f2967557 --- /dev/null +++ b/tools/tests/test_writewatch_preload.py @@ -0,0 +1,119 @@ +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + +PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload" + +PROGRAM = r""" +#include "WRITEWATCH" +#include +#include +#include +#include + +#define PAGES 96 + +static int uffd, pagemap; +static uint64_t page; + +static char *region(void) { + char *m = mmap(NULL, PAGES * page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + madvise(m, PAGES * page, MADV_NOHUGEPAGE); + struct uffdio_register reg = { .range = { (uintptr_t)m, PAGES * page }, .mode = UFFDIO_REGISTER_MODE_WP }; + if (m == MAP_FAILED || ioctl(uffd, UFFDIO_REGISTER, ®)) exit(3); + protect(uffd, (uintptr_t)m, (uintptr_t)m + PAGES * page); + return m; +} + +static long scan(char *m, int emulated, uint64_t flags, uint64_t vec_len, uint64_t max_pages, uint64_t from, uint64_t to, + struct page_region *vec, uint64_t *walk_end) { + struct pm_scan_arg a = { .size = sizeof a, .flags = flags, .start = (uintptr_t)m + from * page, .end = (uintptr_t)m + to * page, + .vec = vec_len ? (uintptr_t)vec : 0, .vec_len = vec_len, .max_pages = max_pages, + .category_mask = PAGE_IS_WRITTEN, .return_mask = PAGE_IS_WRITTEN }; + long n = emulated ? emulate_scan(pagemap, uffd, &a) : ioctl(pagemap, PAGEMAP_SCAN, &a); + *walk_end = (a.walk_end - (uintptr_t)m) / page; + return n; +} + +int main(int argc, char **argv) { + page = (uint64_t)getpagesize(); + uffd = syscall(SYS_userfaultfd, O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY); + struct uffdio_api api = { .api = UFFD_API, .features = UFFD_FEATURE_WP_ASYNC | UFFD_FEATURE_WP_UNPOPULATED }; + pagemap = open("/proc/self/pagemap", O_RDONLY | O_CLOEXEC); + if (uffd < 0 || ioctl(uffd, UFFDIO_API, &api) || pagemap < 0) { puts("unsupported"); return 0; } + char *kernel = region(), *ours = region(); + struct page_region probe[1]; + uint64_t end; + if (scan(kernel, 0, 0, 1, 0, 0, PAGES, probe, &end) < 0) { puts("unsupported"); return 0; } + srand(atoi(argv[1])); + int rounds = atoi(argv[2]), differing = 0; + for (int r = 0; r < rounds; r++) { + int writes = rand() % 24; + for (int w = 0; w < writes; w++) { + int p = rand() % PAGES; + if (rand() % 4 == 0) { + volatile char x = kernel[p * page] + ours[p * page]; + (void)x; + continue; + } + kernel[p * page + rand() % page] = (char)r; + ours[p * page + rand() % page] = (char)r; + } + uint64_t flags = rand() % 2 ? PM_SCAN_WP_MATCHING : 0; + uint64_t vec_len = rand() % 3 == 0 ? 0 : 1 + rand() % 5; + uint64_t max_pages = rand() % 3 == 0 ? 1 + rand() % 8 : 0; + if (!vec_len) flags = PM_SCAN_WP_MATCHING, max_pages = 0; + uint64_t from = rand() % PAGES, to = from + rand() % (PAGES - from + 1); + struct page_region kv[8], ov[8]; + uint64_t kend, oend; + long kn = scan(kernel, 0, flags, vec_len, max_pages, from, to, kv, &kend); + long on = scan(ours, 1, flags, vec_len, max_pages, from, to, ov, &oend); + int same = kn == on && (kn < 0 || kend == oend); + for (long i = 0; same && i < kn; i++) + same = kv[i].start - (uintptr_t)kernel == ov[i].start - (uintptr_t)ours + && kv[i].end - (uintptr_t)kernel == ov[i].end - (uintptr_t)ours && kv[i].categories == ov[i].categories; + struct page_region kall[PAGES], oall[PAGES]; + long ka = scan(kernel, 0, 0, PAGES, 0, 0, PAGES, kall, &kend), oa = scan(ours, 1, 0, PAGES, 0, 0, PAGES, oall, &oend); + same = same && ka == oa; + for (long i = 0; same && i < ka; i++) + same = kall[i].start - (uintptr_t)kernel == oall[i].start - (uintptr_t)ours && kall[i].end - (uintptr_t)kernel == oall[i].end - (uintptr_t)ours; + if (!same) { + differing++; + printf("round %d flags %llu vec %llu max %llu range %llu-%llu: kernel %ld end %llu, ours %ld end %llu\n", r, + (unsigned long long)flags, (unsigned long long)vec_len, (unsigned long long)max_pages, (unsigned long long)from, + (unsigned long long)to, kn, (unsigned long long)kend, on, (unsigned long long)oend); + } + } + printf("rounds %d differing %d\n", rounds, differing); + return 0; +} +""" + + +class WriteWatchPreloadTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + if shutil.which("gcc") is None: + raise unittest.SkipTest("gcc is not available") + cls.work = Path(tempfile.mkdtemp()) + source = cls.work / "writewatch.c" + source.write_text(PROGRAM.replace("WRITEWATCH", str(PRELOAD / "writewatch.c"))) + cls.program = cls.work / "writewatch" + subprocess.run(["gcc", "-O1", "-Wall", "-o", str(cls.program), str(source)], check=True) + + @classmethod + def tearDownClass(cls): + shutil.rmtree(cls.work, ignore_errors=True) + + def test_a_scan_android_refuses_answers_like_the_kernel_one(self): + for seed in range(4): + out = subprocess.run([str(self.program), str(seed), "400"], capture_output=True, text=True, timeout=60).stdout + if out.strip() == "unsupported": + self.skipTest("this kernel has no asynchronous userfaultfd write protection") + self.assertTrue(out.rstrip().endswith("differing 0"), out) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_zram_preload.py b/tools/tests/test_zram_preload.py index a9a437e3ec..88d5c73020 100644 --- a/tools/tests/test_zram_preload.py +++ b/tools/tests/test_zram_preload.py @@ -129,6 +129,8 @@ class ZramPreloadTest(unittest.TestCase): def setUp(self): self.ctl.write_text("0") + for ack in self.dir.glob("ctl.ack.*"): + ack.unlink() def run_program(self, program=None, mb=48, cycles=1, *extra): environment = dict(os.environ, LD_PRELOAD=str(self.lib)) @@ -140,9 +142,10 @@ class ZramPreloadTest(unittest.TestCase): out.setdefault(key, []).append(int(value)) return out - def test_only_the_client_takes_the_signal(self): + def test_every_process_takes_the_signal(self): self.assertEqual([1], self.run_program()["handler"]) - self.assertEqual([0], self.run_program(self.game)["handler"]) + self.assertEqual([1], self.run_program(self.game)["handler"]) + self.assertEqual(2, len(list(self.dir.glob("ctl.ack.*")))) def test_nothing_is_installed_without_the_control_file(self): self.ctl.unlink() @@ -157,6 +160,7 @@ class ZramPreloadTest(unittest.TestCase): self.assertGreater(out["out"][0], 32 * 1024) self.assertLess(out["back"][0], out["out"][0] // 4) self.assertEqual([1], out["intact"]) + self.assertEqual(["1"], [ack.read_text() for ack in self.dir.glob("ctl.ack.*")]) @unittest.skipUnless(swap_total_kb() > 256 * 1024, "needs swap") def test_reads_back_what_the_kernel_swapped_elsewhere(self):