ESync, FSync, NTSync + OpenNow + FEX for Desktop Apps (#197)

* Make the Compatible Proton ARM64 the default and label compatible builds

The CompatToolMapping "0" default always points at DroidDeck's Proton
ARM64 tool, and per-game picks of adopted GE/CachyOS builds are kept,
including when the shortcuts writer remaps.

The tool is named after the Proton build it runs, Proton Experimental
ARM64 (Compatible), or Proton 11.0 ARM64 (Compatible) once that newer build
is installed. Adopted builds carry the same Compatible mark, read from a
string resource the app stages into the runtime, and the Proton page
explains which builds have the prefix fixes.

The registrar is renamed steam-compatibility and the tool
droiddeck-proton-arm64. Existing installs migrate on the next session: the
old tool directory is removed, every mapping that named it moves to the new
tool, and the retired bannerlator-steam-compat script is removed from the
runtime. CI and local packaging include the renamed script.

* Drop the duplicate R import left by merging main

* Add userspace ntsync for Proton on Android

Android kernels have no /dev/ntsync and its app policy refuses futex_waitv,
so every Proton 11 build here fell back to wineserver for every wait.
libblsession now serves /dev/ntsync itself: wineserver opens a memfd region,
each sync object is a timerfd that carries its slot, and the kernel ntsync
ioctls are answered in shared memory with futexes, following the kernel
driver's wake order. Valve's Proton Experimental ARM64, GE-Proton and
proton-cachyos use it unchanged.

Locks record their owner so a killed process cannot wedge the others,
signals are held off inside each critical section, dead processes and
exiting threads are swept, and object lifetimes follow close, dup2, dup3,
close_range and received descriptors.

Fast sync is on by default under Performance > Session fixes, and
PROTON_NO_NTSYNC=1 turns it off per game.

* Add droiddeck-esync as the default sync for Proton on Android

Without a kernel ntsync driver, Proton 11 builds here fell back to
wineserver for every wait. droiddeck-esync brings eventfd and shared-memory
sync to the exact Proton build a game runs on: a pack holds that build's
ntdll.so and wineserver with the patch series in tools/droiddeck-esync
applied, and the guest runs Proton from a shadow tree that links the stock
tool and swaps in those two files. A wineserver from a pack still prefers
/dev/ntsync when a kernel driver or droiddeck-ntsync is there.

Packs are built in Valve's SDK image from each release's own wine source
(Proton Experimental ARM64 tags, GE-Proton and proton-cachyos releases); the
control build must reproduce the release binaries byte for byte, and a
signed index lists the packs. The APK bundles the packs pinned in
release.env, the app fetches newer ones, and Steam's compatibility tool
picks the pack for each Proton build, so new Proton releases get packs
without an app update.

The ntdll side reads, writes and polls its eventfds with raw system calls,
so the guest's LD_PRELOAD wrappers stay out of the sync path. The server
abandons a mutex once a thread killed by TerminateThread has really exited
and when its process dies, and a mutex's owner and recursion count change
in one atomic step, so a killed owner cannot touch the next owner's count.

droiddeck-esync is on by default and PROTON_NO_ESYNC=1 turns it off per
game; droiddeck-ntsync, the userspace ntsync, is now an opt-in toggle.

* Watch Valve's Proton releases and build droiddeck-esync packs for them

A scheduled workflow reads the Proton ARM64 builds Steam ships (anonymous
steamcmd app info) and the upstream source tags, compares them with the
previous watch state and starts the pack build for any build that has no
pack yet. The pack build applies the patch series with --fuzz=0 and runs a
smoke test of each new pack against the esstress suite before it is
published.

* Add droiddeck-fsync, keep Steam and the app on one Proton, fix DirectAudio

droiddeck-fsync: libblsession answers futex_waitv(2), which the app
sandbox refuses, in userspace, so Proton's own fsync runs on the stock
Proton files with no pack. Waiters register the words they wait on in a
table beside the fsync shared memory and sleep on a futex of their own;
FUTEX_WAKE on the fsync memory wakes the registered waiters. Slots carry
one owner word that the sweeper and the owner claim with a CAS, and the
mapping table is rebuilt under a lock held across the real munmap, so a
reused address or a recycled slot cannot lose a waiter. It stands in for
a Proton build without a pack (droiddeck-ntsync where fsync is off), takes
over for games with esync off, and the "droiddeck-fsync first" toggle
(BL_FSYNC_FIRST, also per game) puts it ahead of the packs. The games
Proton keeps off fsync and esync never get it. A launch into a prefix
whose wineserver is still running keeps that server's sync choice.

One Proton for Steam and the app: the Components page's Proton is the
default Steam uses, applied live through the client while Steam runs
(droiddeck-steam-compat) and at the next start otherwise; a choice made in
Steam's menu comes back to the app. Requests are ordered by a sequence that
never goes backwards, and the page no longer jumps back to the default
after a swap or restore.

DirectAudio: the wrapper wrote the driver key with its backslashes
stripped, so no game ever used DirectAudio. Wine 11 also loads a builtin
only from the prefix, so the driver is now linked into system32 and
syswow64 before "directaudio,pulse" is selected; mmdevapi falls back to
winepulse whenever DirectAudio cannot start.

* Pick esync, ntsync or fsync from the Steam settings' Games group

A three-way tab row above the FEX preset sets the sync Proton games use. It
writes the existing switches together (droiddeck-ntsync, droiddeck-fsync
first, droiddeck-esync), so the Performance toggles and the tabs always agree,
starts on esync and keeps the choice until it is changed again.

* Make droiddeck-fsync the default sync for Proton games

A fresh install, or one that never picked a sync, starts on fsync; a choice made
in the Steam settings' Games group still sticks. Games Proton keeps off fsync
still fall back to droiddeck-esync.

* Add wineserver to the Wine sync tabs and order them ntsync, fsync, esync, wineserver

wineserver turns every in-process sync off so games wait through wineserver;
picking any other tab turns sync back on. The tabs shrink to fit a narrow pane.

* Shorten the Wine sync description

* Answer openat2 and execveat for FEX in the session preload

FEX opens every file of its x86 rootfs with openat2(RESOLVE_IN_ROOT) and
only falls back to the host path on EXDEV. Under proot on Android openat2
answers ENOSYS, so each lookup of an x86 library silently went to the host
and missed. The exported syscall() now turns openat2 into openat once the
real call reports ENOSYS: RESOLVE_IN_ROOT paths are taken relative to the
root fd (FEX has already resolved the links inside the rootfs), and an
absolute path under RESOLVE_BENEATH fails with EXDEV as the kernel would.

execveat with an absolute path, or relative to AT_FDCWD, and without
AT_EMPTY_PATH or AT_SYMLINK_NOFOLLOW, is plain execve; it is sent as such
because proot refuses execveat with a directory fd, which FEX uses when it
re-executes itself for a child x86 program.

* Run x86 Linux games and programs through FEX

Steam: Linux-only titles that have no ARM64 build (from the client's
appinfo cache: type game, demo, application or beta) are mapped to a new
compatibility tool, droiddeck-fex ("Linux x86 (FEX)", linux to linux,
no required runtime). Valve's own "fex" tool needs pressure-vessel, which
cannot run under proot, so a mapping to it or to a Steam Linux Runtime is
replaced; any other pick the user made stays. Titles that also ship for
Windows stay on Proton. When such a title is installed and FEX or the
sniper runtime is missing, the client is asked to install them.

droiddeck-fex runs the program under the FEX that Steam installs (app
3127680), with Steam Linux Runtime 3.0 (sniper, app 1628350) as the x86
rootfs:
- the sniper platform is linked in place from its usr-mtree (relative
  links only, files/usr -> .), once per runtime version;
- the x86_64 and i386 builds of libblsession and libfakeinput go into the
  runtime's lib/<triplet>/droiddeck and its etc/ld.so.preload, mirroring
  the session's own list, so x86 programs get the pads and the session
  fixes (FEX passes their system calls straight to the kernel, so the
  ARM64 preloads cannot reach them);
- Config.json sets RootFS and the GL and Vulkan thunks, so x86 games draw
  with the device's Turnip and Mesa;
- the FEX preset and the game's own environment from the Steam settings
  apply, and ARM64 entries are dropped from LD_PRELOAD/LD_LIBRARY_PATH.
It also links ~/.steam/sdk64 and sdk32 to the client's x86 steamclient
when the client has one and nothing is there yet.

Desktop: x86_64 and i386 AppImages can be imported now; they unpack
through FEX (or unsquashfs) and record their architecture. Scripts,
AppImages and programs started in a run session use FEX automatically
when they are x86, and each added app has a "Use FEX" Auto/On/Off choice
in its edit dialog. The launchers' "still running" checks also look at
FEX processes, whose exe is FEX rather than the program. A GitHub release
without an ARM64 AppImage falls back to its x86_64 one. Decky's x86
loader starts through droiddeck-fex instead of the fex-mesa rootfs path,
which no runtime ships.

The x86 preloads are built against glibc 2.31 (Debian 11) so they load
in sniper: tools/linuxfs/build-x86-preloads.sh, run in CI and by
build_local.sh. fakeinput's stat hooks fall back to __xstat on a glibc
without a stat export, and mmap64 takes off64_t for the i386 build.

* Keep a FEX unixlib from outliving its DLL

A FEX package or original bundle without the aarch64-unix helpers left
the previous version's libarm64ecfex.so / libwow64fex.so in the Proton,
so the new DLLs loaded a unixlib built for another FEX. A swap now removes
the helpers the package does not carry; FEX then runs DLL-only, which it
already falls back to when Wine cannot load the unixlib.

* Fix the Wine sync choices an audit found

- wineserver tab: it passed Proton's environment through, so a build with
  esync built in (GE, cachyos) still ran esync and a kernel ntsync would
  still be used. It now sets PROTON_NO_ESYNC, PROTON_NO_FSYNC and
  PROTON_NO_NTSYNC (unless the game's own environment sets them).
- ntsync tab: a Proton whose wineserver has no /dev/ntsync client got
  wineserver-only sync although fsync would work. The hash cache records
  whether the wineserver has one; without it the launch goes to
  droiddeck-fsync, and no stand-in or pack turns droiddeck-ntsync on.
- A build with esync built in returned before the per-game fallbacks, so
  a game that turns esync off ran with no in-process sync. It now gets
  droiddeck-fsync, or droiddeck-ntsync where fsync is off too.
- When a pack's proton cannot start and the stock one is used, or the
  selection fails, the prefix's record now says stock, so a second
  launch into the same running prefix no longer picks the pack's ntdll.
- droiddeck-fsync: its mutex is held across fork and re-made in the
  child, a closed or replaced shm fd is forgotten (close, dup2, dup3,
  close_range, closefrom), and a waiter woken while it was leaving on a
  timeout or signal reports the wake instead of losing it.
- BL_SYNC_MIN_NOFILE applies per game to every verb, debug logs carry
  prefixes.json, the device report names the chosen sync instead of the
  three raw switches, and PATCHES.md and the proot notes describe the
  selector, the fsync default and droiddeck-fsync's futex_waitv.

* Name the runtime's scripts and files droiddeck, migrating old installs

The guest scripts are droiddeck-* now (droiddeck-session and the other 19),
as are the files the app and scripts generate (etc/droiddeck, the network
state files, the components dir, the Steam install stamp, the redist marker,
the extra-Proton wrapper and backups) and the compositor's own names
(libdroiddeckwayland, droiddeck_* sources, DROIDDECK_* switches, the
wl_output and seat names).

Installed runtimes carry on: LegacyNames moves etc/bannerlator and
share/bannerlator over and leaves relative links at the old paths before
every proot command, turns any old script into a link to its new name,
moves the generated files and points menu entries at the new scripts.
The session scripts and steam-compatibility move their markers on first
use, the components dir's desired.tsv is rewritten with it, and the
runtime counts as installed under either session script.

Kept: the banner_ahb_v1/banner_desktop_v1 wire names and BANNER_AUDIO_DIRECT
(read by prebuilt Turnip and Wine builds), Banners-Turnip and other
third-party names, BL_* switches, libblsession, and credits to Bannerlator.

* Unpack x86 AppImages without FEX, then ask Steam for FEX

Importing an x86 AppImage failed when FEX was not installed yet ("needs FEX
to unpack and no unsquashfs is installed"). AppImages now unpack with
uruntime (VHSgunzo, MIT, v0.8.1 aarch64, pinned by sha256 and shipped
unmodified with its licence), which reads SquashFS and DwarFS images of any
architecture natively. FEX's own --appimage-extract and unsquashfs stay as
fallbacks, and an ARM64 image whose own runtime cannot unpack it goes the
same way.

An x86 import with FEX missing records that FEX is wanted, so the next
Steam session requests FEX and the Steam Linux Runtime, and the program's
page says FEX is not set up yet and how to get it.

* Run Vulkan Qt Quick AppImages on Wayland

OpenNOW (Qt 6.8, Qt Quick on Vulkan) closed within two seconds in a run
mode. The session sends toolkits to gamescope's Xwayland, and Qt's xcb
backend only presents with Vulkan when Mesa's X11 WSI does, which needs
DRI3; Xwayland on KGSL has none, so Qt found no queue that can present and
aborted ("Failed to create RHI").

An AppImage that bundles Qt Quick, the Vulkan loader and Qt's Wayland
plugin now runs on gamescope's Wayland socket (the desktop's, outside
gamescope), where Turnip presents as it does for games, with Qt's xcb
backend as the fallback. SDL_VIDEODRIVER and XDG_SESSION_TYPE follow, so
helpers that pick their window system from them (OpenNOW's streamer) agree
with Qt. Everything else stays on X11; a qt file in the app's directory
(wayland or xcb) overrides the choice.

* Keep gamescope's WSI layer away from Qt apps on its Wayland socket

OpenNOW still closed at once: its FFmpeg (the Raspberry Pi fork, libavutil
61) creates its Vulkan queues internally synchronized whenever the driver
offers VK_KHR_internally_synchronized_queues, which DD-Turnip does. The
gamescope WSI layer registers every queue of a new device through
vkGetDeviceQueue, which only returns queues created without flags, so it
got VK_NULL_HANDLE and vkroots aborted on assert(obj) before Qt opened a
window.

Programs that draw on gamescope's Wayland socket do not need the layer,
which only carries X11 windows past Xwayland, so it is turned off for
them. OpenNOW bundles no Vulkan loader (it reaches Vulkan through Qt and
dlopen), so a binary that uses QVulkanInstance counts as a Vulkan app too,
and a Qt Quick app left on X11 says why in the session log.

* Keep the end of the session log, and say when FEX is missing

The session sends its output through head -c into session.log. head
writes through stdio, so it held up to 4 KB that proot's --kill-on-exit
threw away when the guest ended: every log stopped mid-line at a 4096-byte
boundary, losing exactly the lines that say why a program quit (an x86
AppImage's "x86 Linux programs need FEX" among them). dd writes each read
as it comes and keeps the same cap.

A run mode always ends with status 0 (gamescope does not pass its child's
on), so a program that could not start just closed. When the log says FEX
is missing, the ended screen now says so and how to get it.

The app reads FEX's readiness from status.json, which only a launch or an
import wrote, so it still said "not set up" after Steam installed FEX.
droiddeck-fex status rewrites it, and a Steam session ends with it while
FEX is wanted. FEX is also looked for at the tool's root and under files/,
and a tool folder without it lists what it holds.

* Let FEX and its runtime install runnable on an SD card library

A Steam library on shared storage loses the executable bits, so native
tools are staged in private directories bound over it; only Proton and
SteamLinuxRuntime folders were. FEX (3127680) installed there could never
run, droiddeck-fex saw no FEX and kept asking Steam for it. FEX and the
sniper runtime (1628350) now get private directories from their first
download, whatever their install folder is called.

* Keep fsync off in the pack smoke test

A runner whose kernel allows futex_waitv started stock Proton with fsync,
so the server-side baseline never said what the test waits for and every
pack was waved through as untestable; the esync run would have measured
fsync too.

* Judge a pack against stock's own esstress failures

Stock Proton fails esstress's dup wait all under server-side sync as well
(a Wine bug, seen on the phone too), and any stock failure made the test
call the runner unusable. A pack now fails only when it crashes, hangs or
fails a check stock passes.

* Ask Steam for FEX and its runtime one at a time

Both steam://install requests were started together, and the running client
took only the first: FEX installed, the sniper runtime FEX needs never did.
Each request now waits for the client to take it before the next.

* Bundle the first published droiddeck-esync packs in the apk

* Log how an x86 program under FEX ends

FEX keeps its own errors quiet unless asked, so a program it could not run
left nothing in the session log. Its log now goes to stderr, and the AppImage
launcher records the program's exit status or the signal that ended it.

* Show the log a failed AppImage program wrote

Programs like Eden stop themselves on a failed check and say why only in
their own log under the home folder. When the program ends badly, the end of
any log it wrote during the run is copied into the session log.

* Report where an x86 program under FEX hit an illegal instruction

A tiny x86_64 preload, built without libc, catches SIGILL and writes the
address, the instruction bytes and the mapping they belong to before the
program dies as it would have. droiddeck-fex preloads it into x86_64 programs.

* Load the fault reporter from the x86 runtime

Programs under FEX look libraries up in the x86 runtime, so the reporter is
copied there with the other preloads and named by its path inside it.

* Hand FEX its x86 runtime and thunks through the environment

Valve's FEX runs portable and reads its config beside itself, so the
Config.json droiddeck-fex writes was not seen: programs ran without the
runtime. The runtime, thunk libraries and thunk list now also go in FEX's
own environment variables, and each launch says what it was given.

* Use the sync pack built for the installed Proton release

Some Proton releases ship byte-identical ntdll.so and wineserver (Valve
11.0-2b/2c, CachyOS 0702/0703), so a pack built for a newer release
matched an older install exactly and the older install never fetched its
own pack. A pack from a newer release no longer counts as an exact match;
among matches the one built for the installed version wins, then rev.

The app ranks the pack a tool already uses the same way and only fetches
a pack that ranks higher, reads the release epoch from tools.tsv and
refetches when tools.tsv changes. A prefix whose server is still running
re-checks its recorded pack on waitforexitandrun and starts fresh when a
better one now applies.

* Keep published sync packs and revocations consistent

The publish step never replaces a pack that has an entry beside it; a
pack left without its entry by an interrupted run is replaced so the
build stops repeating. Discovery counts revocations the signed index does
not show yet, including superseded packs only the flavor releases list,
so the index is signed again. The release watch always builds every
flavor.

* Fetch the droiddeck-esync packs from DroidDeck-Components

The packs, the signed index and the apk bundle now live in the releases
of Droid-Deck/DroidDeck-Components, together with the pipeline that
builds them, so this repository keeps only the app and the guest code
that consumes them. The app's index and asset URLs point there,
release.env names the repository its bundle comes from, and the apk
builds drop bundled packs that the published index revokes.

* Stop the apk build when the published sync index cannot be read

* Ask Steam for one FEX dependency at a time

The client shows a confirmation dialog for each steam://install, and a
second request replaces the first dialog, so FEX was never installed
when the runtime was requested right after it. The next dependency is
now requested once the previous one has an app manifest.

* Use generic names in the AppImage test fixtures

* Give x86-64 apps under FEX the Vulkan thunk

Apps that bring their own glibc and Vulkan loader skipped FEX's thunk
overlay and loaded their bundled desktop Mesa drivers, which crash on the
phone's GPU during Vulkan setup. droiddeck-fex now adds an x86-64 audit
module when a program's bundled glibc and libstdc++ meet the thunk's
version needs. The module sends libvulkan.so.1 lookups to a nodelete stub
that needs FEX's thunk path. That keeps the thunk mapped when an app
unloads Vulkan and loads it again, since FEX keeps its first trampoline
links and the old addresses get reused.

The fault reporter now restores the default action before re-raising,
because FEX ignores SA_RESETHAND and the handler looped.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-10-04 12:43:57 -04:00
1 parent 84bc7d9948
commit 27782068a3
165 files changed
+11709 -9667

No files matched your search

@@ -6,6 +6,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.droiddeck.launcher.session.ComponentsManager
import com.droiddeck.launcher.session.ProtonDefault
/**
* The Components page's state and work: the Protons and their DXVK/VKD3D sets, the Nightlies
@@ -20,6 +21,7 @@ internal class ComponentsMenu(private val activity: android.app.Activity, privat
var compChecking by mutableStateOf(false)
var compBusy by mutableStateOf<String?>(null)
var compDownloads by mutableStateOf<Map<String, Int>>(emptyMap())
private var shownDefault: String? = null
/** Reads the Protons (and on first open saves their originals) off the UI thread; the Nightlies list comes from its cache. */
fun refreshComponents(snapshotFirst: Boolean = false) {
@@ -28,14 +30,35 @@ internal class ComponentsMenu(private val activity: android.app.Activity, privat
runCatching { ComponentsManager.applyQueued(activity) }
val snap = runCatching { ComponentsManager.snapshot(activity) }.onFailure { Log.w(TAG, "components", it) }.getOrNull()
val cat = runCatching { ComponentsManager.catalog(activity, false) }.getOrNull()
val chosen = snap?.let { s -> runCatching { ProtonDefault.selectedId(activity, s.protons.map { it.proton }) }.getOrNull() }
ui.post {
compSnapshot = snap ?: ComponentsManager.Snapshot(emptyList(), emptyList())
if (cat != null && cat.fetchedAt > 0) { compCatalog = cat.items; compCatalogAt = cat.fetchedAt }
if (compProton == null || snap?.protons?.none { it.proton.id == compProton } == true) compProton = snap?.protons?.firstOrNull()?.proton?.id
if (chosen != null && chosen != shownDefault) {
shownDefault = chosen
compProton = chosen
} else if (compProton == null || snap?.protons?.none { it.proton.id == compProton } == true) {
compProton = chosen ?: snap?.protons?.firstOrNull()?.proton?.id
}
}
}, "components").start()
}
fun chooseProton(id: String) {
val proton = compSnapshot?.protons?.firstOrNull { it.proton.id == id }?.proton ?: return
compProton = id
Thread({
val message = runCatching {
when (ProtonDefault.request(activity, proton)) {
ProtonDefault.Outcome.LIVE -> activity.getString(R.string.comp_default_live, proton.name)
ProtonDefault.Outcome.NEXT_START -> activity.getString(R.string.comp_default_next, proton.name)
ProtonDefault.Outcome.NOT_RUNNABLE -> activity.getString(R.string.comp_default_not_runnable, proton.name)
}
}.getOrElse { e -> activity.getString(R.string.comp_default_failed, e.message ?: e.javaClass.simpleName) }
ui.post { android.widget.Toast.makeText(activity, message, android.widget.Toast.LENGTH_LONG).show() }
}, "components-default").start()
}
fun componentAction(label: String, work: () -> String) {
if (compBusy != null) return
compBusy = label
@@ -137,6 +137,9 @@ class MainActivity : ComponentActivity() {
private var tuSysmem by mutableStateOf(false)
private var zinkLazy by mutableStateOf(false)
private var noXalia by mutableStateOf(true)
private var fastSync by mutableStateOf(false)
private var syncFallback by mutableStateOf(true)
private var fsyncFirst by mutableStateOf(true)
private var gamescopeRealtime by mutableStateOf(false)
private var gpuClockPin by mutableStateOf(false)
private var prootNoSeccomp by mutableStateOf(false)
@@ -863,9 +866,10 @@ class MainActivity : ComponentActivity() {
val applied = runCatching { ComponentsManager.applyQueued(this) }.getOrDefault(emptyList())
if (applied.isNotEmpty()) ui.post {
android.widget.Toast.makeText(this, "Applied: " + applied.joinToString(", "), android.widget.Toast.LENGTH_LONG).show()
if (showComponents) components.refreshComponents()
}
ui.post { if (showComponents) components.refreshComponents() }
}, "components-queue").start()
else if (showComponents) components.refreshComponents()
oscMode = SessionPrefs.oscMode(this)
refreshController()
refreshHomeAppState()
@@ -1018,7 +1022,7 @@ class MainActivity : ComponentActivity() {
busy = if (busy) stage else components.compBusy,
downloads = components.compDownloads,
requestInitialFocus = focusComponentsContent,
onProton = { components.compProton = it },
onProton = { components.chooseProton(it) },
onComp = { components.compComp = it },
onSwap = { file -> components.compProton?.let { pid -> components.componentAction("Swapping") { ComponentsManager.swap(this, pid, file) } } },
onRestore = { version -> components.compProton?.let { pid -> components.componentAction("Restoring") { ComponentsManager.restore(this, pid, components.compComp, version) } } },
@@ -1130,6 +1134,7 @@ class MainActivity : ComponentActivity() {
storageOptions = storageOptions,
storageDiagnostics = mode == SessionService.MODE_STEAM && storageDiagnostics,
fexPreset = if (mode == SessionService.MODE_STEAM) fexPreset else null,
syncBackend = if (mode == SessionService.MODE_STEAM) SessionPrefs.syncBackendOf(fastSync, fsyncFirst, syncFallback) else null,
steamChannel = if (mode == SessionService.MODE_STEAM) steamChannel else null,
steamDeckMode = mode == SessionService.MODE_STEAM && steamDeckMode,
mangoapp = mangoapp,
@@ -1203,6 +1208,12 @@ class MainActivity : ComponentActivity() {
storageDiagnostics = on
},
onFexPreset = { id -> SessionPrefs.setFexPreset(this, id); fexPreset = id },
onSyncBackend = { id ->
SessionPrefs.setSyncBackend(this, id)
fastSync = SessionPrefs.fastSync(this)
fsyncFirst = SessionPrefs.fsyncFirst(this)
syncFallback = SessionPrefs.syncFallback(this)
},
onSteamChannel = { id -> SessionPrefs.setSteamChannel(this, id); steamChannel = id },
onSteamDeckMode = { on ->
SessionPrefs.setSteamDeckMode(this, on)
@@ -1242,6 +1253,9 @@ class MainActivity : ComponentActivity() {
cores = CpuCores.all.map { c -> CoreRow(c, "cpu$c" + (CpuCores.maxGhz(c)?.let { String.format(java.util.Locale.US, " · %.1f GHz", it) } ?: "")) },
clientOverride = clientOverride, clientCores = clientCores, gameCores = gameCores,
tuSysmem = tuSysmem, zinkLazy = zinkLazy, glThread = glThread, noGlError = noGlError, noXalia = noXalia,
fastSync = fastSync,
syncFallback = syncFallback,
fsyncFirst = fsyncFirst,
gamescopeRealtime = gamescopeRealtime,
gpuClockPin = gpuClockPin,
prootNoSeccomp = prootNoSeccomp, prootFastPath = prootFastPath, guestHostname = guestHostname, phantomWarning = phantomWarning,
@@ -1251,6 +1265,9 @@ class MainActivity : ComponentActivity() {
onGlThread = { on -> SessionPrefs.setGlThread(this, on); glThread = on },
onNoGlError = { on -> SessionPrefs.setNoGlError(this, on); noGlError = on },
onNoXalia = { on -> SessionPrefs.setNoXalia(this, on); noXalia = on },
onFastSync = { on -> SessionPrefs.setFastSync(this, on); fastSync = on },
onSyncFallback = { on -> SessionPrefs.setSyncFallback(this, on); syncFallback = on },
onFsyncFirst = { on -> SessionPrefs.setFsyncFirst(this, on); fsyncFirst = on },
onGamescopeRealtime = { on -> SessionPrefs.setGamescopeRealtime(this, on); gamescopeRealtime = on },
onGpuClockPin = { on -> SessionPrefs.setGpuClockPin(this, on); gpuClockPin = on },
onProotNoSeccomp = { on -> SessionPrefs.setProotNoSeccomp(this, on); prootNoSeccomp = on },
@@ -1309,6 +1326,9 @@ class MainActivity : ComponentActivity() {
resolutionCap = SessionPrefs.resolutionCap(this, mode)
customResolution = SessionPrefs.customResolution(this, mode)
fexPreset = SessionPrefs.fexPreset(this)
fastSync = SessionPrefs.fastSync(this)
fsyncFirst = SessionPrefs.fsyncFirst(this)
syncFallback = SessionPrefs.syncFallback(this)
steamChannel = SessionPrefs.steamChannel(this)
steamDeckMode = SessionPrefs.steamDeckMode(this)
mangoapp = SessionPrefs.mangoapp(this)
@@ -1380,6 +1400,9 @@ class MainActivity : ComponentActivity() {
tuSysmem = SessionPrefs.tuSysmem(this)
zinkLazy = SessionPrefs.zinkLazy(this)
noXalia = SessionPrefs.noXalia(this)
fastSync = SessionPrefs.fastSync(this)
syncFallback = SessionPrefs.syncFallback(this)
fsyncFirst = SessionPrefs.fsyncFirst(this)
gamescopeRealtime = SessionPrefs.gamescopeRealtime(this)
gpuClockPin = SessionPrefs.gpuClockPin(this)
prootNoSeccomp = SessionPrefs.prootNoSeccomp(this)
@@ -945,7 +945,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
val on = wanted && probe.reason == null
SessionState.hdr = on
if (on) {
try { android.system.Os.setenv("BANNER_WAYLAND_HDR", "1", true) } catch (e: Exception) { Log.w(TAG, "BANNER_WAYLAND_HDR", e) }
try { android.system.Os.setenv("DROIDDECK_WAYLAND_HDR", "1", true) } catch (e: Exception) { Log.w(TAG, "DROIDDECK_WAYLAND_HDR", e) }
WaylandCompositor.nativeSetZeroCopy(true)
}
WaylandCompositor.nativeSetHdrRequest(
@@ -1156,8 +1156,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}, "session-end-hint").start()
}
private fun showEnded(status: Int, hint: String?) {
if (status == 0) {
private fun showEnded(status: Int, hint: EndHint?) {
if (status == 0 && hint?.evenOnSuccess != true) {
finish()
return
}
@@ -1168,7 +1168,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
else -> "Steam"
}
loading.showEnded(
hint ?: "$what stopped unexpectedly. Share the logs with a bug report, or try again.",
hint?.text ?: "$what stopped unexpectedly. Share the logs with a bug report, or try again.",
"Exit status $status · ${SessionState.logFile?.path ?: "no log"}",
)
focusEndedScreen()
@@ -1196,10 +1196,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
* FEX) on some devices (a Fold 5, twice). The switch that answers it is in Performance, and a
* user who never opens the log would not know.
*/
private fun sessionEndHint(log: File?): String? {
private class EndHint(val text: String, val evenOnSuccess: Boolean = false)
private fun sessionEndHint(log: File?): EndHint? {
if (log == null || !log.isFile) return null
return try {
var enosys = 0
var fexMissing = false
// The tail is where a dying session says why; 512 KB covers the storm without reading a 1 GB log.
val size = log.length()
java.io.RandomAccessFile(log, "r").use { f ->
@@ -1209,11 +1212,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
f.readFully(bytes)
String(bytes, Charsets.ISO_8859_1).lineSequence().forEach { line ->
if (line.contains("Function not implemented")) enosys++
if (line.contains(FEX_MISSING)) fexMissing = true
}
}
if (enosys >= 8) {
"The log shows $enosys \"Function not implemented\" errors: proot's seccomp acceleration is failing a helper on this device. " +
"Try Performance \u2192 \"Run proot without seccomp\" (or \"Skip Steam's xalia helper\") and start again."
if (fexMissing) {
val what = com.droiddeck.launcher.frontend.Library.nameForProgram(SessionState.program) ?: getString(R.string.session_end_program)
EndHint(getString(R.string.session_end_fex_missing, what), evenOnSuccess = true)
} else if (enosys >= 8) {
EndHint("The log shows $enosys \"Function not implemented\" errors: proot's seccomp acceleration is failing a helper on this device. " +
"Try Performance \u2192 \"Run proot without seccomp\" (or \"Skip Steam's xalia helper\") and start again.")
} else null
} catch (e: Exception) {
null
@@ -1998,6 +2005,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
/** How long the leaving flood may take before the session closes without it. */
private const val LEAVE_TIMEOUT_MS = 1_500L
private const val TAG = "SessionActivity"
private const val FEX_MISSING = "droiddeck-fex: x86 Linux programs need"
private const val UNBUFFERED_SOURCES = InputDevice.SOURCE_CLASS_JOYSTICK or InputDevice.SOURCE_CLASS_TRACKBALL or InputDevice.SOURCE_CLASS_POSITION
private const val CURSOR_PAD_HOLD_MS = 1200L
private const val DRAWER_HAT_THRESHOLD = 0.5f
@@ -12,6 +12,7 @@ import com.droiddeck.launcher.gpu.TurnipDriver
import com.droiddeck.launcher.runtime.DesktopCatalog
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.runtime.LinuxRuntimeInstaller
import com.droiddeck.launcher.session.EsyncPacks
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionState
@@ -154,6 +155,9 @@ object DeviceReport {
" (sharpness ${SessionPrefs.upscaleSharpness(context)}%)")
k("FEX preset", SessionPrefs.fexPreset(context).ifEmpty { "FEX defaults" })
k("Skip xalia", SessionPrefs.noXalia(context))
k("Wine sync", SessionPrefs.syncBackend(context))
EsyncPacks.status(LinuxRuntime.rootDir(context)).let { k("droiddeck-esync packs", "${it.installed} installed, ${it.wanted} wanted") }
k("Linux x86 (FEX)", if (com.droiddeck.launcher.runtime.LinuxFex.ready(context)) "ready" else "not set up")
k("gamescope realtime", SessionPrefs.gamescopeRealtime(context))
k("proot without seccomp", SessionPrefs.prootNoSeccomp(context))
k("proot fast path", SessionPrefs.prootFastPath(context))
@@ -14,7 +14,7 @@ object GameEnvironment {
private val namePattern = Regex("[A-Za-z_][A-Za-z0-9_]*")
private val unused = setOf(
"WINEESYNC", "WINENTSYNC", "WINE_FAST_YIELD", "WINE_DO_NOT_CREATE_DXGI_DEVICE_MANAGER",
"WINENTSYNC", "WINE_FAST_YIELD", "WINE_DO_NOT_CREATE_DXGI_DEVICE_MANAGER",
"WINE_NEW_MEDIASOURCE", "WRAPPER_MAX_IMAGE_COUNT", "WRAPPER_DMAHEAP_CACHED",
"ALSA_LATENCY_MS", "ALSA_VOLUME", "ALSA_BASS_BOOST", "ALSA_PERFORMANCE_MODE",
"DXVK_ASYNC", "DXVK_GPLASYNCCACHE",
@@ -15,6 +15,10 @@ object GameEnvironmentOptions {
Option("PROTON_LOG", "1", R.string.game_env_proton_log, Type.TOGGLE, listOf("0", "1")),
Option("PROTON_USE_WINED3D", "1", R.string.game_env_wined3d, Type.TOGGLE, listOf("0", "1")),
Option("PROTON_USE_XALIA", "0", R.string.game_env_xalia, Type.TOGGLE, listOf("0", "1")),
Option("PROTON_NO_NTSYNC", "1", R.string.game_env_no_ntsync, Type.TOGGLE, listOf("0", "1")),
Option("PROTON_NO_ESYNC", "1", R.string.game_env_no_esync, Type.TOGGLE, listOf("0", "1")),
Option("PROTON_NO_FSYNC", "1", R.string.game_env_no_fsync, Type.TOGGLE, listOf("0", "1")),
Option("BL_FSYNC_FIRST", "1", R.string.game_env_fsync_first, Type.TOGGLE, listOf("0", "1")),
Option("DXVK_HUD", "fps", R.string.game_env_hud, Type.MULTIPLE, listOf("scale=0.5", "scale=0.7", "opacity=0.5", "opacity=0.7", "devinfo", "fps", "frametimes", "submissions", "drawcalls", "pipelines", "descriptors", "memory", "gpuload", "version", "api", "cs", "compiler", "samplers")),
Option("DXVK_CONFIG", "dxvk.maxFrameRate = 60", R.string.game_env_dxvk_config, Type.TEXT),
Option("VKD3D_FRAME_RATE", "60", R.string.game_env_vkd3d_limit, Type.NUMBER),
@@ -18,7 +18,7 @@ package com.droiddeck.launcher.core
*
* The device's OWN addresses are not kept: the client's IPv6 check logs "external address <ours>"
* about twenty times a session, and a public IPv6 address is the user's. [learnOwnAddresses] reads
* the link the session was given (etc/bannerlator-net) and every address on the same /64 - privacy
* the link the session was given (etc/droiddeck-net) and every address on the same /64 - privacy
* addresses rotate inside it - or an own public IPv4 is replaced wherever it appears. Likewise every
* Steam account and persona name on the device ([learnAccounts]), for users who sign in with an
* account name rather than an email.
@@ -95,7 +95,7 @@ object LogRedactor {
/** Everything the session's runtime can tell about whose logs these are: addresses and accounts. */
fun learnFromRuntime(root: java.io.File) {
learnOwnAddresses(java.io.File(root, "etc/bannerlator-net"))
learnOwnAddresses(java.io.File(root, "etc/droiddeck-net"))
learnAccounts(java.io.File(root, "root/.local/share/Steam/config/loginusers.vdf"))
}
@@ -91,9 +91,9 @@ object NetworkReport {
} else {
append("etc/resolv.conf does not exist yet - written when the session's link is published.\n")
}
val netdev = File(LinuxRuntime.rootDir(context), "etc/bannerlator-net")
val netdev = File(LinuxRuntime.rootDir(context), "etc/droiddeck-net")
if (netdev.isFile) {
append("\netc/bannerlator-net (the link as the session sees it):\n")
append("\netc/droiddeck-net (the link as the session sees it):\n")
FileUtils.readString(netdev)?.lines()?.forEach { append(" ").append(it).append('\n') }
}
append("\nproot makes no network namespace, so the session uses the phone's connection\n")
@@ -204,7 +204,7 @@ object Library {
* Whether a program from the rail runs at the panel's own resolution rather than the session's
* 720p default. melonDS draws two 256x192 screens on the CPU: the panel's size costs it
* nothing, and 720p scaled up to the panel blurs the sharp pixels its screen layout is set
* up for (bannerlator-pad-defaults).
* up for (droiddeck-pad-defaults).
*/
fun drawsAtPanel(program: String?): Boolean = specs.any { it.program == program && it.atPanel }
@@ -341,7 +341,7 @@ object Library {
// Dolphin: full screen, drawn inside its own main window, without its "stop the emulation?"
// question; no warning boxes either, which wait for a click a controller cannot give
// (they still go to Dolphin's log). The guide button is Dolphin's Toggle Fullscreen hotkey
// (bannerlator-pad-defaults), which shows Dolphin's window and its settings - so no -b, which
// (droiddeck-pad-defaults), which shows Dolphin's window and its settings - so no -b, which
// hides that window; closing Dolphin ends the session. Under gamescope Dolphin does not
// always see its window as focused, and by default both its hotkeys and the game's
// controller then stop: HotkeysRequireFocus off, BackgroundInput on. -C sets a Dolphin.ini
@@ -353,10 +353,10 @@ object Library {
"-e", guestPath,
)
// Full screen (LaunchSettings.cpp -f); the settings seed keeps the Getting Started
// dialog away (bannerlator-pad-defaults).
// dialog away (droiddeck-pad-defaults).
"cemu" -> listOf("-f", "-g", guestPath)
// Full screen (CLI.cpp --fullscreen); the guide button leaves it for melonDS's menus and
// comes back (HK_FullscreenToggle, bannerlator-pad-defaults).
// comes back (HK_FullscreenToggle, droiddeck-pad-defaults).
"melonds" -> listOf("-f", guestPath)
else -> listOf(guestPath)
}
@@ -6,7 +6,7 @@ package com.droiddeck.launcher.gpu;
* DXBC chain translated to SPIR-V. {@link Lossless} decides when; these calls block.
*/
final class LsfgNative {
static { System.loadLibrary("bannerwayland"); }
static { System.loadLibrary("droiddeckwayland"); }
private LsfgNative() {}
@@ -13,16 +13,14 @@ import java.io.RandomAccessFile
* AppImages the user brings: picked from storage, checked, and extracted once into the runtime at
* /opt/appimages/user/<id>/app. proot has no FUSE to mount an image, and extracting it at every
* start would cost its whole size in /tmp each time. Each one gets a menu entry on the Linux
* desktop, and the front end starts it under gamescope through bannerlator-appimage-run.
* desktop, and the front end starts it under gamescope through droiddeck-appimage-run.
*
* <id>/name holds the name to show, <id>/icon.png the icon when the image has a PNG one.
*/
object AppImageManager {
private const val TAG = "AppImageManager"
const val GUEST_DIR = "/opt/appimages/user"
const val LAUNCHER = "/usr/local/bin/bannerlator-appimage-run"
private const val ELF_AARCH64 = 183
private const val ELF_X86_64 = 62
const val LAUNCHER = "/usr/local/bin/droiddeck-appimage-run"
private const val SHARP_ICON = 128
class Item(val id: String, val name: String, val icon: File?, val comment: String?) {
@@ -59,9 +57,8 @@ object AppImageManager {
}
val machine = (head[18].toInt() and 0xff) or ((head[19].toInt() and 0xff) shl 8)
return when {
machine == ELF_X86_64 -> "This AppImage is built for x86_64 PCs. DroidDeck runs ARM64 (aarch64) AppImages - look for an \"aarch64\" or \"arm64\" download."
machine != ELF_AARCH64 -> "This AppImage is not built for ARM64 (aarch64)"
head[8] != 'A'.code.toByte() || head[9] != 'I'.code.toByte() -> "This is an ARM64 program but not an AppImage"
machine != LinuxFex.ELF_AARCH64 && !LinuxFex.isX86(machine) -> "This AppImage is built for neither ARM64 (aarch64) nor x86 PCs"
head[8] != 'A'.code.toByte() || head[9] != 'I'.code.toByte() -> "This is a Linux program but not an AppImage"
head[10].toInt() != 2 -> "Only type 2 AppImages can be imported (this one is type ${head[10].toInt()})"
else -> null
}
@@ -96,6 +93,7 @@ object AppImageManager {
val dir = File(base, idFor(name ?: file.name, base.list()?.toSet() ?: emptySet()))
try {
extract(context, dir, file, onProgress)?.let { FileUtils.delete(dir); return it }
LinuxFex.writeArch(dir, LinuxFex.elfMachine(file))
describe(dir, file)
if (name != null) FileUtils.writeString(File(dir, "name"), name)
if (icon != null && !UserApps.saveIcon(icon, File(dir, "icon.png"))) Log.w(TAG, "icon ${icon.path} could not be read")
@@ -119,6 +117,7 @@ object AppImageManager {
}
return try {
extract(context, dir, file, onProgress) ?: run {
LinuxFex.writeArch(dir, LinuxFex.elfMachine(file))
meta.forEach { (k, v) -> FileUtils.writeString(File(dir, k), v) }
null
}
@@ -140,12 +139,14 @@ object AppImageManager {
file.inputStream().use { input -> image.outputStream().use { FileUtils.copy(input, it) } }
image.setExecutable(true, false)
onProgress("Extracting ${file.name}")
val unpack = if (LinuxFex.isX86(LinuxFex.elfMachine(image))) "${LinuxFex.TOOL} extract ./image.AppImage"
else "./image.AppImage --appimage-extract || { rm -rf squashfs-root AppDir; ${LinuxFex.TOOL} extract ./image.AppImage; }"
val out = StringBuilder()
// uruntime's DwarFS images unpack into AppDir with squashfs-root a link to it, and keep
// one program under several names as hard links (sharun), which Android denies apps.
val status = GuestCommand.run(context, listOf(
"/bin/bash", "-c",
"cd \"$1\" && rm -rf squashfs-root AppDir && ./image.AppImage --appimage-extract >/dev/null && " +
"cd \"$1\" && rm -rf squashfs-root AppDir && { $unpack; } >/dev/null && " +
"rm -rf app && mv \"$(readlink -f squashfs-root)\" app && rm -f squashfs-root",
"extract", "$GUEST_DIR/${dir.name}",
), logName = "appimage-import", linkDir = links) { line -> if (out.length < 2000) out.appendLine(line) }
@@ -19,7 +19,7 @@ import java.nio.file.Files
import java.util.concurrent.atomic.AtomicInteger
/**
* Flatpak's sandboxes, started for the runtime's bwrap stand-in (bannerlator-bwrap).
* Flatpak's sandboxes, started for the runtime's bwrap stand-in (droiddeck-bwrap).
*
* A Flatpak app runs with its runtime as /usr and itself as /app, which bwrap arranges with mount
* namespaces Android gives no app. proot can show the same picture, and started here - beside the
@@ -74,8 +74,7 @@ object DeckyManager {
val assets = release.optJSONArray("assets") ?: continue
val rows = (0 until assets.length()).map { assets.getJSONObject(it) }
val arm = rows.firstOrNull { it.optString("name") == "PluginLoader-arm64" }
val guest = LinuxRuntime.rootDir(context)
val fexReady = File(guest, "usr/share/guestos/fex-mesa").isDirectory && File(guest, "usr/bin/FEX").canExecute()
val fexReady = LinuxFex.ready(context)
val binary = arm ?: if (fexReady) rows.firstOrNull { it.optString("name") == "PluginLoader" } else null
val name = binary?.optString("name") ?: continue
val url = binary.optString("browser_download_url").takeIf { it.startsWith("https://") } ?: continue
@@ -7,8 +7,8 @@ import org.json.JSONObject
import java.io.File
/**
* Flatpak in the Linux runtime: putting it there (bannerlator-flatpak-setup), the apps installed
* from Flathub, and installing, removing and updating them (bannerlator-flatpak). One per-user
* Flatpak in the Linux runtime: putting it there (droiddeck-flatpak-setup), the apps installed
* from Flathub, and installing, removing and updating them (droiddeck-flatpak). One per-user
* installation at /root/.local/share/flatpak, so nothing needs the system helper or polkit.
*
* Every command runs in a proot of its own, outside any session: the store works whether or not
@@ -17,11 +17,11 @@ import java.io.File
object FlatpakManager {
private const val TAG = "FlatpakManager"
const val FLATPAK = "/usr/bin/flatpak"
const val BWRAP = "/usr/local/bin/bannerlator-bwrap"
const val BWRAP = "/usr/local/bin/droiddeck-bwrap"
/** The program the front end starts a Flatpak app through, in a session of its own. */
const val LAUNCHER = "/usr/local/bin/bannerlator-flatpak-run"
private const val HELPER = "/usr/local/bin/bannerlator-flatpak"
private const val SETUP = "/usr/local/bin/bannerlator-flatpak-setup"
const val LAUNCHER = "/usr/local/bin/droiddeck-flatpak-run"
private const val HELPER = "/usr/local/bin/droiddeck-flatpak"
private const val SETUP = "/usr/local/bin/droiddeck-flatpak-setup"
private const val USER_DIR = "root/.local/share/flatpak"
/** One store operation at a time: Flatpak locks its installation per transaction anyway. */
@@ -0,0 +1,109 @@
package com.droiddeck.launcher.runtime
import android.util.Log
import com.droiddeck.launcher.core.FileUtils
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
object LegacyNames {
private const val TAG = "LegacyNames"
const val SESSION_SCRIPT = "/usr/local/bin/bannerlator-session"
val SCRIPTS = listOf(
"appimage-run", "bwrap", "desktop-games", "flatpak", "flatpak-run", "flatpak-setup",
"game-env", "login1", "netmanager", "pad-defaults", "proton-extra", "script-run",
"seed-redists", "session", "steam-games", "steam-install", "steam-launch",
"steam-library", "steam-shim", "steam-shortcuts",
)
private val LINKED_DIRS = listOf("etc/bannerlator" to "etc/droiddeck", "usr/local/share/bannerlator" to "usr/local/share/droiddeck")
private val MOVED_FILES = listOf(
"etc/bannerlator-net" to "etc/droiddeck-net",
"etc/bannerlator-network.json" to "etc/droiddeck-network.json",
"etc/bannerlator-wifi-scan-request" to "etc/droiddeck-wifi-scan-request",
)
private const val MENU_DIR = "usr/local/share/applications"
private const val OLD_BIN = "/usr/local/bin/bannerlator-"
private const val NEW_BIN = "/usr/local/bin/droiddeck-"
@JvmStatic
@Synchronized
fun migrateEtc(root: File) {
for ((old, new) in LINKED_DIRS) moveAndLink(File(root, old), File(root, new))
File(root, "etc/droiddeck/empty").mkdirs()
}
@Synchronized
fun migrateRootfs(root: File) {
migrateEtc(root)
for ((old, new) in MOVED_FILES) move(File(root, old), File(root, new))
linkScripts(root)
rewriteMenuEntries(root)
}
private fun isLink(f: File) = Files.isSymbolicLink(f.toPath())
private fun move(legacy: File, target: File) {
if (isLink(legacy) || !legacy.exists()) return
if (legacy.isDirectory && !isLink(target) && (target.isDirectory || !target.exists())) {
target.mkdirs()
legacy.listFiles()?.forEach { move(it, File(target, it.name)) }
if (!legacy.delete()) Log.w(TAG, "could not empty $legacy")
return
}
if (target.exists() || isLink(target)) {
FileUtils.delete(legacy)
} else if (!legacy.renameTo(target)) {
Log.w(TAG, "could not move $legacy to $target")
}
}
private fun moveAndLink(legacy: File, target: File) {
if (isLink(legacy) || !legacy.exists()) return
move(legacy, target)
if (!legacy.exists()) replaceWithLink(legacy, target)
}
private fun replaceWithLink(legacy: File, target: File) {
val link = File(legacy.parentFile, legacy.name + ".link")
FileUtils.delete(link)
try {
Files.createSymbolicLink(link.toPath(), Paths.get(target.name))
if (!link.renameTo(legacy)) {
FileUtils.delete(link)
Log.w(TAG, "could not link $legacy to ${target.name}")
}
} catch (e: Exception) {
FileUtils.delete(link)
Log.w(TAG, "could not link $legacy to ${target.name}", e)
}
}
private fun linkScripts(root: File) {
val bin = File(root, "usr/local/bin")
for (name in SCRIPTS) {
val target = File(bin, "droiddeck-$name")
val legacy = File(bin, "bannerlator-$name")
if (!target.isFile || isLink(target)) continue
if (isLink(legacy)) {
val points = runCatching { Files.readSymbolicLink(legacy.toPath()).toString() }.getOrNull()
if (points == target.name) continue
} else if (!legacy.exists()) {
continue
}
replaceWithLink(legacy, target)
}
}
private fun rewriteMenuEntries(root: File) {
val entries = File(root, MENU_DIR).listFiles { f -> f.isFile && f.name.startsWith("droiddeck-") && f.name.endsWith(".desktop") } ?: return
for (entry in entries) {
val text = FileUtils.readString(entry) ?: continue
if (!text.contains(OLD_BIN)) continue
val staged = File(entry.parentFile, entry.name + ".staged")
if (!FileUtils.writeString(staged, text.replace(OLD_BIN, NEW_BIN)) || !staged.renameTo(entry)) {
staged.delete()
Log.w(TAG, "could not rewrite $entry")
}
}
}
}
@@ -0,0 +1,62 @@
package com.droiddeck.launcher.runtime
import android.content.Context
import com.droiddeck.launcher.core.FileUtils
import org.json.JSONObject
import java.io.File
import java.io.RandomAccessFile
object LinuxFex {
const val TOOL = "/usr/local/bin/droiddeck-fex"
const val AUTO = "auto"
const val ON = "on"
const val OFF = "off"
val MODES = listOf(AUTO, ON, OFF)
const val ELF_I386 = 3
const val ELF_X86_64 = 62
const val ELF_AARCH64 = 183
private const val MODE_FILE = "fex"
private const val ARCH_FILE = "arch"
private const val STATUS = "root/.local/share/droiddeck-fex/status.json"
fun ready(context: Context): Boolean =
FileUtils.readString(File(LinuxRuntime.rootDir(context), STATUS))
?.let { runCatching { JSONObject(it).optBoolean("ready") }.getOrNull() } == true
fun mode(dir: File): String = FileUtils.readString(File(dir, MODE_FILE))?.trim()?.takeIf { it in MODES } ?: AUTO
fun setMode(dir: File, mode: String): Boolean {
val file = File(dir, MODE_FILE)
return when (mode) {
AUTO -> !file.exists() || file.delete()
ON, OFF -> FileUtils.writeString(file, mode)
else -> false
}
}
fun elfMachine(file: File): Int? = try {
RandomAccessFile(file, "r").use { f ->
val head = ByteArray(20)
if (f.read(head) < head.size) return null
if (head[0] != 0x7f.toByte() || head[1] != 'E'.code.toByte() || head[2] != 'L'.code.toByte() || head[3] != 'F'.code.toByte()) return null
if (head[5].toInt() == 2) ((head[18].toInt() and 0xff) shl 8) or (head[19].toInt() and 0xff)
else (head[18].toInt() and 0xff) or ((head[19].toInt() and 0xff) shl 8)
}
} catch (e: Exception) {
null
}
fun isX86(machine: Int?): Boolean = machine == ELF_X86_64 || machine == ELF_I386
fun archName(machine: Int?): String? = when (machine) {
ELF_X86_64 -> "x86_64"
ELF_I386 -> "i386"
ELF_AARCH64 -> "arm64"
else -> null
}
fun writeArch(dir: File, machine: Int?) {
val name = archName(machine)
if (name == null) File(dir, ARCH_FILE).delete() else FileUtils.writeString(File(dir, ARCH_FILE), name)
}
}
@@ -62,7 +62,7 @@ class LinuxNetworkLinkComponent(
synchronized(lock) { writeNetworkState(currentProperties, currentCapabilities) }
requestWifiScan()
}
val stamp = File(rootDir, "etc/bannerlator-wifi-scan-request").lastModified()
val stamp = File(rootDir, "etc/droiddeck-wifi-scan-request").lastModified()
if (stamp != 0L && stamp != scanRequestStamp) {
scanRequestStamp = stamp
requestWifiScan()
@@ -126,7 +126,7 @@ class LinuxNetworkLinkComponent(
addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION)
addAction(LocationManager.MODE_CHANGED_ACTION)
})
scanRequestStamp = File(rootDir, "etc/bannerlator-wifi-scan-request").lastModified()
scanRequestStamp = File(rootDir, "etc/droiddeck-wifi-scan-request").lastModified()
scanHandler.post(scanRequests)
requestWifiScan()
}
@@ -253,7 +253,7 @@ class LinuxNetworkLinkComponent(
}
}
try {
val file = File(rootDir, "etc/bannerlator-network.json")
val file = File(rootDir, "etc/droiddeck-network.json")
val staged = File(file.path + ".staged")
staged.writeText(state.toString())
if (!staged.renameTo(file)) throw IOException("Could not replace network state")
@@ -335,7 +335,7 @@ class LinuxNetworkLinkComponent(
companion object {
private const val TAG = "LinuxNetworkLink"
private const val LINK_FILE = "etc/bannerlator-net"
private const val LINK_FILE = "etc/droiddeck-net"
private const val LINK_INDEX = 2
private const val DEFAULT_MTU = 1500
private const val OFFLINE_NAME = "eth0"
@@ -27,7 +27,7 @@ import java.util.List;
*/
public final class LinuxRuntime {
public static final String DIR = "linuxfs";
public static final String SESSION_SCRIPT = "/usr/local/bin/bannerlator-session";
public static final String SESSION_SCRIPT = "/usr/local/bin/droiddeck-session";
public static final String MODE_DESKTOP = "desktop";
public static final String MODE_STEAM = "steam";
public static final String MODE_RUN = "run";
@@ -91,7 +91,8 @@ public final class LinuxRuntime {
if (LinuxRuntimeInstaller.isRemoving() || LinuxRuntimeInstaller.hasRemovalPending(context)) return false;
File root = rootDir(context);
return new File(root, "usr/bin/gamescope").isFile()
&& new File(root, SESSION_SCRIPT.substring(1)).isFile()
&& (new File(root, SESSION_SCRIPT.substring(1)).isFile()
|| new File(root, LegacyNames.SESSION_SCRIPT.substring(1)).isFile())
&& prootBinary(context).isFile()
&& prootLoader(context).isFile();
}
@@ -182,6 +183,7 @@ public final class LinuxRuntime {
public static List<String> binds(Context context, File sessionRoot, File runtimeDir,
File externalStorage, List<String> extraBinds) {
File root = rootDir(context);
LegacyNames.migrateEtc(root);
List<String> cmd = new ArrayList<>();
bind(cmd, "/dev");
bind(cmd, "/proc");
@@ -191,7 +193,7 @@ public final class LinuxRuntime {
bind(cmd, "/proc/self/fd/0:/dev/stdin");
bind(cmd, "/proc/self/fd/1:/dev/stdout");
bind(cmd, "/proc/self/fd/2:/dev/stderr");
bind(cmd, new File(root, "etc/bannerlator/empty").getPath() + ":/sys/fs/selinux");
bind(cmd, new File(root, "etc/droiddeck/empty").getPath() + ":/sys/fs/selinux");
bind(cmd, context.getFilesDir().getPath());
bind(cmd, context.getCacheDir().getPath());
if (runtimeDir != null) {
@@ -207,7 +209,7 @@ public final class LinuxRuntime {
bind(cmd, shm.getPath() + ":/dev/shm");
// Android denies apps these; glibc, Steam and libcap read them at startup.
File fakeProc = new File(root, "etc/bannerlator/proc");
File fakeProc = new File(root, "etc/droiddeck/proc");
// libpci picks its procfs backend on whether it can read the /proc/bus/pci directory, which
// the app can, then die()s - exit(1) on the calling process - on the devices file inside
// it, which the app cannot. Chromium loads libpci in its GPU process to name the video
@@ -418,7 +420,7 @@ public final class LinuxRuntime {
* under the mainline name.
*/
private static void bindCpuTemps(List<String> cmd, File root) {
File name = new File(root, "etc/bannerlator/cpu-thermal-type");
File name = new File(root, "etc/droiddeck/cpu-thermal-type");
try {
if (!name.isFile()) Files.write(name.toPath(), "cpu0-thermal\n".getBytes(StandardCharsets.US_ASCII));
} catch (IOException e) {
@@ -31,7 +31,7 @@ import java.io.RandomAccessFile
object UserApps {
private const val TAG = "UserApps"
const val GUEST_DIR = "/opt/droiddeck-apps"
const val SCRIPT_LAUNCHER = "/usr/local/bin/bannerlator-script-run"
const val SCRIPT_LAUNCHER = "/usr/local/bin/droiddeck-script-run"
private const val FLATPAK_OVERRIDES = ".flatpak"
private const val ICON_SIZE = 256
private const val ELF_SCAN_LIMIT = 4000
@@ -53,6 +53,7 @@ object UserApps {
val key: String, val kind: Kind, val name: String, val icon: Any?, val detail: String?,
val program: String, val args: List<String>, val copied: Boolean = false,
val repo: String? = null, val version: String? = null,
val fex: String = LinuxFex.AUTO, val arch: String? = null,
)
class Release(val tag: String, val published: String, val asset: String, val url: String)
@@ -89,6 +90,7 @@ object UserApps {
"script:${dir.name}", Kind.SCRIPT, readName(dir) ?: dir.name, File(dir, "icon.png").takeIf { it.isFile },
FileUtils.readString(File(dir, "source"))?.trim(), SCRIPT_LAUNCHER, listOf("$GUEST_DIR/${dir.name}"),
copied = !java.nio.file.Files.isSymbolicLink(File(dir, "files").toPath()),
fex = LinuxFex.mode(dir),
)
}.orEmpty()
val images = AppImageManager.list(context).map { item ->
@@ -96,6 +98,7 @@ object UserApps {
App(
"appimage:${item.id}", Kind.APPIMAGE, item.name, item.icon, item.comment, AppImageManager.LAUNCHER, listOf(item.guestDir),
repo = FileUtils.readString(File(dir, GITHUB_REPO))?.trim(), version = FileUtils.readString(File(dir, GITHUB_TAG))?.trim(),
fex = LinuxFex.mode(dir), arch = FileUtils.readString(File(dir, "arch"))?.trim()?.takeIf { it.isNotEmpty() },
)
}
val flatpaks = FlatpakManager.installedApps(context).map { app ->
@@ -140,7 +143,7 @@ object UserApps {
* Renames [app] and sets its icon: [icon] a path or URL, "" for its default, null to keep it.
* The Linux desktop's menu entry follows.
*/
fun edit(context: Context, app: App, name: String, icon: String?): String? {
fun edit(context: Context, app: App, name: String, icon: String?, fex: String? = null): String? {
val id = app.key.substringAfter(':')
if (id.isEmpty() || '/' in id || id.startsWith(".")) return null
val dir = when (app.kind) {
@@ -155,6 +158,7 @@ object UserApps {
icon.isEmpty() -> if (app.kind == Kind.APPIMAGE) AppImageManager.restoreIcon(dir) else target.delete()
else -> withIcon(context, icon) { file -> if (file == null || !saveIcon(file, target)) return context.getString(R.string.user_apps_icon_failed) }
}
if (fex != null && app.kind != Kind.FLATPAK && !LinuxFex.setMode(dir, fex)) return context.getString(R.string.user_apps_failed)
when (app.kind) {
Kind.SCRIPT -> writeScriptEntry(context, dir)
Kind.APPIMAGE -> AppImageManager.writeMenuEntry(context, dir)
@@ -310,14 +314,18 @@ object UserApps {
return if (repo.isEmpty() || repo == "." || repo == "..") null else "${m.groupValues[1]}/$repo"
}
/** The ARM64 AppImage among a release's files: named for aarch64/arm64, else for no other CPU. */
/**
* The AppImage among a release's files: named for aarch64/arm64, else for no other CPU, else the
* x86_64 one, which runs through FEX.
*/
internal fun pickAsset(names: List<String>): String? {
val images = names.filter { it.endsWith(".appimage", ignoreCase = true) }
return images.firstOrNull { Regex("aarch64|arm64", RegexOption.IGNORE_CASE).containsMatchIn(it) }
?: images.firstOrNull { !Regex("x86_64|x86-64|amd64|x64|i[36]86|armhf|armv7", RegexOption.IGNORE_CASE).containsMatchIn(it) }
?: images.firstOrNull { Regex("x86_64|x86-64|amd64|x64", RegexOption.IGNORE_CASE).containsMatchIn(it) }
}
/** The newest release of [repo] with an ARM64 AppImage, preferring full releases; else what went wrong. */
/** The newest release of [repo] with an AppImage this device runs, preferring full releases; else what went wrong. */
private fun latestRelease(context: Context, repo: String): Pair<Release?, String?> {
val body = Downloader.downloadString("https://api.github.com/repos/$repo/releases?per_page=15")
val releases = body?.let { runCatching { JSONArray(it) }.getOrNull() }
@@ -4,6 +4,7 @@ import com.droiddeck.launcher.core.Hashes
import android.content.Context
import android.util.Log
import com.droiddeck.launcher.core.Downloader
import com.droiddeck.launcher.core.FileUtils
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.github.luben.zstd.ZstdInputStream
import com.github.luben.zstd.ZstdOutputStream
@@ -84,6 +85,7 @@ object ComponentsManager {
val proton: Proton, val components: Map<String, Component>, val originals: List<Original>, val inUseByGame: Boolean,
/** When a launch last had to put this Proton's chosen files back (epoch seconds), or 0. */
val reappliedAt: Long = 0,
val sync: EsyncPacks.ToolState? = null,
)
data class Snapshot(val protons: List<ProtonView>, val packages: List<Package>)
data class Catalog(val items: List<CatalogItem>, val fetchedAt: Long)
@@ -101,11 +103,25 @@ object ComponentsManager {
private fun stateFile(context: Context) = File(dataDir(context), "state.json")
private fun catalogFile(context: Context) = File(dataDir(context), "catalog.json")
/**
* Inside the Linux runtime, read by the Proton launch wrappers (bannerlator-steam-compat's
* Inside the Linux runtime, read by the Proton launch wrappers (steam-compatibility's
* bl_components) before every game launch: desired.tsv + an unpacked copy of each package in use.
*/
private const val LAUNCH_DIR = "root/.local/share/bannerlator-components"
private fun launchDir(context: Context) = File(root(context), LAUNCH_DIR)
private const val LAUNCH_DIR = "root/.local/share/droiddeck-components"
private const val LEGACY_LAUNCH_DIR = "root/.local/share/bannerlator-components"
private fun launchDir(context: Context): File {
migrateLaunchDir(context)
return File(root(context), LAUNCH_DIR)
}
fun migrateLaunchDir(context: Context) = synchronized(lock) {
val legacy = File(root(context), LEGACY_LAUNCH_DIR)
val dir = File(root(context), LAUNCH_DIR)
if (!legacy.isDirectory || dir.exists() || !legacy.renameTo(dir)) return@synchronized
val desired = File(dir, "desired.tsv")
val text = FileUtils.readString(desired) ?: return@synchronized
val staged = File(dir, "desired.tsv.staged")
if (!FileUtils.writeString(staged, text.replace("/$LEGACY_LAUNCH_DIR/", "/$LAUNCH_DIR/")) || !staged.renameTo(desired)) staged.delete()
}
fun safeName(s: String): String = s.replace(Regex("[^A-Za-z0-9._+-]+"), "_").trim('_').ifEmpty { "unnamed" }
@@ -202,22 +218,24 @@ object ComponentsManager {
* Is anything running on this Proton right now - a game, or the client's own start-up runs,
* whose Wine processes can outlive them? Swaps wait while it is. Read from the command lines.
*/
fun inUse(proton: Proton): Boolean = anyProcess(proton) { needle, text -> text.contains(needle + "proton ") || text.contains(needle + "files/bin") }
fun inUse(context: Context, proton: Proton): Boolean = anyProcess(context, proton) { needle, text -> text.contains(needle + "proton ") || text.contains(needle + "files/bin") }
/**
* Is a game running on this Proton? Only a launch runs proton with the verb waitforexitandrun
* (Proton's own script stays up until the game exits); the client's start-up runs do not.
*/
fun gameRunning(proton: Proton): Boolean = anyProcess(proton) { needle, text -> text.contains(needle + "proton waitforexitandrun") }
fun gameRunning(context: Context, proton: Proton): Boolean = anyProcess(context, proton) { needle, text -> text.contains(needle + "proton waitforexitandrun") }
private fun anyProcess(proton: Proton, match: (String, String) -> Boolean): Boolean {
val needle = proton.guestPath.trimEnd('/') + "/"
private fun anyProcess(context: Context, proton: Proton, match: (String, String) -> Boolean): Boolean {
val needles = (listOf(proton.guestPath) + EsyncPacks.distPathsFor(root(context), proton.guestPath))
.map { it.trimEnd('/') + "/" }
val procs = File("/proc").listFiles() ?: return false
for (p in procs) {
if (!p.name.all(Char::isDigit)) continue
val cmd = runCatching { File(p, "cmdline").readBytes() }.getOrNull() ?: continue
if (cmd.isEmpty()) continue
if (match(needle, String(cmd).replace('\u0000', ' '))) return true
val text = String(cmd).replace('\u0000', ' ')
if (needles.any { match(it, text) }) return true
}
return false
}
@@ -290,6 +308,7 @@ object ComponentsManager {
}
}
require(File(staged, "files").isDirectory) { "${wcp.name} has no files/" }
if (comp == "fex") FEX_FILES.filter { it.endsWith(".so") && !File(staged, it).isFile }.forEach { File(dir, it).delete() }
COMP_DIR[comp]?.let { compDir ->
for (arch in PE_ARCHES) {
val target = File(dir, "$compDir/$arch")
@@ -392,6 +411,7 @@ object ComponentsManager {
if (parts.size >= 2) parts[0].toLongOrNull()?.let { reapplied[parts[1]] = maxOf(reapplied[parts[1]] ?: 0, it) }
}
}
val syncPacks = EsyncPacks.status(root(context))
val views = protons(context).map { p ->
val comps = COMPONENTS.associateWith { comp ->
val detected = if (comp == "fex") fexVersion(p.dir) else readVersionFile(File(p.dir, "${COMP_DIR.getValue(comp)}/version"))
@@ -414,7 +434,7 @@ object ComponentsManager {
q?.optString("label"),
)
}
ProtonView(p, comps, originals(context, p.id), gameRunning(p), reapplied[p.dir.name] ?: 0)
ProtonView(p, comps, originals(context, p.id), gameRunning(context, p), reapplied[p.dir.name] ?: 0, syncPacks.tool(p.guestPath))
}
Snapshot(views, packages(context))
}
@@ -489,7 +509,7 @@ object ComponentsManager {
val wcp = File(packagesDir(context), safeName(file))
val info = packageInfo(wcp)
val state = loadState(context)
if (inUse(p)) {
if (inUse(context, p)) {
state.sub("queued").sub(p.id).put(info.comp, JSONObject().put("kind", "package").put("file", wcp.name).put("label", info.version))
saveState(context, state)
return "${LABEL[info.comp]} ${info.version} goes into ${p.name} when the game running on it closes."
@@ -515,7 +535,7 @@ object ComponentsManager {
val wcp = File(originalsDir(context), "$protonId/${safeName(protonVersion)}/$comp.wcp")
check(wcp.isFile) { "That original bundle is not stored" }
val state = loadState(context)
if (inUse(p)) {
if (inUse(context, p)) {
state.sub("queued").sub(p.id).put(comp, JSONObject().put("kind", "original").put("protonVersion", protonVersion).put("label", "Original $protonVersion"))
saveState(context, state)
return "${LABEL[comp]} of ${p.name} goes back to its original when the game running on it closes."
@@ -545,7 +565,7 @@ object ComponentsManager {
val all = protons(context)
for (pid in queued.keys().asSequence().toList()) {
val p = all.firstOrNull { it.id == pid } ?: run { queued.remove(pid); null } ?: continue
if (inUse(p)) continue
if (inUse(context, p)) continue
val comps = queued.optJSONObject(pid) ?: continue
for (comp in comps.keys().asSequence().toList()) {
val q = comps.optJSONObject(comp) ?: continue
@@ -0,0 +1,941 @@
package com.droiddeck.launcher.session
import android.content.Context
import android.util.Log
import com.droiddeck.launcher.core.FileUtils
import com.droiddeck.launcher.core.Hashes
import com.github.luben.zstd.ZstdInputStream
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import org.apache.commons.compress.archivers.tar.TarConstants
import org.json.JSONArray
import org.json.JSONObject
import java.io.BufferedInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.net.HttpURLConnection
import java.net.URL
import java.nio.file.Files
import java.security.KeyFactory
import java.security.PublicKey
import java.security.SecureRandom
import java.security.Signature
import java.security.spec.X509EncodedKeySpec
import java.util.Base64
import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicBoolean
object EsyncPacks {
private const val TAG = "DroidDeckSync"
const val REPO = "Droid-Deck/DroidDeck-Components"
const val INDEX_URL = "https://github.com/$REPO/releases/download/droiddeck-esync-index/index.json"
const val SIG_URL = "$INDEX_URL.sig"
const val ASSET_PREFIX = "https://github.com/$REPO/releases/download/droiddeck-esync-"
const val PUBLIC_KEY = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFyqZQAMh3g3nsEGLU+kBGVPBEkXrDv5F3kPtuQ+FV1DkTCGmYUQ1LS9wJtHGt0Ht4wToHGGEp9yzDibYZ4/zhg=="
const val NTDLL = "files/lib/wine/aarch64-unix/ntdll.so"
const val WINESERVER = "files/bin-arm64/wineserver"
const val GUEST_STORE = "/root/.local/share/droiddeck-esync"
private const val STORE = "root/.local/share/droiddeck-esync"
private const val PACK_JSON = "pack.json"
private const val COMPLETE = ".complete"
private const val IGNORED = ".ignored"
private const val DIST_JSON = ".droiddeck-esync.json"
private const val WANTED = "wanted.tsv"
private const val TOOLS = "tools.tsv"
private const val FLOOR = "floor"
private const val PACK_FAILURES = "packFailures"
private const val PROGRESS_LABEL = "Fetching droiddeck-esync pack"
private const val INDEX_LIMIT = 4L shl 20
private const val SIG_LIMIT = 4096L
private const val ASSET_LIMIT = 256L shl 20
private const val PACK_JSON_LIMIT = 1L shl 20
private const val MAX_AGE_MS = 12L * 60 * 60 * 1000
private const val WANTED_AGE_MS = 30L * 60 * 1000
private const val FAILURE_BACKOFF_MS = 10L * 60 * 1000
private const val STALE_MS = 60L * 60 * 1000
private const val PRUNE_AGE_MS = 30L * 24 * 60 * 60 * 1000
private const val TIMEOUT_MS = 30_000
private val ID = Regex("[A-Za-z0-9][A-Za-z0-9._-]{0,127}")
private val SHA256 = Regex("[0-9a-f]{64}")
private val ASSET_PATH = Regex("[A-Za-z0-9][A-Za-z0-9._-]*/[A-Za-z0-9][A-Za-z0-9._-]*")
private val TEMP = Regex("\\..+\\.tmp-[0-9a-f]{16}")
private val RETIRED = Regex("\\..+\\.del-[0-9a-f]{16}")
private val BINARIES = listOf(NTDLL, WINESERVER)
private val EXPECTED = setOf(PACK_JSON, NTDLL, WINESERVER)
private val REAL_DIRS = setOf(".", "files", "files/bin-arm64", "files/lib", "files/lib/wine", "files/lib/wine/aarch64-unix")
private val DIRECTORIES = REAL_DIRS - "." + ""
private val STOCK_LINKS = setOf("dist.lock", "files/steampipe_fixups_mtime")
data class Asset(val url: String, val sha256: String, val size: Long)
data class Entry(
val id: String,
val flavor: String,
val rev: Int,
val version: String,
val versionLine: String,
val stock: Map<String, String>,
val exports: String,
val sourceMatch: Boolean,
val files: Map<String, String>,
val asset: Asset,
val revoked: Boolean,
)
data class Index(val schema: Int, val generated: Long, val packs: List<Entry>)
private class Signed(val bytes: ByteArray, val sig: ByteArray, val index: Index)
data class Wanted(
val ntdll: String,
val wineserver: String,
val version: String,
val exports: String,
val toolDir: String,
val firstSeen: Long,
val inUse: Rank? = null,
val epoch: Long = 0L,
) {
val key: String get() = "$ntdll:$wineserver"
}
data class Rank(val kind: Int, val sameVersion: Int, val rev: Int) : Comparable<Rank> {
override fun compareTo(other: Rank): Int = compareValuesBy(this, other, { it.kind }, { it.sameVersion }, { it.rev })
}
data class ToolState(
val toolDir: String,
val versionLine: String,
val ntdll: String,
val wineserver: String,
val state: String,
val packId: String?,
)
data class Status(val installed: Int, val wanted: Int, val tools: List<ToolState>) {
fun tool(guestPath: String): ToolState? {
val path = guestPath.trimEnd('/')
return tools.firstOrNull { it.toolDir.trimEnd('/') == path }
}
}
private val fetchLock = Any()
private val cacheLock = Any()
private val installLock = Any()
private val pending = AtomicBoolean(false)
private val executor = Executors.newSingleThreadExecutor { runnable ->
Thread(runnable, "droiddeck-esync-fetch").apply { isDaemon = true }
}
private val random = SecureRandom()
private val shippedKey: PublicKey by lazy { key(PUBLIC_KEY) }
internal var keyOverride: PublicKey? = null
private val publicKey: PublicKey get() = keyOverride ?: shippedKey
internal var fetcher: (String, Long, OutputStream, ((Long) -> Unit)?) -> Boolean = { url, limit, out, progress ->
httpFetch(url, limit, out, progress)
}
fun store(root: File): File = File(root, STORE)
private fun cacheDir(context: Context) = File(context.filesDir, "droiddeck-esync")
internal fun key(base64: String): PublicKey =
KeyFactory.getInstance("EC").generatePublic(X509EncodedKeySpec(Base64.getDecoder().decode(base64)))
fun allowedUrl(url: String): Boolean =
url.startsWith(ASSET_PREFIX) && ASSET_PATH.matches(url.substring(ASSET_PREFIX.length))
fun parseIndex(bytes: ByteArray): Index {
val root = JSONObject(String(bytes, Charsets.UTF_8))
val schema = root.getInt("schema")
require(schema == 1) { "sync index schema $schema is not supported" }
val generated = root.getLong("generated")
val array = root.getJSONArray("packs")
val packs = ArrayList<Entry>()
val seen = HashSet<String>()
for (i in 0 until array.length()) {
val entry = try {
parseEntry(array.getJSONObject(i))
} catch (e: Exception) {
Log.w(TAG, "sync index entry $i skipped: ${e.message}")
continue
}
if (seen.add(entry.id)) packs.add(entry)
}
return Index(schema, generated, packs)
}
private fun parseEntry(o: JSONObject): Entry {
val id = o.getString("id")
require(ID.matches(id)) { "invalid id $id" }
val asset = o.getJSONObject("asset")
val url = asset.getString("url")
require(allowedUrl(url)) { "$id: asset $url is outside $ASSET_PREFIX" }
val sha256 = asset.getString("sha256").lowercase()
require(SHA256.matches(sha256)) { "$id: invalid asset sha256" }
val size = asset.getLong("size")
require(size in 1..ASSET_LIMIT) { "$id: invalid asset size $size" }
val flavor = o.getString("flavor")
require(flavor.isNotEmpty()) { "$id: no flavor" }
return Entry(
id, flavor, o.getInt("rev"), o.optString("version"), o.optString("version_line"),
hashes(o.getJSONObject("stock")), o.optString("exports").lowercase(), o.opt("source_match") == true,
hashes(o.getJSONObject("files")), Asset(url, sha256, size), o.optBoolean("revoked", false),
)
}
private fun hashes(o: JSONObject): Map<String, String> = BINARIES.associateWith { rel ->
o.getString(rel).lowercase().also { require(SHA256.matches(it)) { "invalid sha256 for $rel" } }
}
fun verify(indexBytes: ByteArray, sigBytes: ByteArray): Boolean = try {
verify(indexBytes, sigBytes, publicKey)
} catch (e: Exception) {
false
}
internal fun verify(indexBytes: ByteArray, sigBytes: ByteArray, key: PublicKey): Boolean = try {
Signature.getInstance("SHA256withECDSA").run {
initVerify(key)
update(indexBytes)
verify(sigBytes)
}
} catch (e: Exception) {
false
}
internal fun accept(indexBytes: ByteArray, sigBytes: ByteArray, cached: Index?, key: PublicKey = publicKey, floor: Long = 0L): Index? {
if (!verify(indexBytes, sigBytes, key)) {
Log.w(TAG, "sync index signature does not verify")
return null
}
val index = try {
parseIndex(indexBytes)
} catch (e: Exception) {
Log.w(TAG, "sync index unreadable: ${e.message}")
return null
}
val minimum = maxOf(cached?.generated ?: Long.MIN_VALUE, floor)
if (index.generated < minimum) {
Log.w(TAG, "sync index ${index.generated} is older than $minimum, one already accepted; kept the cached one")
return null
}
return index
}
internal fun kind(entry: Entry, row: Wanted): Int = when {
entry.stock[NTDLL] == row.ntdll && entry.stock[WINESERVER] == row.wineserver ->
if (entry.version != row.version && row.epoch > 0 && epochOf(entry.versionLine) > row.epoch) 0 else 2
entry.sourceMatch && entry.version.isNotEmpty() && entry.version == row.version &&
entry.exports.isNotEmpty() && entry.exports == row.exports -> 1
else -> 0
}
fun matches(entry: Entry, row: Wanted): Boolean = !entry.revoked && kind(entry, row) > 0
internal fun epochOf(versionLine: String): Long =
versionLine.trim().split(Regex("\\s+")).firstOrNull()?.toLongOrNull()?.takeIf { it > 0 } ?: 0L
internal fun withEpochs(wanted: List<Wanted>, tools: List<ToolState>): List<Wanted> = wanted.map { row ->
tools.firstOrNull {
it.toolDir == row.toolDir && it.ntdll.trim().lowercase() == row.ntdll && it.wineserver.trim().lowercase() == row.wineserver
}?.let { row.copy(epoch = epochOf(it.versionLine)) } ?: row
}
internal fun rank(entry: Entry, row: Wanted): Rank =
Rank(kind(entry, row), if (entry.version.isNotEmpty() && entry.version == row.version) 1 else 0, entry.rev)
fun best(entries: List<Entry>, row: Wanted): Entry? = entries.filter { matches(it, row) }
.maxWithOrNull(compareBy<Entry>({ rank(it, row) }, { it.id }))
internal fun plan(index: Index, wanted: List<Wanted>, installed: Set<String>): List<Entry> =
wanted.mapNotNull { row -> best(index.packs, row)?.takeIf { row.inUse == null || rank(it, row) > row.inUse } }
.distinctBy { it.id }.filter { it.id !in installed }
internal fun upgradeRows(store: File, tools: List<ToolState>): List<Wanted> = tools.mapNotNull { tool ->
val ntdll = tool.ntdll.trim().lowercase()
val wineserver = tool.wineserver.trim().lowercase()
if (tool.state != "pack" || !SHA256.matches(ntdll) || !SHA256.matches(wineserver)) return@mapNotNull null
val token = tool.versionLine.trim().split(Regex("\\s+")).getOrNull(1).orEmpty()
val pack = tool.packId?.takeIf { ID.matches(it) }?.let { installedPack(store, it) }
val exports = if (pack != null && pack.opt("source_match") == true && token.isNotEmpty() && pack.opt("version") == token)
(pack.opt("exports") as? String).orEmpty() else ""
val epoch = epochOf(tool.versionLine)
val inUse = pack?.let { packRank(it, ntdll, wineserver, token, exports, epoch) }?.takeIf { it.kind > 0 }
Wanted(ntdll, wineserver, token, exports, tool.toolDir, 0L, inUse, epoch)
}
private fun packRank(pack: JSONObject, ntdll: String, wineserver: String, token: String, exports: String, epoch: Long): Rank =
Rank(covers(pack, ntdll, wineserver, token, exports, epoch), if (token.isNotEmpty() && pack.opt("version") == token) 1 else 0,
pack.optInt("rev"))
private fun installedPack(store: File, id: String): JSONObject? {
val dir = File(store, "packs/$id")
if (!File(dir, COMPLETE).isFile) return null
return readFile(File(dir, PACK_JSON), PACK_JSON_LIMIT)
?.let { runCatching { JSONObject(String(it, Charsets.UTF_8)) }.getOrNull() }
}
fun parseWanted(text: String): List<Wanted> = text.lineSequence().mapNotNull { line ->
val fields = line.trimEnd('\r').split('\t')
if (fields.size < 5) return@mapNotNull null
val ntdll = fields[0].trim().lowercase()
val wineserver = fields[1].trim().lowercase()
if (!SHA256.matches(ntdll) || !SHA256.matches(wineserver)) return@mapNotNull null
Wanted(ntdll, wineserver, field(fields[2]), field(fields[3]).lowercase(), fields[4],
fields.getOrNull(5)?.trim()?.toLongOrNull() ?: 0L)
}.distinctBy { it.key }.toList()
private fun field(value: String): String = value.trim().takeIf { it != "-" }.orEmpty()
fun parseTools(text: String): List<ToolState> = text.lineSequence().mapNotNull { line ->
val fields = line.trimEnd('\r').split('\t')
if (fields.size < 6 || fields[0].isEmpty()) return@mapNotNull null
ToolState(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5].takeIf { it.isNotEmpty() && it != "-" })
}.toList()
fun status(root: File): Status = try {
val store = store(root)
if (!store.isDirectory) Status(0, 0, emptyList())
else {
val wanted = readText(File(store, WANTED))?.let { parseWanted(it) }.orEmpty()
val tools = readText(File(store, TOOLS))?.let { parseTools(it) }.orEmpty()
Status(installedIds(store).size, wanted.size, settled(store, tools, wanted))
}
} catch (t: Throwable) {
Log.w(TAG, "sync status", t)
Status(0, 0, emptyList())
}
internal fun settled(store: File, tools: List<ToolState>, wanted: List<Wanted>): List<ToolState> {
if (tools.none { it.state == "wanted" }) return tools
val packs = installedIds(store).sorted()
.filter { !File(store, "packs/$it/$IGNORED").exists() }
.mapNotNull { id -> installedPack(store, id)?.let { id to it } }
val rows = wanted.associateBy { it.key }
return tools.map { tool ->
if (tool.state != "wanted") return@map tool
val ntdll = tool.ntdll.trim().lowercase()
val wineserver = tool.wineserver.trim().lowercase()
val token = tool.versionLine.trim().split(Regex("\\s+")).getOrNull(1).orEmpty()
val exports = rows["$ntdll:$wineserver"]?.exports.orEmpty()
val epoch = epochOf(tool.versionLine)
val match = packs.map { (id, pack) -> Triple(id, pack, packRank(pack, ntdll, wineserver, token, exports, epoch)) }
.filter { it.third.kind > 0 }
.maxWithOrNull(compareBy({ it.third }, { it.first }))
if (match == null) tool else tool.copy(state = "pack", packId = match.first)
}
}
private fun covers(pack: JSONObject, ntdll: String, wineserver: String, token: String, exports: String, epoch: Long): Int {
val stock = pack.optJSONObject("stock")
val version = pack.opt("version") as? String
if (stock != null && stock.optString(NTDLL) == ntdll && stock.optString(WINESERVER) == wineserver) {
return if (version != token && epoch > 0 && epochOf(pack.optString("version_line")) > epoch) 0 else 2
}
val packExports = pack.opt("exports") as? String
return if (pack.opt("source_match") == true && token.isNotEmpty() && version == token &&
exports.isNotEmpty() && packExports == exports) 1 else 0
}
fun distPathsFor(root: File, stockGuestPath: String): List<String> = try {
val wanted = stockGuestPath.trimEnd('/')
if (wanted.isEmpty()) emptyList()
else File(store(root), "dist").listFiles().orEmpty()
.filter { !it.name.startsWith(".") && it.isDirectory }
.mapNotNull { dir ->
val record = readText(File(dir, DIST_JSON))?.let { runCatching { JSONObject(it) }.getOrNull() }
?: return@mapNotNull null
val stock = record.optString("stock").trimEnd('/')
val tool = record.optString("tool").trimEnd('/')
if (stock == wanted || tool == wanted) "$GUEST_STORE/dist/${dir.name}" else null
}
.sorted()
} catch (t: Throwable) {
Log.w(TAG, "sync dists", t)
emptyList()
}
fun stageBundled(context: Context, root: File) {
try {
val store = store(root)
if (!store.isDirectory && !store.mkdirs()) {
Log.w(TAG, "could not create $store")
return
}
val bundled = bundledIndex(context)
val trusted = if (bundled == null) cachedIndex(context)
else storeIndex(context, bundled.bytes, bundled.sig, bundled.index, newerOnly = true)
if (trusted != null) removeRevoked(store, trusted)
if (bundled == null) return
if (trusted == null) {
Log.w(TAG, "the bundled sync index is older than one already accepted; bundled packs skipped")
return
}
val revoked = (bundled.index.packs + trusted.packs).filter { it.revoked }.map { it.id }.toSet()
val shipped = context.assets.list("droiddeck-esync/packs")?.toSet().orEmpty()
val missing = bundled.index.packs.filter {
it.id !in revoked && "${it.id}.tzst" in shipped && !File(store, "packs/${it.id}/$COMPLETE").isFile
}
if (missing.isEmpty()) return
sweep(context, store)
for (entry in missing) installBundled(context, store, entry)
} catch (t: Throwable) {
Log.w(TAG, "bundled sync packs", t)
}
}
private fun bundledIndex(context: Context): Signed? {
val bundle = context.assets.list("droiddeck-esync")?.toSet().orEmpty()
if ("index.json" !in bundle || "index.json.sig" !in bundle) return null
val bytes = context.assets.open("droiddeck-esync/index.json").use { readBounded(it, INDEX_LIMIT) }
val sig = context.assets.open("droiddeck-esync/index.json.sig").use { readBounded(it, SIG_LIMIT) }
if (!verify(bytes, sig)) {
Log.w(TAG, "the bundled sync index does not verify; bundled packs skipped")
return null
}
return Signed(bytes, sig, parseIndex(bytes))
}
private fun installBundled(context: Context, store: File, entry: Entry) {
val copy = try {
tempFile(context, entry.id)
} catch (e: IOException) {
Log.w(TAG, "bundled sync pack ${entry.id}", e)
return
}
try {
context.assets.open("droiddeck-esync/packs/${entry.id}.tzst").use { input ->
FileOutputStream(copy).use { output -> copyBounded(input, output, entry.asset.size) }
}
if (install(store, entry, copy)) {
Log.i(TAG, "sync pack ${entry.id} installed from the app")
SessionEvents.record("sync.pack", mapOf("id" to entry.id, "source" to "bundled", "result" to "installed"))
}
} catch (t: Throwable) {
Log.w(TAG, "bundled sync pack ${entry.id}", t)
SessionEvents.record("sync.pack", mapOf("id" to entry.id, "source" to "bundled", "result" to "failed", "reason" to t.message))
} finally {
copy.delete()
}
}
fun fetchInBackground(context: Context, root: File) {
val app = context.applicationContext ?: context
if (!pending.compareAndSet(false, true)) return
try {
executor.execute {
pending.set(false)
fetchWanted(app, root)
}
} catch (t: Throwable) {
pending.set(false)
Log.w(TAG, "could not schedule a sync fetch", t)
}
}
fun enabled(context: Context): Boolean = SessionPrefs.syncFallback(context) || try {
GameEnvironmentStore.read(context).let { config ->
(listOf(config.shared) + config.games.values).any { it["BL_SYNC_FALLBACK"] == "1" }
}
} catch (t: Throwable) {
false
}
fun fetchWanted(context: Context, root: File, onProgress: ((String, Int) -> Unit)? = null): Int = synchronized(fetchLock) {
try {
val store = store(root)
if (!store.isDirectory) return 0
cachedIndex(context)?.let { removeRevoked(store, it) }
if (!enabled(context)) return 0
sweep(context, store)
val toolsText = readText(File(store, TOOLS))
val tools = toolsText?.let { parseTools(it) }.orEmpty()
val wanted = withEpochs(readText(File(store, WANTED))?.let { parseWanted(it) }.orEmpty(), tools)
val index = refreshIndex(context, wanted) ?: return 0
removeRevoked(store, index)
val rows = wanted + upgradeRows(store, tools)
if (toolsText != null) prune(store, keep(store, index, rows, tools, bundledIds(context)), System.currentTimeMillis())
val planned = plan(index, rows, installedIds(store))
val state = loadState(context)
val previous = state.optJSONObject(PACK_FAILURES)
val failures = pruneFailures(previous, index)
val missing = planned.filter { !failedRecently(failures, it, System.currentTimeMillis()) }
var added = 0
for (entry in missing) {
if (download(context, store, entry, onProgress)) {
added++
failures.remove(entry.id)
} else {
failures.put(entry.id, failure(failures, entry, System.currentTimeMillis()))
}
}
val kept = failures.takeIf { it.length() > 0 }
if (kept?.toString() != previous?.toString()) {
if (kept != null) state.put(PACK_FAILURES, kept) else state.remove(PACK_FAILURES)
saveState(context, state)
}
if (planned.size > missing.size) Log.i(TAG, "sync: ${planned.size - missing.size} pack(s) wait after failed downloads")
if (missing.isNotEmpty()) Log.i(TAG, "sync: $added of ${missing.size} wanted pack(s) installed")
added
} catch (t: Throwable) {
Log.w(TAG, "fetching sync packs", t)
0
}
}
fun refreshIndex(context: Context, wanted: List<Wanted> = emptyList()): Index? = synchronized(fetchLock) {
val cached = cachedIndex(context)
val state = loadState(context)
val now = System.currentTimeMillis()
if (!due(cached, state, wanted, now)) return cached
val bytes = fetchBytes(INDEX_URL, INDEX_LIMIT)
val sig = if (bytes != null) fetchBytes(SIG_URL, SIG_LIMIT) else null
val fresh = if (bytes != null && sig != null) accept(bytes, sig, cached, floor = floor(context)) else null
if (bytes == null || sig == null || fresh == null) {
state.put("failedAt", now)
saveState(context, state)
return cached
}
val trusted = storeIndex(context, bytes, sig, fresh, newerOnly = false) ?: return cached
state.remove("failedAt")
state.put("checkedAt", now)
state.put("misses", misses(state.optJSONObject("misses"), trusted, wanted, now))
saveState(context, state)
Log.i(TAG, "sync index ${trusted.generated}: ${trusted.packs.size} pack(s)")
trusted
}
internal fun due(cached: Index?, state: JSONObject, wanted: List<Wanted>, now: Long): Boolean {
val failed = state.optLong("failedAt", 0L)
if (failed > 0 && now - failed in 0 until FAILURE_BACKOFF_MS) return false
val checked = state.optLong("checkedAt", 0L)
if (cached == null || checked <= 0 || now < checked || now - checked >= MAX_AGE_MS) return true
val misses = state.optJSONObject("misses")
return wanted.any { row ->
if (cached.packs.any { matches(it, row) }) return@any false
val miss = misses?.optJSONObject(row.key)
val count = miss?.optInt("n", 0) ?: 0
if (count <= 0) now - checked >= WANTED_AGE_MS
else now - (miss?.optLong("at", 0L) ?: 0L) >= backoff(count)
}
}
private fun backoff(misses: Int): Long = minOf(WANTED_AGE_MS shl minOf(misses - 1, 5), MAX_AGE_MS)
private fun packBackoff(failures: Int): Long = minOf(FAILURE_BACKOFF_MS shl minOf(failures - 1, 7), MAX_AGE_MS)
internal fun pruneFailures(previous: JSONObject?, index: Index): JSONObject {
val out = JSONObject()
if (previous == null) return out
val assets = index.packs.associate { it.id to it.asset.sha256 }
for (id in previous.keys()) {
val record = previous.optJSONObject(id) ?: continue
if (assets[id] == record.optString("sha")) out.put(id, record)
}
return out
}
internal fun failedRecently(failures: JSONObject?, entry: Entry, now: Long): Boolean {
val record = failures?.optJSONObject(entry.id) ?: return false
if (record.optString("sha") != entry.asset.sha256) return false
val count = record.optInt("n", 0)
return count > 0 && now - record.optLong("at", 0L) in 0 until packBackoff(count)
}
internal fun failure(failures: JSONObject, entry: Entry, now: Long): JSONObject {
val record = failures.optJSONObject(entry.id)?.takeIf { it.optString("sha") == entry.asset.sha256 }
return JSONObject().put("sha", entry.asset.sha256).put("n", (record?.optInt("n", 0) ?: 0) + 1).put("at", now)
}
private fun misses(previous: JSONObject?, index: Index, wanted: List<Wanted>, now: Long): JSONObject {
val out = JSONObject()
for (row in wanted) {
if (index.packs.any { matches(it, row) }) continue
val count = previous?.optJSONObject(row.key)?.optInt("n", 0) ?: 0
out.put(row.key, JSONObject().put("n", count + 1).put("at", now))
}
return out
}
private fun loadState(context: Context): JSONObject = synchronized(cacheLock) {
readFile(File(cacheDir(context), "state.json"), PACK_JSON_LIMIT)
?.let { runCatching { JSONObject(String(it, Charsets.UTF_8)) }.getOrNull() } ?: JSONObject()
}
private fun saveState(context: Context, state: JSONObject) = synchronized(cacheLock) {
try {
writeAtomic(File(cacheDir(context).apply { mkdirs() }, "state.json"), state.toString().toByteArray(Charsets.UTF_8))
} catch (e: IOException) {
Log.w(TAG, "sync state", e)
}
}
private fun cachedIndex(context: Context): Index? = synchronized(cacheLock) {
val dir = cacheDir(context)
val bytes = readFile(File(dir, "index.json"), INDEX_LIMIT) ?: return null
val sig = readFile(File(dir, "index.json.sig"), SIG_LIMIT) ?: return null
if (!verify(bytes, sig)) {
Log.w(TAG, "the cached sync index does not verify; ignoring it")
return null
}
runCatching { parseIndex(bytes) }.getOrNull()
}
private fun floor(context: Context): Long = synchronized(cacheLock) {
readFile(File(cacheDir(context), FLOOR), 64)?.toString(Charsets.UTF_8)?.trim()?.toLongOrNull() ?: 0L
}
private fun storeIndex(context: Context, bytes: ByteArray, sig: ByteArray, index: Index, newerOnly: Boolean): Index? = synchronized(cacheLock) {
val cached = cachedIndex(context)
val floor = floor(context)
if (index.generated < floor) return cached
if (cached != null && (cached.generated > index.generated || newerOnly && cached.generated >= index.generated)) return cached
try {
val dir = cacheDir(context).apply { mkdirs() }
if (index.generated > floor) writeAtomic(File(dir, FLOOR), index.generated.toString().toByteArray(Charsets.UTF_8))
writeAtomic(File(dir, "index.json.sig"), sig)
writeAtomic(File(dir, "index.json"), bytes)
} catch (e: IOException) {
Log.w(TAG, "could not cache the sync index", e)
}
index
}
private fun download(context: Context, store: File, entry: Entry, onProgress: ((String, Int) -> Unit)?): Boolean {
if (!allowedUrl(entry.asset.url)) {
Log.w(TAG, "sync pack ${entry.id}: ${entry.asset.url} is outside $ASSET_PREFIX")
return false
}
val part = try {
tempFile(context, entry.id)
} catch (e: IOException) {
Log.w(TAG, "sync pack ${entry.id}", e)
return false
}
try {
onProgress?.invoke(PROGRESS_LABEL, -1)
var reported = -1
val fetched = FileOutputStream(part).use { output ->
fetch(entry.asset.url, entry.asset.size, output) { done ->
val percent = (done * 100 / entry.asset.size).toInt().coerceIn(0, 100)
if (percent != reported) {
reported = percent
onProgress?.invoke(PROGRESS_LABEL, percent)
}
}
}
if (!fetched) {
SessionEvents.record("sync.pack", mapOf("id" to entry.id, "source" to "download", "result" to "failed", "reason" to "download"))
return false
}
if (install(store, entry, part)) {
Log.i(TAG, "sync pack ${entry.id} downloaded and installed")
SessionEvents.record("sync.pack", mapOf("id" to entry.id, "source" to "download", "result" to "installed"))
}
return true
} catch (t: Throwable) {
Log.w(TAG, "sync pack ${entry.id}", t)
SessionEvents.record("sync.pack", mapOf("id" to entry.id, "source" to "download", "result" to "failed", "reason" to t.message))
return false
} finally {
part.delete()
}
}
internal fun install(store: File, entry: Entry, archive: File): Boolean {
require(archive.length() == entry.asset.size) { "${entry.id}: ${archive.length()} bytes, the index says ${entry.asset.size}" }
require(Hashes.sha256(archive) == entry.asset.sha256) { "${entry.id}: the archive does not match the index checksum" }
return TarArchiveInputStream(ZstdInputStream(BufferedInputStream(FileInputStream(archive), 1 shl 16))).use {
place(store, entry, it)
}
}
internal fun place(store: File, entry: Entry, tar: TarArchiveInputStream): Boolean {
val packs = File(store, "packs")
if (!packs.isDirectory && !packs.mkdirs()) throw IOException("could not create $packs")
val temp = File(packs, ".${entry.id}.tmp-${token()}")
try {
if (!temp.mkdir()) throw IOException("could not create $temp")
unpack(tar, temp)
val manifest = File(temp, PACK_JSON)
checkPack(JSONObject(manifest.readText()), entry)
for (rel in BINARIES) {
val file = File(temp, rel)
require(Hashes.sha256(file) == entry.files[rel]) { "${entry.id}: $rel does not match the index" }
if (!file.setReadable(true, false) || !file.setExecutable(true, false)) throw IOException("could not mark $rel executable")
}
manifest.setReadable(true, false)
if (!File(temp, COMPLETE).createNewFile()) throw IOException("could not mark ${entry.id} complete")
return commit(packs, temp, entry.id)
} finally {
if (temp.exists()) FileUtils.delete(temp)
}
}
private fun commit(packs: File, temp: File, id: String): Boolean = synchronized(installLock) {
val target = File(packs, id)
if (File(target, COMPLETE).isFile) return false
if (target.exists() || isLink(target)) retire(packs, target)
if (!temp.renameTo(target)) throw IOException("could not move sync pack $id into place")
true
}
internal fun checkPack(pack: JSONObject, entry: Entry) {
require(pack.opt("format") == 1) { "${entry.id}: pack.json format ${pack.opt("format")}" }
require(pack.opt("id") == entry.id) { "pack.json names ${pack.opt("id")}, the index ${entry.id}" }
require(pack.opt("flavor") == entry.flavor) { "${entry.id}: flavor differs from the index" }
require(pack.opt("rev") == entry.rev) { "${entry.id}: rev differs from the index" }
require(pack.opt("version") == entry.version) { "${entry.id}: version differs from the index" }
require(!pack.has("version_line") || pack.opt("version_line") is String) { "${entry.id}: version_line is not a string" }
require(strictHashes(pack.opt("stock")) == entry.stock) { "${entry.id}: stock hashes differ from the index" }
require(pack.opt("exports") == entry.exports) { "${entry.id}: exports differ from the index" }
require(pack.opt("source_match") == entry.sourceMatch) { "${entry.id}: source_match differs from the index" }
require(strictHashes(pack.opt("files")) == entry.files) { "${entry.id}: file hashes differ from the index" }
require(!pack.has("copy") || validCopy(pack.opt("copy"))) { "${entry.id}: invalid copy list" }
require(!truthy(pack.opt("revoked")) && !truthy(pack.opt("ignored"))) { "${entry.id}: pack.json is revoked" }
}
private fun strictHashes(value: Any?): Map<String, String>? {
if (value !is JSONObject) return null
return BINARIES.associateWith { rel -> (value.opt(rel) as? String)?.takeIf { SHA256.matches(it) } ?: return null }
}
private fun validCopy(value: Any?): Boolean =
value is JSONArray && (0 until value.length()).all { copyPath(value.opt(it)) }
internal fun copyPath(value: Any?): Boolean {
if (value !is String || value.isEmpty() || value.startsWith("/") || '\u0000' in value) return false
if (value.split('/').any { it.isEmpty() || it == "." || it == ".." }) return false
return value.substringBeforeLast('/', ".") in REAL_DIRS && value !in BINARIES && value !in REAL_DIRS &&
value !in STOCK_LINKS && value != DIST_JSON
}
private fun truthy(value: Any?): Boolean = when (value) {
null, JSONObject.NULL -> false
is Boolean -> value
is Number -> value.toDouble() != 0.0
is String -> value.isNotEmpty()
is JSONArray -> value.length() > 0
is JSONObject -> value.length() > 0
else -> true
}
internal fun unpack(tar: TarArchiveInputStream, dest: File) {
val seen = HashSet<String>()
while (true) {
val entry = tar.nextEntry ?: break
val rel = entryPath(entry) ?: continue
require(seen.add(rel)) { "$rel appears twice" }
val limit = if (rel == PACK_JSON) PACK_JSON_LIMIT else ASSET_LIMIT
require(entry.size in 0..limit) { "$rel is too large" }
val out = File(dest, rel)
out.parentFile?.let { if (!it.isDirectory && !it.mkdirs()) throw IOException("could not create $it") }
FileOutputStream(out).use {
copyBounded(tar, it, limit)
it.fd.sync()
}
}
require(seen == EXPECTED) { "the pack lacks ${(EXPECTED - seen).joinToString()}" }
}
internal fun entryPath(entry: TarArchiveEntry): String? {
val name = entry.name
require(!name.startsWith("/")) { "absolute path $name" }
val parts = name.split('/').filter { it.isNotEmpty() }.let { if (it.firstOrNull() == ".") it.drop(1) else it }
require(parts.none { it == "." || it == ".." }) { "unsafe path $name" }
require(!entry.isSymbolicLink && !entry.isLink) { "link entry $name" }
require(!entry.isCharacterDevice && !entry.isBlockDevice && !entry.isFIFO) { "device entry $name" }
val rel = parts.joinToString("/")
if (entry.isDirectory) {
require(rel in DIRECTORIES) { "unexpected directory $name" }
return null
}
require(entry.linkFlag == TarConstants.LF_NORMAL || entry.linkFlag == TarConstants.LF_OLDNORM) { "unsupported entry type for $name" }
require(!entry.isSparse) { "sparse entry $name" }
require(rel in EXPECTED) { "unexpected entry $name" }
return rel
}
internal fun installedIds(store: File): Set<String> = File(store, "packs").listFiles().orEmpty()
.filter { ID.matches(it.name) && File(it, COMPLETE).isFile }
.map { it.name }
.toSet()
internal fun removeRevoked(store: File, index: Index): List<String> {
val revoked = index.packs.filter { it.revoked }.map { it.id }.toSet()
if (revoked.isEmpty()) return emptyList()
val packs = File(store, "packs")
val removed = ArrayList<String>()
synchronized(installLock) {
for (id in revoked) {
val dir = File(packs, id)
if (!dir.exists() && !isLink(dir)) continue
retire(packs, dir)
removed.add(id)
}
}
for (id in removed) {
Log.i(TAG, "sync pack $id was revoked; removed")
SessionEvents.record("sync.pack", mapOf("id" to id, "result" to "revoked"))
}
return removed
}
private fun bundledIds(context: Context): Set<String> =
context.assets.list("droiddeck-esync/packs").orEmpty().filter { it.endsWith(".tzst") }.map { it.removeSuffix(".tzst") }.toSet()
internal fun keep(store: File, index: Index, rows: List<Wanted>, tools: List<ToolState>, bundled: Set<String>): Set<String> {
val ids = HashSet(bundled)
tools.mapNotNullTo(ids) { it.packId }
rows.mapNotNullTo(ids) { best(index.packs, it)?.id }
File(store, "dist").listFiles().orEmpty().filter { it.isDirectory }.forEach { dir ->
val record = readText(File(dir, DIST_JSON))?.let { runCatching { JSONObject(it) }.getOrNull() }
(record?.opt("pack") as? String)?.let { ids.add(it) }
}
return ids
}
internal fun prune(store: File, keep: Set<String>, now: Long): List<String> {
val packs = File(store, "packs")
val removed = ArrayList<String>()
synchronized(installLock) {
for (id in installedIds(store).sorted()) {
val dir = File(packs, id)
if (id in keep || now - dir.lastModified() < PRUNE_AGE_MS) continue
retire(packs, dir)
removed.add(id)
}
}
for (id in removed) {
Log.i(TAG, "sync pack $id is no longer used; removed")
SessionEvents.record("sync.pack", mapOf("id" to id, "result" to "pruned"))
}
return removed
}
private fun retire(packs: File, dir: File) {
val gone = File(packs, ".${dir.name}.del-${token()}")
if (dir.renameTo(gone)) FileUtils.delete(gone) else FileUtils.delete(dir)
}
private fun sweep(context: Context, store: File) {
val now = System.currentTimeMillis()
synchronized(installLock) {
File(store, "packs").listFiles()?.forEach { file ->
if (RETIRED.matches(file.name) || TEMP.matches(file.name) && now - file.lastModified() > STALE_MS) FileUtils.delete(file)
}
}
File(cacheDir(context), "tmp").listFiles()?.forEach { file ->
if (now - file.lastModified() > STALE_MS) FileUtils.delete(file)
}
}
private fun fetchBytes(url: String, limit: Long): ByteArray? {
val out = ByteArrayOutputStream()
return if (fetch(url, limit, out, null)) out.toByteArray() else null
}
private fun fetch(url: String, limit: Long, out: OutputStream, progress: ((Long) -> Unit)?): Boolean =
fetcher(url, limit, out, progress)
private fun httpFetch(url: String, limit: Long, out: OutputStream, progress: ((Long) -> Unit)?): Boolean {
var connection: HttpURLConnection? = null
try {
connection = (URL(url).openConnection() as HttpURLConnection).apply {
connectTimeout = TIMEOUT_MS
readTimeout = TIMEOUT_MS
instanceFollowRedirects = true
setRequestProperty("User-Agent", "DroidDeck-Android")
}
val code = connection.responseCode
if (code / 100 != 2) {
Log.w(TAG, "$url -> HTTP $code")
return false
}
if (connection.contentLengthLong > limit) {
Log.w(TAG, "$url is ${connection.contentLengthLong} bytes, more than $limit")
return false
}
connection.inputStream.use { input ->
val buffer = ByteArray(1 shl 16)
var total = 0L
while (true) {
val n = input.read(buffer)
if (n < 0) break
total += n
if (total > limit) {
Log.w(TAG, "$url sent more than $limit bytes")
return false
}
out.write(buffer, 0, n)
progress?.invoke(total)
}
}
return true
} catch (e: Exception) {
Log.w(TAG, "GET $url: ${e.message}")
return false
} finally {
connection?.disconnect()
}
}
private fun copyBounded(input: InputStream, out: OutputStream, limit: Long): Long {
val buffer = ByteArray(1 shl 16)
var total = 0L
while (true) {
val n = input.read(buffer)
if (n < 0) return total
total += n
if (total > limit) throw IOException("more than $limit bytes")
out.write(buffer, 0, n)
}
}
private fun readBounded(input: InputStream, limit: Long): ByteArray {
val out = ByteArrayOutputStream()
copyBounded(input, out, limit)
return out.toByteArray()
}
private fun readFile(file: File, limit: Long): ByteArray? = try {
if (!file.isFile || file.length() > limit) null else file.readBytes()
} catch (e: IOException) {
null
}
private fun readText(file: File): String? = readFile(file, INDEX_LIMIT)?.toString(Charsets.UTF_8)
private fun writeAtomic(file: File, bytes: ByteArray) {
val temp = File(file.parentFile, ".${file.name}.tmp-${token()}")
try {
temp.writeBytes(bytes)
if (!temp.renameTo(file)) throw IOException("could not replace $file")
} finally {
if (temp.exists()) temp.delete()
}
}
private fun tempFile(context: Context, id: String): File {
val dir = File(cacheDir(context), "tmp")
if (!dir.isDirectory && !dir.mkdirs()) throw IOException("could not create $dir")
return File(dir, "$id.${token()}.tzst")
}
private fun isLink(file: File): Boolean = try {
Files.isSymbolicLink(file.toPath())
} catch (e: Exception) {
false
}
private fun token(): String {
val bytes = ByteArray(8)
synchronized(random) { random.nextBytes(bytes) }
return bytes.joinToString("") { "%02x".format(it.toInt() and 0xff) }
}
}
@@ -11,7 +11,7 @@ import java.io.File
object GameEnvironmentStore {
private const val SETTINGS = "game-environment.json"
private const val GUEST_FILE = "root/.config/droiddeck/game-environment.json"
/** The published file's extra DXVK options (bannerlator-game-env reads it; the app's own file has none). */
/** The published file's extra DXVK options (droiddeck-game-env reads it; the app's own file has none). */
const val DXVK_CONFIG = "dxvkConfig"
@Synchronized
@@ -4,7 +4,7 @@ import java.io.File
/**
* Whether Deck mode's performance overlay is on screen. The client sets its level by rewriting
* mangoapp's config (bannerlator-session makes it, `/tmp/mangohud.*`), and `no_display` is the
* mangoapp's config (droiddeck-session makes it, `/tmp/mangohud.*`), and `no_display` is the
* level that hides it. The feeds whose reads cost something - the fan's tachometer busy-waits in
* the kernel, GPU memory walks every process's mappings - only run while it shows.
*/
@@ -0,0 +1,86 @@
package com.droiddeck.launcher.session
import android.content.Context
import android.util.Log
import com.droiddeck.launcher.runtime.LinuxRuntime
import org.json.JSONObject
import java.io.File
object ProtonDefault {
private const val TAG = "ProtonDefault"
private const val DIR = "root/.local/share/droiddeck-compat"
data class Tool(val name: String, val display: String, val dir: String, val valve: Boolean)
data class Request(val seq: Long, val valve: Boolean, val dir: String)
data class State(val default: String?, val applied: Long, val live: Boolean, val pending: String?, val tools: List<Tool>)
enum class Outcome { LIVE, NEXT_START, NOT_RUNNABLE }
private fun dir(context: Context) = File(LinuxRuntime.rootDir(context), DIR)
internal fun parseState(text: String?): State {
val o = runCatching { JSONObject(text ?: "") }.getOrNull() ?: return State(null, 0, false, null, emptyList())
val tools = o.optJSONArray("tools")
return State(
default = o.optString("default").ifEmpty { null },
applied = o.optLong("applied", 0),
live = o.optBoolean("live", false),
pending = o.optString("pending").ifEmpty { null },
tools = (0 until (tools?.length() ?: 0)).mapNotNull { i ->
tools?.optJSONObject(i)?.let { t ->
Tool(t.optString("name"), t.optString("display"), t.optString("dir"), t.optBoolean("valve"))
}?.takeIf { it.name.isNotEmpty() }
},
)
}
internal fun parseRequest(text: String?): Request? {
val o = runCatching { JSONObject(text ?: "") }.getOrNull() ?: return null
val seq = o.optLong("seq", 0)
val dir = o.optString("dir")
return if (seq > 0 && dir.isNotEmpty()) Request(seq, o.optBoolean("valve"), dir) else null
}
internal fun chosen(state: State, request: Request?): Pair<Boolean, String>? {
if (request != null && request.seq > state.applied) return request.valve to request.dir
val tool = state.tools.firstOrNull { it.name == state.default } ?: return null
return tool.valve to tool.dir
}
internal fun runnable(state: State, proton: ComponentsManager.Proton): Boolean =
state.tools.isEmpty() || state.tools.any { it.valve == proton.valve && it.dir == proton.dir.name }
private fun read(file: File): String? = runCatching { file.readText() }.getOrNull()
fun state(context: Context): State = parseState(read(File(dir(context), "state.json")))
fun selectedId(context: Context, protons: List<ComponentsManager.Proton>): String? {
val d = dir(context)
val pick = chosen(parseState(read(File(d, "state.json"))), parseRequest(read(File(d, "request.json")))) ?: return null
return protons.firstOrNull { it.valve == pick.first && it.dir.name == pick.second }?.id
}
internal fun nextSeq(now: Long, state: State, previous: Request?): Long =
maxOf(now, state.applied + 1, (previous?.seq ?: 0) + 1)
@Synchronized
fun request(context: Context, proton: ComponentsManager.Proton): Outcome {
val state = state(context)
if (!runnable(state, proton)) return Outcome.NOT_RUNNABLE
val d = dir(context)
val seq = nextSeq(System.currentTimeMillis(), state, parseRequest(read(File(d, "request.json"))))
val body = JSONObject().put("seq", seq).put("valve", proton.valve).put("dir", proton.dir.name).toString(1) + "\n"
val staged = File(d, "request.json.staged")
try {
d.mkdirs()
staged.writeText(body)
if (!staged.renameTo(File(d, "request.json"))) throw java.io.IOException("rename failed")
} catch (e: Exception) {
staged.delete()
Log.w(TAG, "could not write the Proton request", e)
throw e
}
val tool = state.tools.firstOrNull { it.valve == proton.valve && it.dir == proton.dir.name }
return if (SessionState.running && state.live && (tool == null || state.pending != tool.name)) Outcome.LIVE else Outcome.NEXT_START
}
}
@@ -131,7 +131,7 @@ object ProtonExtras {
val guest = listOf(
"/usr/bin/env", "-i", "HOME=/root", "USER=root", "PATH=/usr/local/bin:/usr/bin:/bin",
"LANG=C.UTF-8", "XDG_DATA_HOME=/root/.local/share",
"/usr/local/bin/bannerlator-proton-extra", "/root/.local/share/Steam", archive.absolutePath,
"/usr/local/bin/droiddeck-proton-extra", "/root/.local/share/Steam", archive.absolutePath,
)
val command = LinuxRuntime.command(context, null, runtimeDir, null, guest)
val process = ProcessBuilder(command)
@@ -155,6 +155,14 @@ object ProtonExtras {
else {
archive.delete()
unqueue(context, tool)
if (EsyncPacks.enabled(context)) {
onProgress("Fetching droiddeck-esync pack", -1)
try {
EsyncPacks.fetchWanted(context, root, onProgress)
} catch (t: Throwable) {
Log.w(TAG, "sync pack for ${tool.name}", t)
}
}
null
}
} catch (e: Exception) {
@@ -13,6 +13,8 @@ object SecondaryLibrary {
"4185400" to "SteamLinuxRuntime_4-arm64",
"4427310" to "Proton Experimental (ARM64)",
"4628740" to "Proton 11.0 (ARM64)",
"1628350" to "SteamLinuxRuntime_sniper",
"3127680" to "FEX-Emu",
)
fun privateRoot(files: File, library: File): File {
@@ -32,7 +34,7 @@ object SecondaryLibrary {
val id = Regex("\"appid\"\\s+\"(\\d+)\"").find(text)?.groupValues?.get(1)
val dir = Regex("\"installdir\"\\s+\"([^\"]+)\"").find(text)?.groupValues?.get(1)
if (id != null && dir != null && File(dir).name == dir &&
(dir.startsWith("Proton ") || dir.startsWith("SteamLinuxRuntime"))) tools[id] = dir
(dir.startsWith("Proton ") || dir.startsWith("SteamLinuxRuntime") || id in bootstrapTools)) tools[id] = dir
}
val overrides = ArrayList<Pair<File, String>>()
for (name in listOf("compatdata", "shadercache")) {
@@ -3,7 +3,9 @@ package com.droiddeck.launcher.session
import android.content.Context
import android.os.Environment
import android.util.Log
import com.droiddeck.launcher.R
import com.droiddeck.launcher.core.FileUtils
import com.droiddeck.launcher.runtime.LegacyNames
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.runtime.ProotFastPath
import java.io.File
@@ -27,35 +29,38 @@ object SessionFiles {
fun stage(context: Context, root: File) {
GameEnvironmentStore.publish(context)
val files = arrayOf(
"usr/local/bin/bannerlator-game-env" to "usr/local/bin/bannerlator-game-env",
"usr/local/bin/droiddeck-game-env" to "usr/local/bin/droiddeck-game-env",
"usr/local/bin/droiddeck-esync" to "usr/local/bin/droiddeck-esync",
"usr/local/bin/droiddeck-steam-compat" to "usr/local/bin/droiddeck-steam-compat",
"usr/local/bin/droiddeck-fex" to "usr/local/bin/droiddeck-fex",
"libblsession.so" to "usr/local/lib/libblsession.so",
"libfakeinput.so" to "usr/local/lib/libfakeinput.so",
"libblfastpath.so" to "usr/local/lib/libblfastpath.so",
"usr/local/bin/bannerlator-session" to "usr/local/bin/bannerlator-session",
"usr/local/bin/droiddeck-session" to "usr/local/bin/droiddeck-session",
"usr/local/bin/steam-compatibility" to "usr/local/bin/steam-compatibility",
"usr/local/bin/droiddeck-clipboard" to "usr/local/bin/droiddeck-clipboard",
"usr/local/bin/bannerlator-steam-compat" to "usr/local/bin/bannerlator-steam-compat",
"usr/local/bin/bannerlator-steam-install" to "usr/local/bin/bannerlator-steam-install",
"usr/local/bin/bannerlator-steam-ui-scale" to "usr/local/bin/bannerlator-steam-ui-scale",
"usr/local/bin/bannerlator-steam-library" to "usr/local/bin/bannerlator-steam-library",
"usr/local/bin/bannerlator-seed-redists" to "usr/local/bin/bannerlator-seed-redists",
"usr/local/bin/bannerlator-proton-extra" to "usr/local/bin/bannerlator-proton-extra",
"usr/local/bin/bannerlator-netmanager" to "usr/local/bin/bannerlator-netmanager",
"usr/local/bin/bannerlator-login1" to "usr/local/bin/bannerlator-login1",
"usr/local/bin/bannerlator-steam-launch" to "usr/local/bin/bannerlator-steam-launch",
"usr/local/bin/bannerlator-desktop-games" to "usr/local/bin/bannerlator-desktop-games",
"usr/local/bin/bannerlator-desktop-bookmarks" to "usr/local/bin/bannerlator-desktop-bookmarks",
"usr/local/bin/bannerlator-steam-shim" to "usr/local/bin/bannerlator-steam-shim",
"usr/local/bin/bannerlator-steam-shortcuts" to "usr/local/bin/bannerlator-steam-shortcuts",
"usr/local/bin/bannerlator-steam-games" to "usr/local/bin/bannerlator-steam-games",
"usr/local/bin/bannerlator-pad-defaults" to "usr/local/bin/bannerlator-pad-defaults",
"usr/local/bin/droiddeck-steam-install" to "usr/local/bin/droiddeck-steam-install",
"usr/local/bin/droiddeck-steam-ui-scale" to "usr/local/bin/droiddeck-steam-ui-scale",
"usr/local/bin/droiddeck-steam-library" to "usr/local/bin/droiddeck-steam-library",
"usr/local/bin/droiddeck-seed-redists" to "usr/local/bin/droiddeck-seed-redists",
"usr/local/bin/droiddeck-proton-extra" to "usr/local/bin/droiddeck-proton-extra",
"usr/local/bin/droiddeck-netmanager" to "usr/local/bin/droiddeck-netmanager",
"usr/local/bin/droiddeck-login1" to "usr/local/bin/droiddeck-login1",
"usr/local/bin/droiddeck-steam-launch" to "usr/local/bin/droiddeck-steam-launch",
"usr/local/bin/droiddeck-desktop-games" to "usr/local/bin/droiddeck-desktop-games",
"usr/local/bin/droiddeck-desktop-bookmarks" to "usr/local/bin/droiddeck-desktop-bookmarks",
"usr/local/bin/droiddeck-steam-shim" to "usr/local/bin/droiddeck-steam-shim",
"usr/local/bin/droiddeck-steam-shortcuts" to "usr/local/bin/droiddeck-steam-shortcuts",
"usr/local/bin/droiddeck-steam-games" to "usr/local/bin/droiddeck-steam-games",
"usr/local/bin/droiddeck-pad-defaults" to "usr/local/bin/droiddeck-pad-defaults",
// Flatpak: the bwrap stand-in, the store's helper and setup, and the front end's launcher.
"usr/local/bin/bannerlator-bwrap" to "usr/local/bin/bannerlator-bwrap",
"usr/local/bin/bannerlator-flatpak" to "usr/local/bin/bannerlator-flatpak",
"usr/local/bin/bannerlator-flatpak-setup" to "usr/local/bin/bannerlator-flatpak-setup",
"usr/local/bin/bannerlator-flatpak-run" to "usr/local/bin/bannerlator-flatpak-run",
"usr/local/bin/droiddeck-bwrap" to "usr/local/bin/droiddeck-bwrap",
"usr/local/bin/droiddeck-flatpak" to "usr/local/bin/droiddeck-flatpak",
"usr/local/bin/droiddeck-flatpak-setup" to "usr/local/bin/droiddeck-flatpak-setup",
"usr/local/bin/droiddeck-flatpak-run" to "usr/local/bin/droiddeck-flatpak-run",
// The user's own AppImages, extracted at import (AppImageManager).
"usr/local/bin/bannerlator-appimage-run" to "usr/local/bin/bannerlator-appimage-run",
"usr/local/bin/bannerlator-script-run" to "usr/local/bin/bannerlator-script-run",
"usr/local/bin/droiddeck-appimage-run" to "usr/local/bin/droiddeck-appimage-run",
"usr/local/bin/droiddeck-script-run" to "usr/local/bin/droiddeck-script-run",
// The SteamOS helpers the client calls in Deck mode: the two Armada found it needs, plus
// the three under /usr/bin, all no-ops that answer "nothing to do" (see each file).
"usr/bin/steamos-update" to "usr/bin/steamos-update",
@@ -102,9 +107,14 @@ object SessionFiles {
val wlroots = if (File(root, "usr/bin/labwc").isFile) {
arrayOf("usr/local/lib/droiddeck-wlroots/libwlroots-0.20.so" to "usr/local/lib/droiddeck-wlroots/libwlroots-0.20.so")
} else emptyArray()
val fexPreloads = listOf("x86_64", "i386").flatMap { arch ->
listOf("libblsession.so", "libfakeinput.so").map { "$arch/$it" to "usr/local/lib/droiddeck-fex/$arch/$it" }
} + listOf("libfaultreport.so", "libthunkaudit.so", "libvulkan-thunk.so").map { "x86_64/$it" to "usr/local/lib/droiddeck-fex/x86_64/$it" }
val optional = (arrayOf(
"usr/local/bin/gamescope" to "usr/local/bin/gamescope",
) + wlroots + mangoapp).filter { (asset, _) ->
"usr/local/lib/droiddeck/uruntime" to "usr/local/lib/droiddeck/uruntime",
"usr/local/share/licenses/uruntime/LICENSE" to "usr/local/share/licenses/uruntime/LICENSE",
) + wlroots + mangoapp + fexPreloads).filter { (asset, _) ->
val dir = asset.substringBeforeLast('/')
runCatching { context.assets.list("linuxfs/$dir")?.contains(asset.substringAfterLast('/')) == true }.getOrDefault(false)
}
@@ -126,6 +136,10 @@ object SessionFiles {
}
if (!installed) Log.e(TAG, "$relative NOT staged")
}
File(root, "usr/local/bin/bannerlator-steam-compat").delete()
LegacyNames.migrateRootfs(root)
ComponentsManager.migrateLaunchDir(context)
EsyncPacks.stageBundled(context, root)
// The DirectAudio driver for games under Proton: the glibc build of winedirectaudio, which
// the Proton wrappers add to WINEDLLPATH when the session asks for it (BL_DIRECTAUDIO).
// Staged like the scripts, so a driver fix reaches an installed runtime without re-hosting.
@@ -168,6 +182,9 @@ object SessionFiles {
staged.delete()
Log.e(TAG, "could not write ld.so.preload")
}
if (!FileUtils.writeString(File(etc, "steam-compatibility-label"), context.getString(R.string.steam_compat_label))) {
Log.e(TAG, "could not write steam-compatibility-label")
}
val startupMovieDir = File(root, "root/.local/share/Steam/config/uioverrides/movies")
// Steam looks up these conventional names in its user override directory. Keep both
@@ -285,6 +285,52 @@ object SessionPrefs {
prefs(context).edit().putBoolean("noXalia", on).apply()
}
fun fastSync(context: Context): Boolean = prefs(context).getBoolean("fastSync", false)
fun setFastSync(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("fastSync", on).apply()
}
fun fsyncFirst(context: Context): Boolean = prefs(context).getBoolean("fsyncFirst", true)
fun setFsyncFirst(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("fsyncFirst", on).apply()
}
const val SYNC_ESYNC = "esync"
const val SYNC_NTSYNC = "ntsync"
const val SYNC_FSYNC = "fsync"
const val SYNC_WINESERVER = "wineserver"
/**
* The sync Proton games use, as the three switches above decide it: droiddeck-ntsync wins
* while it is on, then droiddeck-fsync first, then droiddeck-esync, and wineserver alone while all three are off.
*/
fun syncBackend(context: Context): String = syncBackendOf(fastSync(context), fsyncFirst(context), syncFallback(context))
fun syncBackendOf(fastSync: Boolean, fsyncFirst: Boolean, syncFallback: Boolean): String = when {
fastSync -> SYNC_NTSYNC
fsyncFirst -> SYNC_FSYNC
syncFallback -> SYNC_ESYNC
else -> SYNC_WINESERVER
}
/** Picks one sync for Proton games; the switches change together, in one write. */
fun setSyncBackend(context: Context, backend: String) {
require(backend == SYNC_ESYNC || backend == SYNC_NTSYNC || backend == SYNC_FSYNC || backend == SYNC_WINESERVER) { "unknown sync $backend" }
prefs(context).edit()
.putBoolean("fastSync", backend == SYNC_NTSYNC)
.putBoolean("fsyncFirst", backend == SYNC_FSYNC)
.putBoolean("syncFallback", backend != SYNC_WINESERVER)
.apply()
}
fun syncFallback(context: Context): Boolean = prefs(context).getBoolean("syncFallback", true)
fun setSyncFallback(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("syncFallback", on).apply()
}
/**
* Whether gamescope asks for realtime-priority Vulkan queues (GAMESCOPE_FORCE_VULKAN_REALTIME=1,
* which the app's gamescope build honours without CAP_SYS_NICE). Off by default, as in
@@ -212,7 +212,7 @@ class SessionService : Service() {
}
// Another Steam client on the device signs ours out seconds after every login; the one that
// does it here runs from boot without being opened. Only the Steam session signs in.
// The desktop too: its Steam launchers run the client right there (bannerlator-steam-launch).
// The desktop too: its Steam launchers run the client right there (droiddeck-steam-launch).
if (SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP) RivalClients.stopBeforeSession(this)
SessionState.firstFrameSeen = false
SessionState.guestPid = -1
@@ -300,7 +300,7 @@ class SessionService : Service() {
val size = SessionState.outputSize
val guest = ArrayList<String>()
// The desktop's Steam launchers start the client there (bannerlator-steam-launch), through the
// The desktop's Steam launchers start the client there (droiddeck-steam-launch), through the
// same set-up as a Steam session: it gets what the client and its games are started with.
val steamHere = SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP
addClientEnvironment(guest, steamHere)
@@ -339,7 +339,7 @@ class SessionService : Service() {
guest.add("BL_WLR_RENDERER=" + (override?.takeIf { it.isNotEmpty() } ?: SessionPrefs.desktopRenderer(this)))
}
// The user's own games, for the runtime's shortcuts writer to put in the client's library
// before the client starts (see frontend/AddedGames and bannerlator-steam-shortcuts).
// before the client starts (see frontend/AddedGames and droiddeck-steam-shortcuts).
if (steamHere) {
val added = com.droiddeck.launcher.frontend.AddedGames.scan(this)
val listing = com.droiddeck.launcher.frontend.AddedGames.writeListing(this, added)
@@ -350,7 +350,7 @@ class SessionService : Service() {
}
// Where the guest leaves a request for another session (the desktop's Steam launchers).
guest.add("BL_LAUNCH_DIR=" + sessionRoot.path)
// The second library's name, for bannerlator-steam-library; the bind itself is made below.
// The second library's name, for droiddeck-steam-library; the bind itself is made below.
GameStorage.effective(this)?.let { guest.add("BL_LIBRARY_LABEL=" + it.label.replace('"', ' ')) }
if (SessionState.mode == MODE_STEAM && SessionState.steamUi == "desktop") guest.add("BL_STEAM_UI=desktop")
// The desktop asked for with Steam in it (the front end's "Steam Desktop UI", Big Picture's
@@ -455,6 +455,8 @@ class SessionService : Service() {
it.replace("\\", "\\\\").replace(" ", "\\ ")
}
watchLaunchRequests(sessionRoot)
watchSyncWanted(root)
EsyncPacks.fetchInBackground(this, root)
// One session replacing another (the desktop's Steam launchers): the old proot is killed
// by the teardown a second after the new one has started, and its exit used to arrive
// here as "session ended: 137" and end the NEW session. An exit belongs to the session
@@ -473,6 +475,8 @@ class SessionService : Service() {
if (gen == sessionGen) {
launchWatcher?.stopWatching()
launchWatcher = null
syncWatcher?.stopWatching()
syncWatcher = null
components.reversed().forEach { runCatching { it.stop() } }
components.clear()
}
@@ -594,6 +598,9 @@ class SessionService : Service() {
// XALIA_SUPPORTED_ONLY itself otherwise). Skipped by default: under FEX it costs every game
// a slice of a core for gamepad navigation the session already has.
if (SessionPrefs.noXalia(this)) guest.add("PROTON_USE_XALIA=0")
guest.add("BL_SYNC=" + (if (SessionPrefs.fastSync(this)) "1" else "0"))
guest.add("BL_SYNC_FALLBACK=" + (if (SessionPrefs.syncFallback(this)) "1" else "0"))
guest.add("BL_FSYNC_FIRST=" + (if (SessionPrefs.fsyncFirst(this)) "1" else "0"))
// gamescope's realtime Vulkan queues (the session script turns this into
// GAMESCOPE_FORCE_VULKAN_REALTIME); off unless the user turns it on.
guest.add("BL_GAMESCOPE_REALTIME=" + (if (SessionPrefs.gamescopeRealtime(this)) "1" else "0"))
@@ -781,7 +788,7 @@ class SessionService : Service() {
File(home, "Storage").mkdirs()
binds.add(Environment.getExternalStorageDirectory().path + ":/root/Storage")
// A second Steam library: the storage chosen in the Steam cog, at the path the runtime's
// bannerlator-steam-library registers with the client. Nothing bound = the script removes
// droiddeck-steam-library registers with the client. Nothing bound = the script removes
// the entry, so the client never offers a place that is not there.
val library = GameStorage.effective(this)
var storageDiagnosticLibrary: File? = null
@@ -1112,6 +1119,24 @@ class SessionService : Service() {
launchWatcher = watcher
}
@Volatile private var syncWatcher: android.os.FileObserver? = null
private fun watchSyncWanted(root: File) {
syncWatcher?.stopWatching()
syncWatcher = null
val store = EsyncPacks.store(root)
if (!store.isDirectory) return
@Suppress("DEPRECATION")
val watcher = object : android.os.FileObserver(store.path, CLOSE_WRITE or MOVED_TO) {
override fun onEvent(event: Int, path: String?) {
if (path != "wanted.tsv" && path != "tools.tsv") return
EsyncPacks.fetchInBackground(this@SessionService, root)
}
}
watcher.startWatching()
syncWatcher = watcher
}
private fun updateSuspendPolicy() {
if (!SessionState.running) return
if (suspendPolicy == SessionPrefs.SUSPEND_MANUAL && (!activityVisible || !screenOn)) {
@@ -1253,6 +1278,8 @@ class SessionService : Service() {
suspendOperationPending = false
launchWatcher?.stopWatching()
launchWatcher = null
syncWatcher?.stopWatching()
syncWatcher = null
// proot's --kill-on-exit takes the guest tree down only if proot gets to run it, and
// SIGKILL never lets it. A SIGKILLed proot left its tracees alive with no tracer: every
// seccomp-trapped syscall then failed with ENOSYS, they spun on retries at a full core
@@ -1465,7 +1492,7 @@ class SessionService : Service() {
private const val ACTION_AUXILIARY_EXITED = "com.droiddeck.launcher.AUXILIARY_EXITED"
private const val EXTRA_AUXILIARY_PID = "auxiliaryPid"
/** Command lines that can only belong to a session of ours. */
private val STRAGGLERS = listOf("bannerlator-session", "gamescope", "Xwayland", "steamrtarm64",
private val STRAGGLERS = listOf("droiddeck-session", "gamescope", "Xwayland", "steamrtarm64",
"steamwebhelper", "linuxfs/opt/android-host/proot", "/libproot.so", "pulseaudio/libpulseaudio.so")
/** How long proot gets to run its own cleanup before it is killed outright. */
private const val GRACE_MS = 1200L
@@ -54,8 +54,8 @@ object UserAppsState {
run(context, target.name, R.string.user_apps_removed) { app, progress -> UserApps.remove(app, target, progress) }
}
fun edit(context: Context, target: UserApps.App, name: String, icon: String?) =
run(context, name, R.string.user_apps_saved) { app, _ -> UserApps.edit(app, target, name, icon) }
fun edit(context: Context, target: UserApps.App, name: String, icon: String?, fex: String? = null) =
run(context, name, R.string.user_apps_saved) { app, _ -> UserApps.edit(app, target, name, icon, fex) }
fun checkUpdate(context: Context, target: UserApps.App) {
if (checking != null) return
@@ -91,6 +91,7 @@ import coil.request.ImageRequest
import com.droiddeck.launcher.R
import com.droiddeck.launcher.core.FileUtils
import com.droiddeck.launcher.files.InAppFilePicker
import com.droiddeck.launcher.runtime.LinuxFex
import com.droiddeck.launcher.runtime.UserApps
import com.droiddeck.launcher.store.UserAppsState
import kotlinx.coroutines.Dispatchers
@@ -230,12 +231,14 @@ internal fun AddAppDialog(runtimeReady: Boolean, onDismiss: () -> Unit, onAdd: (
* back to the default, else a picked file or a suggestion.
*/
@Composable
internal fun EditAppDialog(app: UserApps.App, onDismiss: () -> Unit, onSave: (String, String?) -> Unit) {
internal fun EditAppDialog(app: UserApps.App, onDismiss: () -> Unit, onSave: (String, String?, String?) -> Unit) {
val ctx = LocalContext.current
val shown = rememberShown(onDismiss)
val close = { shown.targetState = false }
var name by rememberSaveable(app.key) { mutableStateOf(app.name) }
var icon by rememberSaveable(app.key) { mutableStateOf<String?>(null) }
var fex by rememberSaveable(app.key) { mutableStateOf(app.fex) }
val fexChoice = app.kind != UserApps.Kind.FLATPAK
val pickIcon = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
if (r.resultCode == Activity.RESULT_OK) InAppFilePicker.pickedFile(r.data)?.let { icon = it.path }
}
@@ -245,7 +248,7 @@ internal fun EditAppDialog(app: UserApps.App, onDismiss: () -> Unit, onSave: (St
else -> iconModel(i)
}
val busy = UserAppsState.working
val changed = name.trim() != app.name || icon != null
val changed = name.trim() != app.name || icon != null || fex != app.fex
AppDialog(shown, close, "editApp", wide = false) {
DialogHeader(stringResource(app.kind.label()), stringResource(R.string.edit_app_title, app.name))
Rise(1) {
@@ -260,13 +263,25 @@ internal fun EditAppDialog(app: UserApps.App, onDismiss: () -> Unit, onSave: (St
clear = if (preview == null) null else R.string.add_app_icon_reset to { icon = "" },
)
app.repo?.let { repo -> IconSuggestions(repo, icon) { icon = it } }
if (fexChoice) {
Text(stringResource(R.string.app_fex_title).uppercase(), fontSize = 11.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.2.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
SegmentedTabs(
listOf(
LinuxFex.AUTO to stringResource(R.string.app_fex_auto),
LinuxFex.ON to stringResource(R.string.app_fex_on),
LinuxFex.OFF to stringResource(R.string.app_fex_off),
),
fex,
) { fex = it }
Text(stringResource(R.string.app_fex_hint), fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
}
}
DialogFooter(
busy?.let { stringResource(R.string.add_app_busy, it) },
stringResource(R.string.edit_app_save), name.isNotBlank() && changed && busy == null,
onCancel = close,
) { onSave(name.trim(), icon); close() }
) { onSave(name.trim(), icon, fex.takeIf { fexChoice && it != app.fex }); close() }
}
}
@@ -187,6 +187,14 @@ fun ComponentsPage(
MenuItem(
v.proton.name, checked = v.proton.id == view.proton.id,
detail = (if (swaps > 0) stringResource(R.string.comp_swapped, v.proton.version, swaps) else stringResource(R.string.comp_all_original, v.proton.version))
.let {
when (v.sync?.state) {
"pack" -> stringResource(R.string.comp_esync_pack, it)
"wanted" -> stringResource(R.string.comp_esync_wanted, it)
"builtin" -> stringResource(R.string.comp_esync_builtin, it)
else -> it
}
}
.let { if (v.inUseByGame) stringResource(R.string.comp_game_running_suffix, it) else it },
focusRequester = if (i == 0) first else null,
) { onProton(v.proton.id); protonMenu = false }
@@ -57,6 +57,7 @@ import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.outlined.Apps
import androidx.compose.material.icons.outlined.Terminal
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.produceState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalContext
@@ -575,6 +576,10 @@ private fun UserAppPage(app: UserApps.App, s: FrontEndState, a: FrontEndActions,
val narrow = LocalNarrowPane.current
var confirm by remember(app.key) { mutableStateOf(false) }
var editing by rememberSaveable(app.key) { mutableStateOf(false) }
val x86 = (app.arch == "x86_64" || app.arch == "i386") && app.fex != com.droiddeck.launcher.runtime.LinuxFex.OFF
val fexReady by produceState<Boolean?>(null, app.key, x86, s.sessionRunning) {
value = if (x86) kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { com.droiddeck.launcher.runtime.LinuxFex.ready(ctx) } else true
}
LaunchedEffect(confirm) { if (confirm) { kotlinx.coroutines.delay(4000); confirm = false } }
Rise(0) { BackLink(stringResource(R.string.user_apps_back)) { onSelect("desktop") } }
Rise(1) {
@@ -586,7 +591,8 @@ private fun UserAppPage(app: UserApps.App, s: FrontEndState, a: FrontEndActions,
Column {
Text(app.name, fontSize = if (narrow) 22.sp else 26.sp, fontWeight = FontWeight.Bold, color = colors.onBackground)
Text(
app.repo?.let { stringResource(R.string.user_apps_github_version, it, app.version.orEmpty()) } ?: stringResource(app.kind.label()),
(app.repo?.let { stringResource(R.string.user_apps_github_version, it, app.version.orEmpty()) } ?: stringResource(app.kind.label())) +
(if (app.arch == "x86_64" || app.arch == "i386") " · " + stringResource(R.string.app_fex_x86, app.arch) else ""),
fontSize = 14.sp, color = colors.onSurfaceVariant,
)
}
@@ -609,7 +615,10 @@ private fun UserAppPage(app: UserApps.App, s: FrontEndState, a: FrontEndActions,
}
}
if (UserAppsState.working != null || UserAppsState.lastError != null) Rise(4) { UserAppsProgress() }
if (editing) EditAppDialog(app, onDismiss = { editing = false }) { name, icon -> UserAppsState.edit(ctx, app, name, icon) }
if (fexReady == false) Rise(4) {
Box(Modifier.fillMaxWidth().padding(vertical = 8.dp)) { Note(stringResource(R.string.app_fex_not_ready, app.arch.orEmpty())) }
}
if (editing) EditAppDialog(app, onDismiss = { editing = false }) { name, icon, fex -> UserAppsState.edit(ctx, app, name, icon, fex) }
val detail = app.detail
if (detail != null) Rise(4) {
Box(Modifier.fillMaxWidth().padding(vertical = 8.dp)) {
@@ -73,6 +73,8 @@ class ModeSettings(
/** Steam only: record allocation and sampled storage timings in the next session's Share logs. */
val storageDiagnostics: Boolean = false,
val fexPreset: String? = null,
/** Steam only: SessionPrefs.SYNC_* chosen for Proton games; null outside Steam. */
val syncBackend: String? = null,
/** Steam only: games are stretched to fill the screen (null = not a Steam page). */
val forceFullscreen: Boolean? = null,
val stretch16x9: Boolean? = null,
@@ -134,6 +136,7 @@ class ModeSettingsActions(
val onPickGameStorageFolder: () -> Unit = {},
val onStorageDiagnostics: (Boolean) -> Unit = {},
val onFexPreset: (String) -> Unit = {},
val onSyncBackend: (String) -> Unit = {},
val onForceFullscreen: (Boolean) -> Unit = {},
val onStretch16x9: (Boolean) -> Unit = {},
val onSteamChannel: (String) -> Unit = {},
@@ -404,6 +407,20 @@ fun ModeSettingsPage(s: ModeSettings, a: ModeSettingsActions) {
)
}
if (steam && s.fexPreset != null) SettingsGroup(stringResource(R.string.game_settings_title)) {
if (s.syncBackend != null) SettingsRow(
stringResource(R.string.sync_backend_title),
stringResource(R.string.sync_backend_hint),
) {
SegmentedTabs(
listOf(
SessionPrefs.SYNC_NTSYNC to stringResource(R.string.sync_backend_ntsync),
SessionPrefs.SYNC_FSYNC to stringResource(R.string.sync_backend_fsync),
SessionPrefs.SYNC_ESYNC to stringResource(R.string.sync_backend_esync),
SessionPrefs.SYNC_WINESERVER to stringResource(R.string.sync_backend_wineserver),
),
s.syncBackend,
) { id -> host.open = null; a.onSyncBackend(id) }
}
ChoiceRow(
host, "fex", stringResource(R.string.fex_preset_title), stringResource(R.string.fex_next_launch),
FexPreset.all.map { it.id to stringResource(it.label) }, s.fexPreset,
@@ -39,6 +39,9 @@ fun PerformancePage(
glThread: Boolean,
noGlError: Boolean,
noXalia: Boolean,
fastSync: Boolean,
syncFallback: Boolean,
fsyncFirst: Boolean,
gamescopeRealtime: Boolean,
gpuClockPin: Boolean,
prootNoSeccomp: Boolean,
@@ -51,6 +54,9 @@ fun PerformancePage(
onGlThread: (Boolean) -> Unit,
onNoGlError: (Boolean) -> Unit,
onNoXalia: (Boolean) -> Unit,
onFastSync: (Boolean) -> Unit,
onSyncFallback: (Boolean) -> Unit,
onFsyncFirst: (Boolean) -> Unit,
onGamescopeRealtime: (Boolean) -> Unit,
onGpuClockPin: (Boolean) -> Unit,
onProotNoSeccomp: (Boolean) -> Unit,
@@ -126,6 +132,21 @@ fun PerformancePage(
stringResource(R.string.perf_xalia_hint),
noXalia, onChange = onNoXalia,
)
ToggleRow(
host, "syncfallback", stringResource(R.string.perf_esync),
stringResource(R.string.perf_esync_hint),
syncFallback, onChange = onSyncFallback,
)
ToggleRow(
host, "fsyncfirst", stringResource(R.string.perf_fsync),
stringResource(R.string.perf_fsync_hint),
fsyncFirst, onChange = onFsyncFirst,
)
ToggleRow(
host, "fastsync", stringResource(R.string.perf_fastsync),
stringResource(R.string.perf_fastsync_hint),
fastSync, onChange = onFastSync,
)
ToggleRow(
host, "seccomp", stringResource(R.string.perf_seccomp),
stringResource(R.string.perf_seccomp_hint),
@@ -48,12 +48,17 @@ fun ProtonPage(
stringResource(R.string.proton_stop_first),
fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 8.dp, bottom = 6.dp),
)
val compatible = stringResource(R.string.steam_compat_label)
Text(
stringResource(R.string.proton_compatible_note, compatible),
fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 8.dp, bottom = 6.dp),
)
SettingsGroup(stringResource(R.string.proton_available)) {
for (row in rows) {
SettingsRow(
row.name,
when {
row.installed != null -> stringResource(R.string.proton_installed, row.installed)
row.installed != null -> stringResource(R.string.proton_installed_compatible, row.installed, compatible)
row.queued -> stringResource(R.string.proton_queued)
else -> stringResource(R.string.proton_not_installed)
},
@@ -8,6 +8,11 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.offset
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.selected
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
@@ -33,6 +38,7 @@ import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
@@ -661,3 +667,62 @@ fun SettingsPage(
}
}
}
/**
* A short row of tabs with one chosen: a pill in the signal blue slides under the choice and its
* label turns to sit on it. Left and right move between tabs; a tap or A picks one. [selected]
* null leaves no tab chosen.
*/
@Composable
fun <T> SegmentedTabs(options: List<Pair<T, String>>, selected: T?, modifier: Modifier = Modifier, onPick: (T) -> Unit) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val index = options.indexOfFirst { it.first == selected }
val shape = RoundedCornerShape(12.dp)
val pillShape = RoundedCornerShape(9.dp)
BoxWithConstraints(modifier) {
val segment = minOf(92.dp, (maxWidth - 8.dp) / options.size)
val slide by animateDpAsState(segment * index.coerceAtLeast(0), Motion.sp(0.75f), label = "tabPill")
val shown by animateFloatAsState(if (index >= 0) 1f else 0f, Motion.tw(180), label = "tabPillShown")
Box(
modifier = Modifier
.height(48.dp).width(segment * options.size + 8.dp)
.clip(shape).background(colors.surfaceVariant).border(1.dp, pal.line2, shape)
.padding(4.dp),
) {
Box(
Modifier.offset(x = slide).width(segment).fillMaxHeight()
.graphicsLayer { alpha = shown }
.clip(pillShape).background(pal.signal),
)
Row {
options.forEachIndexed { i, (value, label) ->
val src = remember { MutableInteractionSource() }
val hot = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value
val chosen = i == index
val ink by animateColorAsState(
when {
chosen -> pal.onSignal
hot -> colors.onBackground
else -> colors.onSurfaceVariant
},
Motion.tw(220), label = "tabInk",
)
val pick = { onPick(value) }
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.width(segment).fillMaxHeight()
.clip(pillShape)
.glideBorder(hot, pillShape, if (chosen) pal.onSignal else pal.signal)
.semantics { role = Role.Tab; this.selected = chosen }
.hoverable(src)
.clickable(interactionSource = src, indication = LocalIndication.current, onClick = pick)
.controllerConfirm(onClick = pick),
) {
Text(label, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = ink, maxLines = 1, softWrap = false)
}
}
}
}
}
}
@@ -7,7 +7,7 @@ import android.view.WindowManager
/**
* What the panel says about HDR, read from android.view.Display: the gate the compositor's HDR10
* output sits behind (banner_color.h). A property of the display, not the device - and the
* output sits behind (droiddeck_color.h). A property of the display, not the device - and the
* settings screen greys the HDR switch out with the reason when it is not there, rather than
* offering a switch that a session would then silently ignore.
*/
@@ -13,7 +13,7 @@ import android.view.Surface;
*/
public final class WaylandCompositor {
static {
System.loadLibrary("bannerwayland");
System.loadLibrary("droiddeckwayland");
}
private WaylandCompositor() {}
@@ -30,7 +30,7 @@ public final class WaylandCompositor {
if (firstFrameListener == r) firstFrameListener = null;
}
/** Invoked from native (banner_on_first_frame) on the first present. */
/** Invoked from native (droiddeck_on_first_frame) on the first present. */
@SuppressWarnings("unused")
static void onFirstFramePresented() {
Runnable r = firstFrameListener;
@@ -60,7 +60,7 @@ public final class WaylandCompositor {
if (gameListener == l) gameListener = null;
}
/** Invoked from native (banner_on_game_surface). */
/** Invoked from native (droiddeck_on_game_surface). */
@SuppressWarnings("unused")
static void onGameSurface(String window, String gpuName) {
GameListener l = gameListener;
@@ -80,7 +80,7 @@ public final class WaylandCompositor {
return Math.max(frameIntervalNanos, System.nanoTime() - last) / 1_000_000;
}
/** Invoked from native (banner_on_game_frame) for every frame of the HUD's window. */
/** Invoked from native (droiddeck_on_game_frame) for every frame of the HUD's window. */
@SuppressWarnings("unused")
static void onGameFrame() {
long now = System.nanoTime();
@@ -95,7 +95,7 @@ public final class WaylandCompositor {
if (l != null) l.onGameFrame();
}
/** Invoked from native (banner_on_game_program) once per game window that starts presenting. */
/** Invoked from native (droiddeck_on_game_program) once per game window that starts presenting. */
@SuppressWarnings("unused")
static void onGameProgram(int pid, String program) {
GameListener l = gameListener;
@@ -115,7 +115,7 @@ public final class WaylandCompositor {
public static void setPointerLockListener(PointerLockListener l) { pointerLockListener = l; }
/** Invoked from native (banner_on_pointer_lock). */
/** Invoked from native (droiddeck_on_pointer_lock). */
@SuppressWarnings("unused")
static void onPointerLock(boolean locked, int x, int y) {
PointerLockListener l = pointerLockListener;
@@ -139,7 +139,7 @@ public final class WaylandCompositor {
if (clipboardListener == l) clipboardListener = null;
}
/** Invoked from native (banner_on_clipboard_text) with UTF-8 bytes. */
/** Invoked from native (droiddeck_on_clipboard_text) with UTF-8 bytes. */
@SuppressWarnings("unused")
static void onClipboardText(byte[] utf8) {
ClipboardListener l = clipboardListener;
@@ -158,7 +158,7 @@ public final class WaylandCompositor {
public static void setTextInputListener(TextInputListener l) { textInputListener = l; }
/** Invoked from native (banner_on_text_input). */
/** Invoked from native (droiddeck_on_text_input). */
@SuppressWarnings("unused")
static void onTextInput(boolean enabled, String program, int x, int y, int w, int h) {
TextInputListener l = textInputListener;
@@ -240,7 +240,7 @@ public final class WaylandCompositor {
public static native void nativeSetOutputRefreshRate(float hz);
/** Show a single fullscreen window on its own Android layer (SurfaceControl) instead of blitting
* it into the compositor's swapchain. BANNER_WAYLAND_ZERO_COPY=1 in the container's environment
* it into the compositor's swapchain. DROIDDECK_WAYLAND_ZERO_COPY=1 in the container's environment
* variables is the launch default; see waylandcomp/ZERO_COPY_SPIKE.md.
*
* Live and thread-safe: before the compositor starts this is the initial state, and afterwards
@@ -264,12 +264,12 @@ public final class WaylandCompositor {
/** Compressed (UBWC) game buffers: the compositor advertises DRM_FORMAT_MOD_QCOM_COMPRESSED next to
* LINEAR on zwp_linux_dmabuf_v1 for every format its driver can import that way, so the game's
* Turnip allocates compressed swapchain images instead of resolving every frame to a linear copy.
* Default on; BANNER_WAYLAND_UBWC=0 in the container's environment variables turns it off (A/B).
* Default on; DROIDDECK_WAYLAND_UBWC=0 in the container's environment variables turns it off (A/B).
* Set before the compositor starts. */
public static native void nativeSetUbwc(boolean on);
/** Debug: advertise no DRM device (main device 0:0) in the dma-buf feedback, as a phone that
* exposes no /dev/dri node to apps does. BANNER_WAYLAND_NO_RENDER_NODE=1 in the container's or
* exposes no /dev/dri node to apps does. DROIDDECK_WAYLAND_NO_RENDER_NODE=1 in the container's or
* shortcut's environment variables. Set before the compositor starts. */
public static native void nativeSetNoRenderNode(boolean on);
@@ -311,13 +311,13 @@ public final class WaylandCompositor {
* already presented a previous one. */
public static native void nativeResetFirstFrame();
// ── HDR10 output, round 1 (waylandcomp/src/banner_color.h, wl_color_mgmt.c) ─────────────────
// Opt-in: BANNER_WAYLAND_HDR=1 in the container's or shortcut's env vars. The compositor offers
// ── HDR10 output, round 1 (waylandcomp/src/droiddeck_color.h, wl_color_mgmt.c) ─────────────────
// Opt-in: DROIDDECK_WAYLAND_HDR=1 in the container's or shortcut's env vars. The compositor offers
// games HDR10 (wp_color_manager_v1 + 10-bit buffers, frames tagged BT2020_PQ on the game's own
// display layer) only when the game's display lists HDR10 as well; otherwise nothing changes and
// the session log says why. Not the drawer's "HDR" effect, which is an SDR bloom/contrast filter.
/** HDR_MODE_OFF / HDR_MODE_ON (BANNER_WAYLAND_HDR=1) / HDR_MODE_FORCE (=force: skip the display
/** HDR_MODE_OFF / HDR_MODE_ON (DROIDDECK_WAYLAND_HDR=1) / HDR_MODE_FORCE (=force: skip the display
* check, for testing the negotiation on an SDR panel). */
public static final int HDR_MODE_OFF = 0, HDR_MODE_ON = 1, HDR_MODE_FORCE = 2;