mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +00:00
fix(install): recheck cancellation after sha256 and wire package resume cancel
This commit is contained in:
commit
1b5cd6add9
399 files changed
+28516
-1432
No files matched your search
@@ -56,8 +56,9 @@ class BatteryComponent(val dir: File, private val vpowerDir: File) : SessionPart
|
||||
val timeToEmptyS = if (discharging && chargeNowUah > 0 && abs(currentAvgUa) > 0) chargeNowUah * 3600L / abs(currentAvgUa) else 0L
|
||||
val charging = status == BatteryManager.BATTERY_STATUS_CHARGING
|
||||
val timeToFullS = if (charging && chargeFullUah > chargeNowUah && abs(currentAvgUa) > 0) (chargeFullUah - chargeNowUah) * 3600L / abs(currentAvgUa) else 0L
|
||||
// Android can keep reporting charging at 100%; Linux reports Full there, and Steam shows 99% until it does.
|
||||
val statusText = when (status) {
|
||||
BatteryManager.BATTERY_STATUS_CHARGING -> "Charging"
|
||||
BatteryManager.BATTERY_STATUS_CHARGING -> if (pct >= 100) "Full" else "Charging"
|
||||
BatteryManager.BATTERY_STATUS_DISCHARGING -> "Discharging"
|
||||
BatteryManager.BATTERY_STATUS_FULL -> "Full"
|
||||
BatteryManager.BATTERY_STATUS_NOT_CHARGING -> "Not charging"
|
||||
|
||||
@@ -155,8 +155,7 @@ object ComponentsManager {
|
||||
if (staged.exists()) check(staged.delete()) { "Could not remove unpublished component selections" }
|
||||
}
|
||||
|
||||
private fun saveState(context: Context, state: JSONObject) {
|
||||
val prepared = prepareLaunchState(context, state)
|
||||
private fun saveState(context: Context, state: JSONObject, prepared: PreparedLaunchState = prepareLaunchState(context, state)) {
|
||||
val dir = launchDir(context)
|
||||
val tmp = File(dir, "desired.tsv.tmp")
|
||||
try {
|
||||
@@ -175,6 +174,17 @@ object ComponentsManager {
|
||||
?.forEach { it.deleteRecursively() }
|
||||
}
|
||||
|
||||
fun republish(context: Context): Boolean = synchronized(lock) {
|
||||
recoverState(context)
|
||||
val saved = stateFile(context)
|
||||
if (saved.exists() && runCatching { JSONObject(saved.readText()) }.isFailure) return false
|
||||
val state = loadState(context)
|
||||
val prepared = prepareLaunchState(context, state)
|
||||
if ((FileUtils.readString(File(launchDir(context), "desired.tsv")) ?: "") == prepared.text) return false
|
||||
saveState(context, state, prepared)
|
||||
true
|
||||
}
|
||||
|
||||
private fun JSONObject.sub(key: String): JSONObject = optJSONObject(key) ?: JSONObject().also { put(key, it) }
|
||||
|
||||
private fun rememberProfiledComponent(state: JSONObject, comp: String) {
|
||||
@@ -780,6 +790,64 @@ object ComponentsManager {
|
||||
true
|
||||
}
|
||||
|
||||
private fun checkPackageUnused(context: Context, state: JSONObject, name: String) {
|
||||
val installed = protons(context).distinctBy { it.id }.associateBy { it.id }
|
||||
for (key in listOf("queued", "active")) {
|
||||
val byProton = state.sub(key)
|
||||
for (pid in byProton.keys()) {
|
||||
val comps = byProton.optJSONObject(pid) ?: continue
|
||||
for (comp in comps.keys()) {
|
||||
val entry = comps.optJSONObject(comp) ?: continue
|
||||
check(entry.optString("file") != name || !liveSelection(key, entry, installed[pid])) {
|
||||
context.getString(R.string.cmgr_package_in_use, name, installed[pid]?.name ?: pid)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val profiles = state.sub("profiles")
|
||||
for (scope in profiles.keys()) {
|
||||
val profile = profiles.optJSONObject(scope) ?: continue
|
||||
check(COMPONENTS.none { profile.optString(it) == name }) { context.getString(R.string.cmgr_package_in_use, name, scope) }
|
||||
}
|
||||
}
|
||||
|
||||
fun carryOver(context: Context, fromDir: String, toDir: String) {
|
||||
synchronized(lock) {
|
||||
val target = protons(context).firstOrNull { it.id == safeName(toDir) } ?: return
|
||||
val state = loadState(context)
|
||||
val wanted = carried(state, safeName(fromDir)) { File(packagesDir(context), it).isFile }
|
||||
val active = state.sub("active").optJSONObject(target.id)
|
||||
val queued = state.sub("queued").sub(target.id)
|
||||
var changed = false
|
||||
wanted.forEach { (comp, entry) ->
|
||||
if (active?.has(comp) != true && !queued.has(comp)) {
|
||||
queued.put(comp, entry)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if (queued.length() == 0) state.sub("queued").remove(target.id)
|
||||
if (changed) saveState(context, state)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun carried(state: JSONObject, from: String, present: (String) -> Boolean): Map<String, JSONObject> = buildMap {
|
||||
state.optJSONObject("active")?.optJSONObject(from)?.let { active ->
|
||||
active.keys().forEach { comp ->
|
||||
val entry = active.optJSONObject(comp) ?: return@forEach
|
||||
val file = entry.optString("file")
|
||||
if (comp in COMPONENTS && file.endsWith(".wcp") && present(file)) {
|
||||
put(comp, JSONObject().put("kind", "package").put("file", file).put("label", entry.optString("label")))
|
||||
}
|
||||
}
|
||||
}
|
||||
state.optJSONObject("queued")?.optJSONObject(from)?.let { queued ->
|
||||
queued.keys().forEach { comp ->
|
||||
val entry = queued.optJSONObject(comp) ?: return@forEach
|
||||
if (comp in COMPONENTS && entry.optString("kind") == "package" && present(entry.optString("file"))) put(comp, entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun forgetProton(context: Context, dirName: String) {
|
||||
synchronized(lock) {
|
||||
val id = safeName(dirName)
|
||||
@@ -791,6 +859,33 @@ object ComponentsManager {
|
||||
}
|
||||
}
|
||||
|
||||
private fun storePackage(context: Context, part: File, dest: File) {
|
||||
try {
|
||||
if (dest.isFile && runCatching { Hashes.sha256(dest) }.getOrNull()?.equals(Hashes.sha256(part), true) == true) return
|
||||
if (dest.exists()) checkPackageUnused(context, loadState(context), dest.name)
|
||||
val store = File(launchDir(context), "store").canonicalFile
|
||||
val cacheKey = unpackedCacheKey(dest.name)
|
||||
val unpacked = File(store, cacheKey).canonicalFile
|
||||
check(unpacked.parentFile == store) { "Invalid unpacked component cache path for ${dest.name}" }
|
||||
val complete = File(unpacked, ".complete")
|
||||
if (complete.exists()) check(complete.delete()) { "Could not invalidate unpacked component ${dest.name}" }
|
||||
if (!part.renameTo(dest)) {
|
||||
dest.delete()
|
||||
check(part.renameTo(dest)) { "Could not store ${dest.name}" }
|
||||
}
|
||||
if (!unpacked.deleteRecursively() && unpacked.exists()) {
|
||||
check(!complete.exists()) { "Could not invalidate unpacked component ${dest.name}" }
|
||||
Log.w(TAG, "Could not remove stale unpacked files for ${dest.name}; cache marker is invalidated")
|
||||
}
|
||||
} finally {
|
||||
part.delete()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun unpackedCacheKey(filename: String): String = safeName(filename.removeSuffix(".wcp")).also {
|
||||
require(it != "." && it != "..") { "Invalid component cache name" }
|
||||
}
|
||||
|
||||
fun deletePackage(context: Context, file: String): String = synchronized(lock) {
|
||||
val name = safeName(file)
|
||||
val state = loadState(context)
|
||||
@@ -840,7 +935,7 @@ object ComponentsManager {
|
||||
fun importPackage(context: Context, source: File, name: String): Package = synchronized(lock) {
|
||||
val info = packageInfo(context, source)
|
||||
val dest = File(packagesDir(context), safeName(name).let { if (it.endsWith(".wcp")) it else "$it.wcp" })
|
||||
source.copyTo(File(dest.parentFile, dest.name + ".part"), overwrite = true).renameTo(dest)
|
||||
storePackage(context, source.copyTo(File(dest.parentFile, dest.name + ".part"), overwrite = true), dest)
|
||||
info.copy(file = dest.name)
|
||||
}
|
||||
|
||||
@@ -863,6 +958,7 @@ object ComponentsManager {
|
||||
.put("url", a.optString("browser_download_url")).put("size", a.optLong("size")).put("digest", a.optString("digest")))
|
||||
}
|
||||
}
|
||||
if (items.length() == 0 && cache.isFile) runCatching { return parseCatalog(JSONObject(cache.readText())) }
|
||||
val out = JSONObject().put("items", items).put("fetchedAt", System.currentTimeMillis() / 1000)
|
||||
val tmp = File(cache.parentFile, cache.name + ".tmp")
|
||||
tmp.writeText(out.toString()); tmp.renameTo(cache)
|
||||
@@ -992,7 +1088,7 @@ object ComponentsManager {
|
||||
}
|
||||
if (!Hashes.sha256(part).equals(item.digest.substringAfter(':'), true)) { part.delete(); error(context.getString(R.string.cmgr_checksum_mismatch)) }
|
||||
val info = runCatching { packageInfo(context, part) }.getOrElse { part.delete(); throw it }
|
||||
synchronized(lock) { part.renameTo(dest) }
|
||||
synchronized(lock) { storePackage(context, part, dest) }
|
||||
return info.copy(file = dest.name)
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* The FEX build DroidDeck-Components' fex.json names for the x86-64 client. A session uses the last copy read.
|
||||
* The FEX build DroidDeck-Components' fex.json names for x86 programs. A session uses the last copy read.
|
||||
* Components' build-fex.yml replaces the archive on its single `fex` release and records the build's version;
|
||||
* a release per build (fex-2610-r5) is still read.
|
||||
*/
|
||||
@@ -62,7 +62,7 @@ object FexCatalog {
|
||||
return build
|
||||
}
|
||||
|
||||
/** For droiddeck-steam-x64: the build and every source its archive may come from (it checks the sha256). */
|
||||
/** For droiddeck-fex-update: the build and every source its archive may come from (it checks the sha256). */
|
||||
fun environment(build: Build, sources: List<String> = DownloadSource.candidates(build.url)): List<String> = listOf(
|
||||
"BL_FEX_TAG=${build.tag}",
|
||||
"BL_FEX_SHA256=${build.sha256}",
|
||||
|
||||
@@ -78,6 +78,14 @@ object GameEnvironmentStore {
|
||||
return config
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun setDefault(context: Context, scope: String, name: String, value: String): Boolean {
|
||||
val config = read(context)
|
||||
if (GameEnvironment.hasOverride(config, scope, name)) return false
|
||||
save(context, GameEnvironment.withScopeValue(config, scope, name, value))
|
||||
return true
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun publish(context: Context, config: GameEnvironment.Config = read(context)) {
|
||||
val resolved = config.copy(shared = GameEnvironment.defaults(SessionPrefs.fexPreset(context), SessionPrefs.forceSsbs(context)) + config.shared)
|
||||
|
||||
@@ -14,9 +14,12 @@ object GameStorage {
|
||||
|
||||
fun options(context: Context): List<Option> {
|
||||
val sm = context.getSystemService(StorageManager::class.java)
|
||||
val primary = context.getExternalFilesDir(null)?.absolutePath
|
||||
val primaryStorage = Environment.getExternalStorageDirectory()?.absolutePath
|
||||
return context.getExternalFilesDirs(null).orEmpty().filterNotNull().mapNotNull { dir ->
|
||||
val removable = try { Environment.isExternalStorageRemovable(dir) } catch (e: Exception) { false }
|
||||
if (!removable) return@mapNotNull null
|
||||
// Non-primary app dirs are usable even when Android reports the volume as non-removable (USB SSDs often do).
|
||||
if (primary != null && dir.absolutePath == primary) return@mapNotNull null
|
||||
if (!primaryStorage.isNullOrBlank() && dir.absolutePath.startsWith("$primaryStorage/")) return@mapNotNull null
|
||||
val volume = try { sm?.getStorageVolume(dir) } catch (e: Exception) { null }
|
||||
val name = volume?.getDescription(context)?.takeIf { it.isNotBlank() && !it.equals("android", true) } ?: context.getString(R.string.gstore_sd_card)
|
||||
Option(context.getString(R.string.gstore_volume_free, name, free(dir)), File(dir, "steam").absolutePath, name)
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import com.droiddeck.launcher.R
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
|
||||
internal object MemoryReadout {
|
||||
data class Device(val totalKb: Long, val availableKb: Long, val swapTotalKb: Long, val swapFreeKb: Long) {
|
||||
val usedKb get() = (totalKb - availableKb).coerceAtLeast(0)
|
||||
val swapUsedKb get() = (swapTotalKb - swapFreeKb).coerceAtLeast(0)
|
||||
}
|
||||
|
||||
data class Split(val gameKb: Long, val droiddeckKb: Long, val gpuKb: Long?)
|
||||
|
||||
fun parseMeminfo(text: String): Device? {
|
||||
fun field(name: String) = Regex("""(?m)^$name:\s+(\d+) kB""").find(text)?.groupValues?.get(1)?.toLongOrNull()
|
||||
val total = field("MemTotal") ?: return null
|
||||
val available = field("MemAvailable") ?: return null
|
||||
return Device(total, available, field("SwapTotal") ?: 0, field("SwapFree") ?: 0)
|
||||
}
|
||||
|
||||
fun residentKb(status: String): Long {
|
||||
fun field(name: String) = Regex("""(?m)^$name:\s+(\d+) kB""").find(status)?.groupValues?.get(1)?.toLongOrNull() ?: 0
|
||||
return field("RssAnon") + field("RssShmem")
|
||||
}
|
||||
|
||||
fun inWinePrefix(environ: ByteArray): Boolean {
|
||||
var start = 0
|
||||
val key = "WINEPREFIX=".toByteArray()
|
||||
for (i in 0..environ.size) {
|
||||
if (i == environ.size || environ[i] == 0.toByte()) {
|
||||
if (i - start >= key.size && (key.indices).all { environ[start + it] == key[it] }) return true
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun androidKb(device: Device, split: Split): Long =
|
||||
(device.usedKb - split.gameKb - split.droiddeckKb - (split.gpuKb ?: 0)).coerceAtLeast(0)
|
||||
|
||||
fun gb(kb: Long): String = String.format(Locale.US, "%.1f", kb / (1024.0 * 1024.0))
|
||||
|
||||
fun availableMb(): Long? = runCatching { parseMeminfo(File("/proc/meminfo").readText())?.availableKb?.div(1024) }.getOrNull()
|
||||
|
||||
fun device(): Device? = runCatching { parseMeminfo(File("/proc/meminfo").readText()) }.getOrNull()
|
||||
|
||||
fun split(root: Int = android.os.Process.myPid()): Split {
|
||||
val parents = HashMap<Int, Int>()
|
||||
File("/proc").listFiles()?.forEach { entry ->
|
||||
val pid = entry.name.toIntOrNull() ?: return@forEach
|
||||
parentOf(pid)?.let { parents[pid] = it }
|
||||
}
|
||||
val children = parents.entries.groupBy({ it.value }, { it.key })
|
||||
var game = 0L
|
||||
var droiddeck = 0L
|
||||
val queue = ArrayDeque<Int>().apply { add(root) }
|
||||
val seen = HashSet<Int>()
|
||||
while (queue.isNotEmpty()) {
|
||||
val pid = queue.removeFirst()
|
||||
if (!seen.add(pid)) continue
|
||||
val status = runCatching { File("/proc/$pid/status").readText() }.getOrNull()
|
||||
if (status != null) {
|
||||
val kb = residentKb(status)
|
||||
val windows = pid != root && runCatching { inWinePrefix(File("/proc/$pid/environ").readBytes()) }.getOrDefault(false)
|
||||
if (windows) game += kb else droiddeck += kb
|
||||
}
|
||||
children[pid]?.let(queue::addAll)
|
||||
}
|
||||
return Split(game, droiddeck, gpuKb())
|
||||
}
|
||||
|
||||
private fun parentOf(pid: Int): Int? {
|
||||
val stat = runCatching { File("/proc/$pid/stat").readText() }.getOrNull() ?: return null
|
||||
val close = stat.lastIndexOf(')')
|
||||
if (close < 0 || close + 2 >= stat.length) return null
|
||||
return stat.substring(close + 2).split(' ').getOrNull(1)?.toIntOrNull()
|
||||
}
|
||||
|
||||
private fun gpuKb(): Long? = runCatching {
|
||||
File("/sys/class/kgsl/kgsl/page_alloc").readText().trim().split(Regex("\\s+"))[0].toLong() / 1024
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
object MemoryLog {
|
||||
private const val TAG = "Memory"
|
||||
private const val PERIOD_MS = 10_000L
|
||||
@Volatile private var thread: Thread? = null
|
||||
|
||||
internal fun line(device: MemoryReadout.Device, split: MemoryReadout.Split): String =
|
||||
"used ${device.usedKb / 1024}/${device.totalKb / 1024} MB, available ${device.availableKb / 1024} MB, " +
|
||||
"swap ${device.swapUsedKb / 1024}/${device.swapTotalKb / 1024} MB | game ${split.gameKb / 1024}, " +
|
||||
"droiddeck ${split.droiddeckKb / 1024}, android ${MemoryReadout.androidKb(device, split) / 1024}, " +
|
||||
"gpu ${split.gpuKb?.div(1024) ?: "?"} MB"
|
||||
|
||||
@Synchronized
|
||||
fun start() {
|
||||
if (thread != null) return
|
||||
thread = Thread({
|
||||
while (!Thread.currentThread().isInterrupted) {
|
||||
runCatching { MemoryReadout.device()?.let { android.util.Log.i(TAG, line(it, MemoryReadout.split())) } }
|
||||
try { Thread.sleep(PERIOD_MS) } catch (e: InterruptedException) { break }
|
||||
}
|
||||
}, "memory-log").apply { isDaemon = true; start() }
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun stop() {
|
||||
thread?.interrupt()
|
||||
thread = null
|
||||
}
|
||||
}
|
||||
|
||||
class MemoryHud(context: Context) {
|
||||
var text by mutableStateOf("")
|
||||
private set
|
||||
|
||||
private val context = context.applicationContext
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
@Volatile private var running = false
|
||||
@Volatile private var generation = 0
|
||||
private var thread: Thread? = null
|
||||
|
||||
fun refresh() {
|
||||
if (SessionPrefs.memoryHud(context) == SessionPrefs.MEMORY_HUD_OFF) stop() else start()
|
||||
}
|
||||
|
||||
fun start() {
|
||||
if (running || SessionPrefs.memoryHud(context) == SessionPrefs.MEMORY_HUD_OFF) return
|
||||
running = true
|
||||
val token = ++generation
|
||||
thread = Thread({
|
||||
while (running && generation == token) {
|
||||
val line = runCatching { sample() }.getOrDefault("")
|
||||
handler.post { if (running && generation == token) text = line }
|
||||
try { Thread.sleep(PERIOD_MS) } catch (e: InterruptedException) { break }
|
||||
}
|
||||
}, "memory-hud").apply { isDaemon = true; start() }
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
running = false
|
||||
generation++
|
||||
thread?.interrupt()
|
||||
thread = null
|
||||
text = ""
|
||||
}
|
||||
|
||||
private fun sample(): String {
|
||||
val device = MemoryReadout.device() ?: return ""
|
||||
val memory = context.getString(
|
||||
R.string.memory_hud_simple,
|
||||
MemoryReadout.gb(device.usedKb), MemoryReadout.gb(device.totalKb),
|
||||
MemoryReadout.gb(device.swapUsedKb), MemoryReadout.gb(device.swapTotalKb),
|
||||
)
|
||||
if (SessionPrefs.memoryHud(context) != SessionPrefs.MEMORY_HUD_ADVANCED) return memory
|
||||
val split = MemoryReadout.split()
|
||||
val parts = context.getString(
|
||||
R.string.memory_hud_split,
|
||||
MemoryReadout.gb(split.gameKb), MemoryReadout.gb(split.droiddeckKb), MemoryReadout.gb(MemoryReadout.androidKb(device, split)),
|
||||
)
|
||||
val gpu = split.gpuKb?.let { context.getString(R.string.memory_hud_gpu, MemoryReadout.gb(it)) }
|
||||
return listOfNotNull(memory, parts, gpu).joinToString("\n")
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val PERIOD_MS = 2000L
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,13 @@ import com.droiddeck.launcher.stores.epic.EpicClient
|
||||
object NoSteamLaunch {
|
||||
const val PROTON_RUN = "/usr/local/bin/droiddeck-proton-run"
|
||||
const val EPIC = "/usr/local/bin/droiddeck-epic"
|
||||
const val BATTLENET = com.droiddeck.launcher.runtime.BattleNet.PROGRAM
|
||||
|
||||
class Command(val program: String, val args: List<String>, val name: String)
|
||||
|
||||
fun scope(game: Library.SteamGame): String? = when {
|
||||
game.library == Library.EPIC_LAUNCHER -> EpicClient.shortcutAppId.toString()
|
||||
game.library == Library.BATTLENET_LAUNCHER -> com.droiddeck.launcher.runtime.BattleNet.APP_ID.toString()
|
||||
game.library == Library.ADDED || game.appId > 0 -> game.profileKey
|
||||
else -> null
|
||||
}?.takeIf { it.isNotEmpty() && GameEnvironment.validScope(it) }
|
||||
@@ -30,6 +32,8 @@ object NoSteamLaunch {
|
||||
|
||||
fun command(game: Library.SteamGame, added: AddedGames.Game?): Command? = when {
|
||||
game.library == Library.EPIC_LAUNCHER -> Command(EPIC, listOf("run"), game.name)
|
||||
game.library == Library.ADDED && game.source == com.droiddeck.launcher.stores.Store.BATTLENET.id ->
|
||||
game.storeId?.let(com.droiddeck.launcher.runtime.BattleNet::title)?.let { Command(BATTLENET, listOf("launch", it.code), game.name) }
|
||||
game.library == Library.ADDED -> added?.let { a -> a.steamAppId?.let { Command(PROTON_RUN, listOf("--app", it.toString()), a.name) } ?: addedCommand(a) }
|
||||
game.appId > 0 -> Command(PROTON_RUN, listOf("--app", game.appId.toString()), game.name)
|
||||
else -> null
|
||||
@@ -37,7 +41,9 @@ object NoSteamLaunch {
|
||||
|
||||
fun addedCommand(game: AddedGames.Game): Command = Command(
|
||||
PROTON_RUN,
|
||||
listOf("--app", (game.appId and 0xFFFFFFFFL).toString(), "--dir", game.guestDir, "--options", game.launchOptions, "--", game.guestExe),
|
||||
listOf("--app", (game.appId and 0xFFFFFFFFL).toString(), "--dir", game.guestDir) +
|
||||
(if (game.launchOptions.isEmpty()) emptyList() else listOf("--options", game.launchOptions)) +
|
||||
listOf("--", game.guestExe),
|
||||
game.name,
|
||||
)
|
||||
|
||||
@@ -45,11 +51,13 @@ object NoSteamLaunch {
|
||||
|
||||
fun addedGame(context: Context, game: Library.SteamGame): AddedGames.Game? {
|
||||
val id = game.appId.toLong() and 0xFFFFFFFFL
|
||||
return AddedGames.scan(context).firstOrNull { settingsId(it) == id }
|
||||
val one = game.gameFiles?.let { AddedGames.single(context, it.path) }
|
||||
return one?.takeIf { settingsId(it) == id } ?: AddedGames.scan(context).firstOrNull { settingsId(it) == id }
|
||||
}
|
||||
|
||||
fun nameFor(program: String?, args: List<String>): String? = when (program) {
|
||||
EPIC -> Library.EPIC_LAUNCHER_NAME
|
||||
BATTLENET -> args.getOrNull(args.indexOf("launch") + 1)?.takeIf { args.contains("launch") }?.let { names[it] } ?: com.droiddeck.launcher.stores.Store.BATTLENET.label
|
||||
PROTON_RUN -> args.getOrNull(args.indexOf("--app") + 1)?.takeIf { args.contains("--app") }?.let { names[it] }
|
||||
else -> null
|
||||
}
|
||||
@@ -58,5 +66,6 @@ object NoSteamLaunch {
|
||||
|
||||
fun remember(command: Command) {
|
||||
if (command.program == PROTON_RUN) command.args.getOrNull(command.args.indexOf("--app") + 1)?.let { names[it] = command.name }
|
||||
if (command.program == BATTLENET) command.args.getOrNull(command.args.indexOf("launch") + 1)?.takeIf { command.args.contains("launch") }?.let { names[it] = command.name }
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import com.droiddeck.launcher.wayland.WaylandCompositor
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
|
||||
class PerfHud(context: Context) {
|
||||
var text by mutableStateOf("")
|
||||
@@ -32,9 +31,9 @@ class PerfHud(context: Context) {
|
||||
private var lastFps = 0f
|
||||
private var running = false
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val intervals = FloatArray(GRAPH)
|
||||
private val graphWrite = AtomicInteger()
|
||||
private val lastFrameNs = AtomicLong()
|
||||
private val samples = FloatArray(GRAPH)
|
||||
private var graphBase = 0L
|
||||
private var graphSeen = 0L
|
||||
|
||||
@Volatile private var showFps = true
|
||||
@Volatile private var showBattery = true
|
||||
@@ -59,14 +58,6 @@ class PerfHud(context: Context) {
|
||||
}
|
||||
override fun onGameFrame() {
|
||||
frames.incrementAndGet()
|
||||
if (!showGraph) return
|
||||
val now = System.nanoTime()
|
||||
val previous = lastFrameNs.getAndSet(now)
|
||||
if (previous == 0L) return
|
||||
val ms = ((now - previous) / 1_000_000f).coerceIn(0f, 50f)
|
||||
val slot = graphWrite.get()
|
||||
intervals[slot and (GRAPH - 1)] = ms
|
||||
graphWrite.compareAndSet(slot, slot + 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,9 +91,9 @@ class PerfHud(context: Context) {
|
||||
if (!enabled || !anyPart || running) return
|
||||
running = true
|
||||
lastTick = SystemClock.elapsedRealtime()
|
||||
lastFrameNs.set(0L)
|
||||
frames.set(0)
|
||||
graphWrite.set(0)
|
||||
graphBase = shownTotal()
|
||||
graphSeen = graphBase
|
||||
WaylandCompositor.setGameListener(listener)
|
||||
handler.postDelayed(tick, TICK_MS)
|
||||
}
|
||||
@@ -135,23 +126,19 @@ class PerfHud(context: Context) {
|
||||
return sticky.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0)
|
||||
}
|
||||
|
||||
private fun shownTotal(): Long = try { WaylandCompositor.nativeHudFrameTimes(samples) } catch (t: Throwable) { 0L }
|
||||
|
||||
private fun clearGraph() {
|
||||
lastFrameNs.set(0L)
|
||||
graphWrite.set(0)
|
||||
graphBase = shownTotal()
|
||||
graphSeen = graphBase
|
||||
if (graph.isNotEmpty()) graph = FloatArray(0)
|
||||
}
|
||||
|
||||
private fun publishGraph() {
|
||||
val count = graphWrite.get()
|
||||
val shown = minOf(count, GRAPH)
|
||||
if (shown < 2) {
|
||||
graph = FloatArray(0)
|
||||
return
|
||||
}
|
||||
val out = FloatArray(shown)
|
||||
val start = count - shown
|
||||
for (i in 0 until shown) out[i] = intervals[(start + i) and (GRAPH - 1)]
|
||||
graph = out
|
||||
val total = shownTotal()
|
||||
if (total == graphSeen && graph.isNotEmpty()) return
|
||||
graphSeen = total
|
||||
graph = recent(samples, total, graphBase)
|
||||
}
|
||||
|
||||
private fun line(base: Float): String {
|
||||
@@ -176,6 +163,14 @@ class PerfHud(context: Context) {
|
||||
companion object {
|
||||
private const val TICK_MS = 1_000L
|
||||
private const val GRAPH = 128
|
||||
internal const val GRAPH_MAX_MS = 50f
|
||||
|
||||
internal fun recent(samples: FloatArray, total: Long, base: Long): FloatArray {
|
||||
val filled = minOf(total, samples.size.toLong()).toInt()
|
||||
val shown = minOf(filled.toLong(), (total - base).coerceAtLeast(0L)).toInt()
|
||||
if (shown < 2) return FloatArray(0)
|
||||
return FloatArray(shown) { samples[filled - shown + it].coerceIn(0f, GRAPH_MAX_MS) }
|
||||
}
|
||||
|
||||
internal fun batteryCelsius(deci: Int): String? =
|
||||
if (deci <= 0) null else String.format(Locale.US, "%.1f°C", deci / 10f)
|
||||
|
||||
@@ -114,12 +114,19 @@ object ProtonDefault {
|
||||
return if (SessionState.running && state.live && (tool == null || state.pending != tool.name)) Outcome.LIVE else Outcome.NEXT_START
|
||||
}
|
||||
|
||||
internal fun movedGames(choices: Map<String, GameChoice?>, from: Set<String>, to: String): Map<String, GameChoice?>? {
|
||||
if (choices.values.none { it != null && !it.valve && it.dir in from }) return null
|
||||
return choices.mapValues { (_, choice) -> if (choice != null && !choice.valve && choice.dir in from) GameChoice(false, to) else choice }
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun requestGame(context: Context, scope: String, proton: ComponentsManager.Proton?): Outcome {
|
||||
require(GameEnvironment.validScope(scope))
|
||||
fun moveGames(context: Context, from: Set<String>, to: String) {
|
||||
val d = dir(context)
|
||||
val choices = parseGames(read(File(d, GAMES))).toMutableMap()
|
||||
choices[scope] = proton?.let { GameChoice(it.valve, it.dir.name) }
|
||||
val moved = movedGames(parseGames(read(File(d, GAMES))), from, to) ?: return
|
||||
writeGames(d, moved)
|
||||
}
|
||||
|
||||
private fun writeGames(d: File, choices: Map<String, GameChoice?>) {
|
||||
val games = JSONObject()
|
||||
choices.forEach { (id, choice) ->
|
||||
games.put(id, choice?.let { JSONObject().put("valve", it.valve).put("dir", it.dir) } ?: JSONObject.NULL)
|
||||
@@ -134,6 +141,15 @@ object ProtonDefault {
|
||||
Log.w(TAG, "could not write the per-game Proton request", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun requestGame(context: Context, scope: String, proton: ComponentsManager.Proton?): Outcome {
|
||||
require(GameEnvironment.validScope(scope))
|
||||
val d = dir(context)
|
||||
val choices = parseGames(read(File(d, GAMES))).toMutableMap()
|
||||
choices[scope] = proton?.let { GameChoice(it.valve, it.dir.name) }
|
||||
writeGames(d, choices)
|
||||
val state = state(context)
|
||||
val tool = proton?.let { selected -> state.tools.firstOrNull { it.valve == selected.valve && it.dir == selected.dir.name } }
|
||||
return if (SessionState.running && state.live && (proton == null || tool != null && state.pending != tool.name)) {
|
||||
|
||||
@@ -16,16 +16,20 @@ object ProtonExtras {
|
||||
private const val TAG = "ProtonExtras"
|
||||
private const val NEED_BYTES = 4L * 1024 * 1024 * 1024
|
||||
private const val RELEASES = "https://api.github.com/repos/%s/releases?per_page=15"
|
||||
const val CHECK_EVERY_MS = 6L * 60 * 60 * 1000
|
||||
const val CHECK_EVERY_MS = 60L * 60 * 1000
|
||||
@Volatile
|
||||
var installInProgress = false
|
||||
private set
|
||||
@Volatile
|
||||
private var replacing = false
|
||||
|
||||
class Tool(val id: String, val name: String, val prefix: String, val repo: String, val assetPattern: Regex)
|
||||
|
||||
internal data class Asset(val tag: String, val name: String, val url: String, val sha512: String?, val size: Long,
|
||||
val sha256: String? = null)
|
||||
|
||||
const val OWN = "droiddeck"
|
||||
|
||||
val tools = listOf(
|
||||
Tool("ge", "GE-Proton", "GE-Proton", "GloriousEggroll/proton-ge-custom", Regex("aarch64\\.tar\\.(gz|xz)$")),
|
||||
Tool("cachyos", "proton-cachyos", "proton-cachyos", "CachyOS/proton-cachyos", Regex("arm64\\.tar\\.(gz|xz)$")),
|
||||
@@ -78,11 +82,23 @@ object ProtonExtras {
|
||||
|
||||
fun update(context: Context, tool: Tool): String? = updateFor(installedTags(context, tool), cachedLatest(context, tool))
|
||||
|
||||
fun missing(context: Context, tool: Tool): String? =
|
||||
if (tool.id == OWN && !declined(context) && installedAll(context, tool).isEmpty()) cachedLatest(context, tool) else null
|
||||
|
||||
private fun choices(context: Context) = context.getSharedPreferences("proton-auto-updates", Context.MODE_PRIVATE)
|
||||
|
||||
fun declined(context: Context): Boolean = choices(context).getBoolean("$OWN.declined", false)
|
||||
|
||||
fun setDeclined(context: Context, declined: Boolean) {
|
||||
choices(context).edit().putBoolean("$OWN.declined", declined).apply()
|
||||
}
|
||||
|
||||
fun cachedLatest(context: Context, tool: Tool): String? =
|
||||
readJson(latestFile(context)).optJSONObject(tool.id)?.optString("tag")?.ifEmpty { null }
|
||||
|
||||
private val checkLock = Any()
|
||||
private const val RETRY_MS = 15L * 60 * 1000
|
||||
private const val USER_SETTINGS = "user_settings.py"
|
||||
private var lastAttempt = 0L
|
||||
|
||||
fun checkLatest(context: Context, force: Boolean = false, now: Long = System.currentTimeMillis()): Boolean {
|
||||
@@ -145,6 +161,44 @@ object ProtonExtras {
|
||||
}
|
||||
}
|
||||
|
||||
private fun replaceOlder(context: Context, tool: Tool) {
|
||||
val all = installedAll(context, tool)
|
||||
val newest = all.lastOrNull() ?: return
|
||||
val older = all.dropLast(1)
|
||||
if (older.isEmpty()) return
|
||||
replacing = true
|
||||
try {
|
||||
for (old in older.asReversed()) {
|
||||
if (SessionState.running) break
|
||||
if (runCatching { ComponentsManager.carryOver(context, old, newest) }.onFailure { Log.w(TAG, "components of $old", it) }.isFailure) continue
|
||||
if (runCatching { keepUserSettings(context, old, newest) }.onFailure { Log.w(TAG, "user settings of $old", it) }.isFailure) continue
|
||||
if (runCatching { ProtonDefault.moveGames(context, setOf(old), newest) }.onFailure { Log.w(TAG, "per-game picks of $old", it) }.isFailure) continue
|
||||
if (File(toolsDir(context), old).deleteRecursively()) ComponentsManager.forgetProton(context, old)
|
||||
else Log.w(TAG, "could not remove $old")
|
||||
}
|
||||
} finally {
|
||||
replacing = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun keepUserSettings(context: Context, old: String, newest: String) {
|
||||
val from = File(File(toolsDir(context), old), USER_SETTINGS)
|
||||
val to = File(File(toolsDir(context), newest), USER_SETTINGS)
|
||||
if (from.isFile && !to.exists()) from.copyTo(to)
|
||||
}
|
||||
|
||||
fun tidy(context: Context) {
|
||||
val tool = tools.firstOrNull { it.id == OWN } ?: return
|
||||
if (installedAll(context, tool).size > 1) replaceOlder(context, tool)
|
||||
}
|
||||
|
||||
fun awaitReplacement(timeoutMs: Long) {
|
||||
val until = System.currentTimeMillis() + timeoutMs
|
||||
while (replacing && System.currentTimeMillis() < until) {
|
||||
try { Thread.sleep(50) } catch (_: InterruptedException) { Thread.currentThread().interrupt(); return }
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun install(context: Context, tool: Tool, onProgress: (String, Int) -> Unit): String? {
|
||||
if (installInProgress) return context.getString(R.string.pextra_busy)
|
||||
@@ -246,6 +300,7 @@ object ProtonExtras {
|
||||
archive.delete()
|
||||
unqueue(context, tool)
|
||||
record(context, tool, placed, asset.tag)
|
||||
if (tool.id == OWN) replaceOlder(context, tool)
|
||||
if (EsyncPacks.enabled(context)) {
|
||||
onProgress(context.getString(R.string.esync_fetching), -1)
|
||||
try {
|
||||
|
||||
@@ -30,6 +30,7 @@ class RumbleComponent : SessionPart() {
|
||||
private val joyConPairs = HashMap<Long, Motors>()
|
||||
private var preferences: SharedPreferences? = null
|
||||
private var enabled = false
|
||||
private var quiet = false
|
||||
private var motorThread: HandlerThread? = null
|
||||
private var handler: Handler? = null
|
||||
private val preferenceListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||
@@ -44,6 +45,11 @@ class RumbleComponent : SessionPart() {
|
||||
if (!enabled) cancelAll()
|
||||
}
|
||||
|
||||
@Synchronized fun quiet(on: Boolean) {
|
||||
quiet = on
|
||||
if (on) cancelAll()
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
val ctx = app() ?: return
|
||||
val s = try { LocalServerSocket(NAME) } catch (e: Exception) { Log.w(TAG, "rumble: no listener ($e)"); return }
|
||||
@@ -89,7 +95,7 @@ class RumbleComponent : SessionPart() {
|
||||
private fun u16(b: ByteArray, at: Int): Int = (b[at].toInt() and 0xFF) or ((b[at + 1].toInt() and 0xFF) shl 8)
|
||||
|
||||
@Synchronized private fun buzz(strong: Int, weak: Int, ms: Int, slot: Int) {
|
||||
if (!enabled) return
|
||||
if (!enabled || quiet) return
|
||||
val target = target(slot)
|
||||
val previous = playing[slot]
|
||||
if (target !== previous) {
|
||||
|
||||
@@ -17,12 +17,13 @@ object SessionDisplay {
|
||||
fun screenSize(panel: Pair<Int, Int>): Pair<Int, Int> =
|
||||
(maxOf(panel.first, panel.second) and 1.inv()) to (minOf(panel.first, panel.second) and 1.inv())
|
||||
|
||||
fun resolveChoice(panel: Pair<Int, Int>, choice: String): Pair<Int, Int> {
|
||||
if (choice == MATCH_SCREEN || choice == FOLLOW_SCREEN) return screenSize(panel)
|
||||
presetHeight(choice)?.let { return resolve(panel, it, SessionPrefs.SHAPE_AUTO) }
|
||||
fun resolveChoice(panel: Pair<Int, Int>, choice: String, portrait: Boolean = false): Pair<Int, Int> {
|
||||
fun orient(size: Pair<Int, Int>) = if (portrait) size.second to size.first else size
|
||||
if (choice == MATCH_SCREEN || choice == FOLLOW_SCREEN) return orient(screenSize(panel))
|
||||
presetHeight(choice)?.let { return orient(resolve(panel, it, SessionPrefs.SHAPE_AUTO)) }
|
||||
val parts = choice.split('x').map { it.toIntOrNull() }
|
||||
return if (parts.size == 2 && parts.all { it != null && it > 0 }) parts[0]!! to parts[1]!!
|
||||
else resolve(panel, 720, SessionPrefs.SHAPE_AUTO)
|
||||
else orient(resolve(panel, 720, SessionPrefs.SHAPE_AUTO))
|
||||
}
|
||||
|
||||
fun resolutionOptions(panel: Pair<Int, Int>): List<String> {
|
||||
@@ -31,8 +32,10 @@ object SessionDisplay {
|
||||
.filter { resolveChoice(panel, it) != screenSize(panel) } + MATCH_SCREEN + FOLLOW_SCREEN
|
||||
}
|
||||
|
||||
fun followSize(width: Int, height: Int): Pair<Int, Int>? =
|
||||
if (minOf(width, height) < FOLLOW_MIN_SIDE) null else (width and 1.inv()) to (height and 1.inv())
|
||||
fun followSize(width: Int, height: Int, controlsBelow: Boolean = false): Pair<Int, Int>? =
|
||||
if (width <= 0 || height <= 0 ||
|
||||
(if (controlsBelow) width else minOf(width, height)) < FOLLOW_MIN_SIDE) null
|
||||
else (width and 1.inv()) to (height and 1.inv())
|
||||
|
||||
const val UNFOLDED_MAX_GAME_SHARE = 0.8f
|
||||
|
||||
@@ -49,13 +52,14 @@ object SessionDisplay {
|
||||
foldable: Boolean,
|
||||
controllerConnected: Boolean,
|
||||
keepWithController: Boolean,
|
||||
steamDeckPad: Boolean,
|
||||
gamepadAvailable: Boolean,
|
||||
pip: Boolean,
|
||||
width: Int,
|
||||
height: Int,
|
||||
smallestWidthDp: Int,
|
||||
): Boolean = enabled && foldable && (keepWithController || !controllerConnected) && steamDeckPad &&
|
||||
!pip && width > 0 && height > 0 && smallestWidthDp >= UNFOLDED_MIN_DP
|
||||
): Boolean = enabled && (keepWithController || !controllerConnected) && gamepadAvailable &&
|
||||
!pip && width > 0 && height > 0 &&
|
||||
(height > width || (foldable && smallestWidthDp >= UNFOLDED_MIN_DP))
|
||||
|
||||
|
||||
fun panelSize(context: Context): Pair<Int, Int> {
|
||||
@@ -79,5 +83,5 @@ object SessionDisplay {
|
||||
}
|
||||
|
||||
fun canStretch16x9(size: Pair<Int, Int>): Boolean =
|
||||
(size.second * 16 + 4) / 9 / 2 * 2 > size.first
|
||||
(size.second * 16 + 4) / 9 / 2 * 2 > size.first || (size.first * 9 + 8) / 16 / 2 * 2 > size.second
|
||||
}
|
||||
@@ -74,12 +74,14 @@ object SessionFiles {
|
||||
"usr/local/bin/droiddeck-steam-shortcuts" to "usr/local/bin/droiddeck-steam-shortcuts",
|
||||
"usr/local/bin/droiddeck-xbox" to "usr/local/bin/droiddeck-xbox",
|
||||
"usr/local/bin/droiddeck-store-launch" to "usr/local/bin/droiddeck-store-launch",
|
||||
"usr/local/bin/droiddeck-battlenet" to "usr/local/bin/droiddeck-battlenet",
|
||||
"usr/local/bin/droiddeck-epic" to "usr/local/bin/droiddeck-epic",
|
||||
"usr/local/bin/droiddeck-epic-steam" to "usr/local/bin/droiddeck-epic-steam",
|
||||
"usr/local/bin/droiddeck-open-url" to "usr/local/bin/droiddeck-open-url",
|
||||
"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",
|
||||
"usr/local/bin/droiddeck-steam-x64" to "usr/local/bin/droiddeck-steam-x64",
|
||||
"usr/local/bin/droiddeck-fex-update" to "usr/local/bin/droiddeck-fex-update",
|
||||
"usr/local/bin/droiddeck-steamrt-shim" to "usr/local/bin/droiddeck-steamrt-shim",
|
||||
"usr/local/bin/droiddeck-x64-arm-proton" to "usr/local/bin/droiddeck-x64-arm-proton",
|
||||
"usr/local/bin/droiddeck-x64-arm-webhelper" to "usr/local/bin/droiddeck-x64-arm-webhelper",
|
||||
@@ -97,6 +99,15 @@ object SessionFiles {
|
||||
"usr/local/bin/droiddeck-script-run" to "usr/local/bin/droiddeck-script-run",
|
||||
"usr/local/bin/droiddeck-open" to "usr/local/bin/droiddeck-open",
|
||||
"usr/local/bin/droiddeck-proton-run" to "usr/local/bin/droiddeck-proton-run",
|
||||
"usr/local/bin/droiddeck-innoextract" to "usr/local/bin/droiddeck-innoextract",
|
||||
"usr/local/lib/droiddeck-inno/innoextract" to "usr/local/lib/droiddeck-inno/innoextract",
|
||||
"usr/local/lib/droiddeck-inno/libboost_container.so.1.92.0" to "usr/local/lib/droiddeck-inno/libboost_container.so.1.92.0",
|
||||
"usr/local/lib/droiddeck-inno/libboost_filesystem.so.1.92.0" to "usr/local/lib/droiddeck-inno/libboost_filesystem.so.1.92.0",
|
||||
"usr/local/lib/droiddeck-inno/libboost_iostreams.so.1.92.0" to "usr/local/lib/droiddeck-inno/libboost_iostreams.so.1.92.0",
|
||||
"usr/local/lib/droiddeck-inno/libboost_program_options.so.1.92.0" to "usr/local/lib/droiddeck-inno/libboost_program_options.so.1.92.0",
|
||||
"usr/local/lib/droiddeck-inno/libboost_random.so.1.92.0" to "usr/local/lib/droiddeck-inno/libboost_random.so.1.92.0",
|
||||
"usr/local/share/licenses/droiddeck-inno/LICENSE.innoextract" to "usr/local/share/licenses/droiddeck-inno/LICENSE.innoextract",
|
||||
"usr/local/share/licenses/droiddeck-inno/LICENSE.boost" to "usr/local/share/licenses/droiddeck-inno/LICENSE.boost",
|
||||
"usr/bin/steamos-update" to "usr/bin/steamos-update",
|
||||
"usr/bin/steamos-select-branch" to "usr/bin/steamos-select-branch",
|
||||
"usr/bin/steamos-session-select" to "usr/bin/steamos-session-select",
|
||||
@@ -141,6 +152,8 @@ object SessionFiles {
|
||||
} + listOf("libvulkan-thunk.so", "libwebkitinput.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",
|
||||
// The gamescope pack carries its own WSI layer (patch 0117); it replaces the runtime's stock copy.
|
||||
"usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so" to "usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so",
|
||||
"usr/local/lib/droiddeck/uruntime" to "usr/local/lib/droiddeck/uruntime",
|
||||
"usr/local/lib/droiddeck-pipewire.tzst" to "usr/local/lib/droiddeck-pipewire.tzst",
|
||||
"usr/local/share/licenses/uruntime/LICENSE" to "usr/local/share/licenses/uruntime/LICENSE",
|
||||
@@ -205,7 +218,11 @@ object SessionFiles {
|
||||
if (!File(Environment.getExternalStorageDirectory(), NO_PAD_SWITCH).exists()) {
|
||||
preload.append("/usr/local/lib/libfakeinput.so\n")
|
||||
}
|
||||
if (ProotFastPath.enabled(context)) preload.append(ProotFastPath.LIBRARY + "\n")
|
||||
if (ProotFastPath.enabled(context)) {
|
||||
val library = com.droiddeck.launcher.agent.AgentEnv.fastPathLibrary(context)
|
||||
preload.append(library + "\n")
|
||||
if (startsSession && library != ProotFastPath.LIBRARY) Log.i(TAG, "fast path preload: $library (debugging override)")
|
||||
}
|
||||
val etc = File(root, "etc").apply { mkdirs() }
|
||||
val staged = File(etc, "ld.so.preload.staged")
|
||||
if (!FileUtils.writeString(staged, preload.toString())
|
||||
|
||||
@@ -12,6 +12,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.core.content.FileProvider
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.core.LogRedactor
|
||||
import com.droiddeck.launcher.runtime.BattleNet
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import java.io.File
|
||||
import java.util.zip.ZipEntry
|
||||
@@ -49,7 +50,8 @@ object SessionLogShare {
|
||||
val logs = LinuxRuntime.logDir(context)
|
||||
val stores = recent(File(logs, STORES_DIR))
|
||||
val tools = recent(File(logs, SessionPaths.TOOLS_DIR))
|
||||
val total = (files + live + stores + tools).sumOf { it.length() }.coerceAtLeast(1L)
|
||||
val battleNet = battleNetLogs(context)
|
||||
val total = (files + live + stores + tools + battleNet.map { it.second }).sumOf { it.length() }.coerceAtLeast(1L)
|
||||
var done = 0L
|
||||
var shown = -1
|
||||
fun advance(f: File) {
|
||||
@@ -62,6 +64,7 @@ object SessionLogShare {
|
||||
live.forEach { f -> addEntry(z, folder.name + "/steam/" + f.name, f); advance(f) }
|
||||
stores.forEach { f -> addEntry(z, "$STORES_DIR/" + f.name, f); advance(f) }
|
||||
tools.forEach { f -> addEntry(z, SessionPaths.TOOLS_DIR + "/" + f.name, f); advance(f) }
|
||||
battleNet.forEach { (name, f) -> addEntry(z, "$BATTLENET_DIR/$name", f); advance(f) }
|
||||
}
|
||||
return zip
|
||||
}
|
||||
@@ -88,6 +91,27 @@ object SessionLogShare {
|
||||
|
||||
private fun shareDir(context: Context): File = File(context.cacheDir, "share")
|
||||
|
||||
private const val BATTLENET_DIR = "battlenet"
|
||||
|
||||
private fun battleNetLogs(context: Context): List<Pair<String, File>> {
|
||||
val drive = File(BattleNet.prefix(context), "pfx/drive_c")
|
||||
val data = File(drive, "ProgramData/Battle.net")
|
||||
fun logsUnder(dir: File, prefix: String) = dir.listFiles { f -> f.isDirectory && f.name.startsWith(prefix) }.orEmpty().map { File(it, "Logs") }
|
||||
return newest("droiddeck", listOf(File(LinuxRuntime.rootDir(context), "root/.cache/droiddeck/battlenet")), 2, setOf("battlenet.log", "spawned.log")) +
|
||||
newest("client", listOf(File(drive, "users/steamuser/AppData/Local/Battle.net/Logs")), 6) +
|
||||
newest("agent", listOf(File(data, "Agent/Logs")) + logsUnder(File(data, "Agent"), "Agent."), 10, byDir = true) +
|
||||
newest("setup", logsUnder(File(data, "Setup"), ""), 3, byDir = true)
|
||||
}
|
||||
|
||||
private fun newest(folder: String, dirs: List<File>, count: Int, names: Set<String>? = null, byDir: Boolean = false): List<Pair<String, File>> {
|
||||
val since = System.currentTimeMillis() - RECENT_DAYS * 86_400_000L
|
||||
return dirs.flatMap { dir ->
|
||||
dir.listFiles { f -> f.isFile && f.name.endsWith(".log") && (names == null || f.name in names) && f.lastModified() >= since && f.length() <= STEAM_LOG_MAX_BYTES }.orEmpty().toList()
|
||||
}.sortedByDescending { it.lastModified() }.take(count).map { f ->
|
||||
(if (byDir) "$folder/${f.parentFile?.parentFile?.name}/${f.name}" else "$folder/${f.name}") to f
|
||||
}
|
||||
}
|
||||
|
||||
private fun recent(dir: File): List<File> {
|
||||
val since = System.currentTimeMillis() - RECENT_DAYS * 86_400_000L
|
||||
return dir.listFiles { f -> f.isFile && f.lastModified() >= since }?.sortedBy { it.name }.orEmpty()
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.droiddeck.launcher.core.TextureFiltering
|
||||
import com.droiddeck.launcher.gpu.Cardboard
|
||||
import com.droiddeck.launcher.gpu.ScreenEffects
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
object SessionPrefs {
|
||||
data class GameTextureFiltering(val anisotropy: Int? = null, val lodBias: String? = null)
|
||||
@@ -43,6 +44,8 @@ object SessionPrefs {
|
||||
private fun prefs(context: Context) = context.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
|
||||
val orientationOptions = listOf(
|
||||
ActivityInfo.SCREEN_ORIENTATION_USER to R.string.setup_launcher_orientation_auto,
|
||||
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT to R.string.setup_orientation_portrait,
|
||||
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE to R.string.setup_orientation_auto,
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE to R.string.setup_orientation_landscape,
|
||||
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE to R.string.setup_orientation_reverse,
|
||||
@@ -58,6 +61,17 @@ object SessionPrefs {
|
||||
prefs(context).edit().putInt("orientation", orientation).apply()
|
||||
}
|
||||
|
||||
fun windowOrientation(context: Context, followScreen: Boolean, smallestWidthDp: Int): Int =
|
||||
if (followScreen && smallestWidthDp >= SessionDisplay.UNFOLDED_MIN_DP && !prefs(context).contains("orientation"))
|
||||
ActivityInfo.SCREEN_ORIENTATION_USER else orientation(context)
|
||||
|
||||
fun portrait(context: Context): Boolean = when (orientation(context)) {
|
||||
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT -> true
|
||||
ActivityInfo.SCREEN_ORIENTATION_USER ->
|
||||
context.resources.configuration.orientation == android.content.res.Configuration.ORIENTATION_PORTRAIT
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun launcherFullscreen(context: Context): Boolean = prefs(context).getBoolean("launcherFullscreen", true)
|
||||
|
||||
fun setLauncherFullscreen(context: Context, on: Boolean) {
|
||||
@@ -111,6 +125,12 @@ object SessionPrefs {
|
||||
prefs(context).edit().putString("storesView", if (view in STORES_VIEWS) view else STORES_VIEWS.first()).apply()
|
||||
}
|
||||
|
||||
fun libraryShowUninstalled(context: Context): Boolean = prefs(context).getBoolean("libraryShowUninstalled", false)
|
||||
|
||||
fun setLibraryShowUninstalled(context: Context, show: Boolean) {
|
||||
prefs(context).edit().putBoolean("libraryShowUninstalled", show).apply()
|
||||
}
|
||||
|
||||
fun storesTabOrder(context: Context): List<String> = idList(prefs(context).getString("storesTabOrder", null))
|
||||
|
||||
fun setStoresTabOrder(context: Context, order: List<String>) {
|
||||
@@ -141,6 +161,34 @@ object SessionPrefs {
|
||||
prefs(context).edit().putString("storesInstallLanguage", code).apply()
|
||||
}
|
||||
|
||||
const val DEFAULT_STORAGE_ASK = "ask"
|
||||
const val DEFAULT_STORAGE_INTERNAL = "internal"
|
||||
const val DEFAULT_STORAGE_EXTERNAL = "external"
|
||||
private val DEFAULT_STORAGE_VALUES = setOf(DEFAULT_STORAGE_ASK, DEFAULT_STORAGE_INTERNAL, DEFAULT_STORAGE_EXTERNAL)
|
||||
|
||||
fun defaultStorage(context: Context): String =
|
||||
prefs(context).getString("defaultStorage", DEFAULT_STORAGE_ASK)
|
||||
?.takeIf { it in DEFAULT_STORAGE_VALUES } ?: DEFAULT_STORAGE_ASK
|
||||
|
||||
fun setDefaultStorage(context: Context, value: String) {
|
||||
prefs(context).edit().putString("defaultStorage", value.takeIf { it in DEFAULT_STORAGE_VALUES } ?: DEFAULT_STORAGE_ASK).apply()
|
||||
}
|
||||
|
||||
fun defaultStorageFolder(context: Context): String = prefs(context).getString("defaultStorageFolder", "") ?: ""
|
||||
|
||||
fun defaultStorageFolderLabel(context: Context): String = prefs(context).getString("defaultStorageFolderLabel", "") ?: ""
|
||||
|
||||
fun setDefaultStorageFolder(context: Context, path: String, label: String) {
|
||||
prefs(context).edit()
|
||||
.putString("defaultStorageFolder", path)
|
||||
.putString("defaultStorageFolderLabel", label)
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun clearDefaultStorageFolder(context: Context) {
|
||||
prefs(context).edit().remove("defaultStorageFolder").remove("defaultStorageFolderLabel").apply()
|
||||
}
|
||||
|
||||
fun gameStoresParallel(context: Context): Int = prefs(context).getInt("gameStoresParallel", 1).coerceIn(1, 3)
|
||||
|
||||
fun setGameStoresParallel(context: Context, count: Int) {
|
||||
@@ -195,16 +243,10 @@ object SessionPrefs {
|
||||
private fun mangoappSession(context: Context) =
|
||||
SessionState.mode == SessionService.MODE_STEAM && mangoapp(context)
|
||||
|
||||
fun lowLatencyController(context: Context): Boolean = prefs(context).getBoolean("lowLatencyController", false)
|
||||
fun lowLatency(context: Context): Boolean = prefs(context).getBoolean("lowLatency", true)
|
||||
|
||||
fun setLowLatencyController(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("lowLatencyController", on).apply()
|
||||
}
|
||||
|
||||
fun lowLatencyTouch(context: Context): Boolean = prefs(context).getBoolean("lowLatencyTouch", false)
|
||||
|
||||
fun setLowLatencyTouch(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("lowLatencyTouch", on).apply()
|
||||
fun setLowLatency(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("lowLatency", on).apply()
|
||||
}
|
||||
|
||||
fun backActionsInverted(context: Context): Boolean = prefs(context).getBoolean("backActionsInverted", false)
|
||||
@@ -213,6 +255,16 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("backActionsInverted", inverted).apply()
|
||||
}
|
||||
|
||||
val BACK_DOUBLE_TAP_MS_OPTIONS = (100..800 step 100).toList()
|
||||
|
||||
fun backDoubleTapMs(context: Context): Int =
|
||||
prefs(context).getInt("backDoubleTapMs", 500).takeIf { it in BACK_DOUBLE_TAP_MS_OPTIONS } ?: 500
|
||||
|
||||
fun setBackDoubleTapMs(context: Context, ms: Int) {
|
||||
require(ms in BACK_DOUBLE_TAP_MS_OPTIONS)
|
||||
prefs(context).edit().putInt("backDoubleTapMs", ms).apply()
|
||||
}
|
||||
|
||||
const val TOUCH_AUTO = "auto"
|
||||
const val TOUCH_PAD = "touchpad"
|
||||
const val TOUCH_DIRECT = "direct"
|
||||
@@ -453,6 +505,24 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("gamescopeRealtime", on).apply()
|
||||
}
|
||||
|
||||
fun ramCapMb(context: Context): Int = prefs(context).getInt("ramCapMb", 0).coerceAtLeast(0)
|
||||
|
||||
fun setRamCapMb(context: Context, mb: Int) {
|
||||
prefs(context).edit().putInt("ramCapMb", mb.coerceAtLeast(0)).apply()
|
||||
}
|
||||
|
||||
fun zramClient(context: Context): Boolean = prefs(context).getBoolean("zramClient", true)
|
||||
|
||||
fun setZramClient(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("zramClient", on).apply()
|
||||
}
|
||||
|
||||
fun vramCapMb(context: Context): Int = prefs(context).getInt("vramCapMb", 0).coerceAtLeast(0)
|
||||
|
||||
fun setVramCapMb(context: Context, mb: Int) {
|
||||
prefs(context).edit().putInt("vramCapMb", mb.coerceAtLeast(0)).apply()
|
||||
}
|
||||
|
||||
fun gpuClockPin(context: Context): Boolean = prefs(context).getBoolean("gpuClockPin", false)
|
||||
|
||||
fun setGpuClockPin(context: Context, on: Boolean) {
|
||||
@@ -481,6 +551,15 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("cursorComposite", on).apply()
|
||||
}
|
||||
|
||||
/**
|
||||
* The rootfs ships Termux's unpatched proot. A session uses it only when this file exists,
|
||||
* so a missing add-on pack cannot silently fall back to it.
|
||||
* Path: Android/data/<package>/files/droiddeck-stock-proot
|
||||
*/
|
||||
@JvmStatic
|
||||
fun allowStockProot(context: Context): Boolean =
|
||||
context.getExternalFilesDir(null)?.let { File(it, "droiddeck-stock-proot").isFile } == true
|
||||
|
||||
const val DEFAULT_GUEST_HOSTNAME = "DroidDeck"
|
||||
|
||||
@JvmStatic
|
||||
@@ -523,6 +602,7 @@ object SessionPrefs {
|
||||
}
|
||||
|
||||
fun mangoapp(context: Context): Boolean = prefs(context).getBoolean("mangoapp", true)
|
||||
fun vsyncThread(context: Context): Boolean = prefs(context).getBoolean("vsyncThread", true)
|
||||
fun setMangoapp(context: Context, on: Boolean) { prefs(context).edit().putBoolean("mangoapp", on).apply() }
|
||||
|
||||
fun zinkLazy(context: Context): Boolean = prefs(context).getBoolean("zinkLazy", true)
|
||||
@@ -554,6 +634,32 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("logs", on).apply()
|
||||
}
|
||||
|
||||
fun battleNetNoSteamSet(context: Context): Boolean = prefs(context).getBoolean("battleNetNoSteamSet", false)
|
||||
fun setBattleNetNoSteamSet(context: Context) { prefs(context).edit().putBoolean("battleNetNoSteamSet", true).apply() }
|
||||
|
||||
fun clearCachedApps(context: Context): Boolean = prefs(context).getBoolean("clearCachedApps", false)
|
||||
fun setClearCachedApps(context: Context, on: Boolean) { prefs(context).edit().putBoolean("clearCachedApps", on).apply() }
|
||||
|
||||
fun backgroundAppLimit(context: Context): Int =
|
||||
prefs(context).getInt("backgroundAppLimit", com.droiddeck.launcher.core.BackgroundAppLimit.OFF)
|
||||
.takeIf { it in com.droiddeck.launcher.core.BackgroundAppLimit.CHOICES } ?: com.droiddeck.launcher.core.BackgroundAppLimit.OFF
|
||||
fun setBackgroundAppLimit(context: Context, limit: Int) {
|
||||
require(limit in com.droiddeck.launcher.core.BackgroundAppLimit.CHOICES)
|
||||
prefs(context).edit().putInt("backgroundAppLimit", limit).apply()
|
||||
}
|
||||
|
||||
const val MEMORY_HUD_OFF = "off"
|
||||
const val MEMORY_HUD_SIMPLE = "simple"
|
||||
const val MEMORY_HUD_ADVANCED = "advanced"
|
||||
|
||||
fun memoryHud(context: Context): String =
|
||||
prefs(context).getString("memoryHud", MEMORY_HUD_OFF)
|
||||
?.takeIf { it == MEMORY_HUD_SIMPLE || it == MEMORY_HUD_ADVANCED } ?: MEMORY_HUD_OFF
|
||||
fun setMemoryHud(context: Context, value: String) {
|
||||
require(value == MEMORY_HUD_OFF || value == MEMORY_HUD_SIMPLE || value == MEMORY_HUD_ADVANCED)
|
||||
prefs(context).edit().putString("memoryHud", value).apply()
|
||||
}
|
||||
|
||||
fun storageDiagnosticsEnabled(context: Context): Boolean =
|
||||
prefs(context).getBoolean("storageDiagnostics", false)
|
||||
|
||||
@@ -582,8 +688,10 @@ object SessionPrefs {
|
||||
parseResolution(value)?.let { return "${it.first}x${it.second}" }
|
||||
}
|
||||
if (!resolutionChosen(context, mode) && !saved.contains("shape")) return SessionDisplay.DEFAULT_RESOLUTION
|
||||
val legacy = SessionDisplay.resolve(panel, resolutionCap(context, mode), shapeMode(context), customResolution(context, mode))
|
||||
val custom = customResolution(context, mode)
|
||||
val legacy = SessionDisplay.resolve(panel, resolutionCap(context, mode), shapeMode(context), custom)
|
||||
return if (legacy == SessionDisplay.screenSize(panel)) SessionDisplay.MATCH_SCREEN
|
||||
else if (custom == null && legacy == SessionDisplay.resolve(panel, legacy.second, SHAPE_AUTO)) "${legacy.second}p"
|
||||
else "${legacy.first}x${legacy.second}"
|
||||
}
|
||||
|
||||
@@ -831,16 +939,15 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("hdr.$mode", on).apply()
|
||||
}
|
||||
|
||||
fun fpsLimit(context: Context, mode: String): Int = prefs(context).getInt("fpsLimit.$mode", 0)
|
||||
/** Compositor frame limit that releases buffers to the game unpaced. */
|
||||
const val FPS_UNPACED = -1
|
||||
|
||||
fun setFpsLimit(context: Context, mode: String, fps: Int) {
|
||||
prefs(context).edit().putInt("fpsLimit.$mode", fps.coerceAtLeast(0)).apply()
|
||||
}
|
||||
|
||||
val fpsLimitChoices = listOf(0 to "Off", 30 to "30", 40 to "40", 45 to "45", 60 to "60", 90 to "90", 120 to "120")
|
||||
|
||||
fun fpsLimitChoices(context: Context): List<Pair<Int, String>> =
|
||||
fpsLimitChoices.map { (fps, label) -> fps to if (fps == 0) context.getString(R.string.frame_gen_off) else label }
|
||||
/**
|
||||
* Buffers go back to the game as soon as they are replaced instead of once per refresh;
|
||||
* Steam's Frame Limit in the Quick Access menu caps games. Mirroring still follows the glasses' refresh rate.
|
||||
*/
|
||||
fun compositorFpsLimit(mirrorRefreshLimit: Int): Int =
|
||||
if (mirrorRefreshLimit <= 0) FPS_UNPACED else mirrorRefreshLimit
|
||||
|
||||
val upscalerChoices = listOf(
|
||||
0 to "Linear", 2 to "Nearest", 4 to "AMD FSR 1", 3 to "Snapdragon GSR",
|
||||
@@ -1029,6 +1136,18 @@ object SessionPrefs {
|
||||
|
||||
fun unfoldedControls(context: Context): Boolean = prefs(context).getBoolean("unfoldedControls", false)
|
||||
|
||||
fun controlsBelowWanted(context: Context, mode: String, width: Int, height: Int, pip: Boolean = false): Boolean =
|
||||
SessionDisplay.unfoldedControlsWanted(
|
||||
enabled = unfoldedControls(context),
|
||||
foldable = SessionDisplay.foldable(context),
|
||||
controllerConnected = com.droiddeck.launcher.input.PadBridge.anyControllerConnected() ||
|
||||
com.droiddeck.launcher.input.SteamControllerBle.connected,
|
||||
keepWithController = unfoldedControlsWithController(context),
|
||||
gamepadAvailable = mode == SessionService.MODE_STEAM && builtinPad(context),
|
||||
pip = pip, width = width, height = height,
|
||||
smallestWidthDp = context.resources.configuration.smallestScreenWidthDp,
|
||||
)
|
||||
|
||||
fun setUnfoldedControls(context: Context, enabled: Boolean) {
|
||||
prefs(context).edit().putBoolean("unfoldedControls", enabled).apply()
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.os.PowerManager
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.view.Display
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
import com.droiddeck.launcher.audio.DirectAudioRelayComponent
|
||||
@@ -349,8 +350,10 @@ class SessionService : Service() {
|
||||
pipTask = false
|
||||
SessionState.program = intent?.getStringExtra(EXTRA_PROGRAM)
|
||||
SessionState.programArgs = intent?.getStringArrayExtra(EXTRA_PROGRAM_ARGS)?.toList().orEmpty()
|
||||
SessionState.gameId = intent?.getStringExtra(EXTRA_GAME_ID)
|
||||
SessionState.steamUi = intent?.getStringExtra(EXTRA_STEAM_UI)
|
||||
SessionState.steamUrl = intent?.getStringExtra(EXTRA_STEAM_URL)
|
||||
com.droiddeck.launcher.stores.battlenet.BattleNetClient.clearRequests(LinuxRuntime.sessionRoot(this))
|
||||
synchronized(stopLock) {
|
||||
SessionState.steamClientArch = null
|
||||
SessionState.running = true
|
||||
@@ -365,6 +368,9 @@ class SessionService : Service() {
|
||||
SessionEvents.transition(SessionPhase.STARTING_GUEST, "service.started", mapOf("mode" to SessionState.mode))
|
||||
com.droiddeck.launcher.wayland.CompositorHost.newSession()
|
||||
val gen = ++sessionGen
|
||||
SessionPrefs.backgroundAppLimit(this).takeIf { it != com.droiddeck.launcher.core.BackgroundAppLimit.OFF }
|
||||
?.let { com.droiddeck.launcher.core.BackgroundAppLimit.applyAsync(this, it) }
|
||||
if (SessionPrefs.clearCachedApps(this)) clearCachedApps()
|
||||
cancelQueuedSteamGame(clearMailbox = false)
|
||||
clearSteamGameMailbox()
|
||||
if (SessionState.mode == MODE_STEAM) SessionState.steamUrl
|
||||
@@ -372,6 +378,7 @@ class SessionService : Service() {
|
||||
acquireLocks()
|
||||
Thread({
|
||||
OrphanReaper.reap("session starting")
|
||||
ProtonExtras.awaitReplacement(120_000)
|
||||
runSession(gen)
|
||||
}, "session-start").start()
|
||||
return START_NOT_STICKY
|
||||
@@ -424,8 +431,33 @@ class SessionService : Service() {
|
||||
val sessionRoot = LinuxRuntime.sessionRoot(this).apply { mkdirs() }
|
||||
val runtimeDir = File(filesDir, ".wayland-rt").apply { mkdirs() }
|
||||
killStragglers()
|
||||
for (pack in listOf(AddonPack.PROOT, AddonPack.DIRECTAUDIO))
|
||||
if (!pack.await(this, { gen == sessionGen && SessionState.running })) Log.w(TAG, "${pack.name} pack unavailable")
|
||||
val stillStarting = { gen == sessionGen && SessionState.running }
|
||||
val prootPack = LinuxRuntime.patchedProot(this) || AddonPack.PROOT.await(this, stillStarting)
|
||||
val directAudioPack = AddonPack.DIRECTAUDIO.await(this, stillStarting)
|
||||
if (!stillStarting()) {
|
||||
Log.i(TAG, "session stopped while add-on packs were downloading")
|
||||
return
|
||||
}
|
||||
if (!directAudioPack) {
|
||||
Log.w(TAG, "directaudio pack unavailable; game audio drivers will not be staged")
|
||||
mainHandler.post {
|
||||
Toast.makeText(this, R.string.session_directaudio_missing, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
if (!LinuxRuntime.patchedProot(this)) {
|
||||
if (SessionPrefs.allowStockProot(this)) {
|
||||
Log.w(TAG, "proot: patched proot missing; droiddeck-stock-proot allows the rootfs copy")
|
||||
} else {
|
||||
val message = getString(R.string.session_proot_missing)
|
||||
Log.e(TAG, "$message (pack ready=$prootPack)")
|
||||
SessionEvents.fail("PROOT_MISSING", message, -1)
|
||||
stopSession(-1)
|
||||
return
|
||||
}
|
||||
}
|
||||
val agentEnvironment = runCatching { com.droiddeck.launcher.agent.AgentEnv.beginSession(this) }
|
||||
.onFailure { Log.w(TAG, "agent environment skipped", it) }
|
||||
.getOrDefault(emptyList())
|
||||
SessionFiles.stage(this, root, startsSession = true)
|
||||
// Earlier sessions' reports still read the Steam logs and VAC marker this session replaces.
|
||||
SessionArtifacts.awaitCollections()
|
||||
@@ -437,6 +469,10 @@ class SessionService : Service() {
|
||||
|
||||
val sessionDir = openSessionFolder()
|
||||
val sessionLog = File(sessionDir, "session.log")
|
||||
val prootLine = "== proot: ${LinuxRuntime.prootBinary(this).path} (${LinuxRuntime.prootSource(this)})"
|
||||
Log.i(TAG, prootLine)
|
||||
runCatching { sessionLog.appendText(prootLine + "\n") }
|
||||
.onFailure { Log.w(TAG, "could not write the proot line to ${sessionLog.path}", it) }
|
||||
|
||||
Log.i(TAG, GpuClockPin.start(this))
|
||||
Log.i(TAG, GameThreadHints.start(this))
|
||||
@@ -444,16 +480,19 @@ class SessionService : Service() {
|
||||
val size = SessionState.outputSize
|
||||
val guest = ArrayList<String>()
|
||||
val steamHere = SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP
|
||||
runCatching { ComponentsManager.republish(this) }
|
||||
.onSuccess { if (it) Log.i(TAG, "component selections published for the installed Proton builds") }
|
||||
.onFailure { Log.w(TAG, "component selections", it) }
|
||||
if (steamHere) {
|
||||
runCatching { ComponentsManager.ensureForcedPackages(this) }
|
||||
.onSuccess { if (it != null) Log.i(TAG, it) }
|
||||
.onFailure { Log.w(TAG, "forced components", it) }
|
||||
}
|
||||
addClientEnvironment(guest, steamHere)
|
||||
addClientEnvironment(guest, steamHere, agentEnvironment)
|
||||
if (steamHere) guest.add("BL_EPIC_APP_ID=" + com.droiddeck.launcher.stores.epic.EpicClient.shortcutAppId)
|
||||
val fastPathAt = guest.size
|
||||
|
||||
val pulse = startAudio(guest, sessionDir)
|
||||
val pulse = startAudio(guest, sessionDir, directAudioPack)
|
||||
if (steamHere) {
|
||||
val encoder = VideoEncodeBridge(File(filesDir, "venc/venc.sock"))
|
||||
encoder.attach(this)
|
||||
@@ -463,13 +502,21 @@ class SessionService : Service() {
|
||||
|
||||
guest.add("BL_WIDTH=" + size.first)
|
||||
guest.add("BL_HEIGHT=" + size.second)
|
||||
if (SessionState.followScreen) guest.add("BL_FOLLOW_OUTPUT=1")
|
||||
if (SessionState.followScreen || size.first < size.second ||
|
||||
SessionPrefs.orientation(this) == android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER)
|
||||
guest.add("BL_FOLLOW_OUTPUT=1")
|
||||
if (SessionState.hdr) {
|
||||
guest.add("BL_HDR=1")
|
||||
guest.add("DXVK_HDR=1")
|
||||
Log.i(TAG, "hdr: gamescope --hdr-enabled, DXVK_HDR=1")
|
||||
}
|
||||
guest.add("BL_FPS=" + SessionState.fpsLimit)
|
||||
// gamescope's WSI layer and winex11 reuse their per-present window checks for this long.
|
||||
guest.add("DROIDDECK_WSI_BYPASS_CHECK_MS=100")
|
||||
guest.add("WINE_OFFSCREEN_CHECK_MS=100")
|
||||
// gamescope turns buffers around slower than an uncapped game draws; more images keep it drawing.
|
||||
// The WSI layer goes back to its default count while Steam's Frame Limit holds the game.
|
||||
guest.add("GAMESCOPE_WSI_MIN_IMAGE_COUNT=8")
|
||||
guest.add("GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT=1")
|
||||
guest.add("BL_REFRESH=" + Math.round(SessionState.refreshHz))
|
||||
guest.add("BL_LOG=" + sessionLog.path)
|
||||
guest.add("BL_DEBUG_DIR=" + sessionDir.path)
|
||||
@@ -559,6 +606,9 @@ class SessionService : Service() {
|
||||
Log.i(TAG, "proot: seccomp acceleration off by request")
|
||||
}
|
||||
fastPathKey?.let { ProotFastPath.hostEnv(it).let { (k, v) -> hostEnv[k] = v } }
|
||||
for (key in listOf("PROOT_PROFILE", "PROOT_PROFILE_SLOW_US")) {
|
||||
guest.lastOrNull { it.startsWith("$key=") }?.substringAfter('=')?.let { hostEnv[key] = it }
|
||||
}
|
||||
val prootLibs = LinuxRuntime.prootLibraryPath(this)
|
||||
if (prootLibs.isNotEmpty()) hostEnv["LD_LIBRARY_PATH"] = prootLibs
|
||||
|
||||
@@ -580,6 +630,10 @@ class SessionService : Service() {
|
||||
networkLink.attach(this)
|
||||
networkLink.publish()
|
||||
components.add(networkLink)
|
||||
val deviceControls = com.droiddeck.launcher.runtime.DeviceControlsComponent(this, root) { activityVisible && screenOn }
|
||||
deviceControls.attach(this)
|
||||
deviceControls.publish()
|
||||
components.add(deviceControls)
|
||||
if (gen != sessionGen || !SessionState.running) {
|
||||
Log.i(TAG, "session stopped while it was starting; not launching it")
|
||||
if (gen == sessionGen) components.clear()
|
||||
@@ -601,7 +655,7 @@ class SessionService : Service() {
|
||||
val program = programStatus(sessionRoot)
|
||||
Log.i(TAG, "session ended: $status" + if (program != null) " (program $program)" else "")
|
||||
stopSession(program ?: status ?: -1)
|
||||
}, null)
|
||||
}, null, sessionLog.takeIf { "PROOT_PROFILE=1" in hostEnv.asArray() })
|
||||
Log.i(TAG, "session pid $pid, log ${sessionLog.path}")
|
||||
if (gen != sessionGen || !SessionState.running) {
|
||||
Log.i(TAG, "session stopped while its guest was starting; taking it down")
|
||||
@@ -670,10 +724,11 @@ class SessionService : Service() {
|
||||
DeviceReport.write(this, File(sessionDir, "device.txt"), SessionState.mode)
|
||||
NetworkReport.write(this, File(sessionDir, "network.txt"))
|
||||
SessionLogCapture.start(File(sessionDir, "app.log"))
|
||||
MemoryLog.start()
|
||||
return sessionDir
|
||||
}
|
||||
|
||||
private fun addClientEnvironment(guest: MutableList<String>, steamHere: Boolean) {
|
||||
private fun addClientEnvironment(guest: MutableList<String>, steamHere: Boolean, agentEnvironment: List<String>) {
|
||||
guest.add("/usr/bin/env")
|
||||
guest.add("-i")
|
||||
guest.add("DROIDDECK_BWRAP_SOCKET=" + com.droiddeck.launcher.runtime.BwrapSpawner.socket(this))
|
||||
@@ -726,8 +781,8 @@ class SessionService : Service() {
|
||||
SessionArtifacts.recordClient(it, arch)
|
||||
SessionArtifacts.markSteamLogs(it, File(SessionPrefs.steamRoot(this, arch), "logs"))
|
||||
}
|
||||
if (arch == "x86_64") FexCatalog.cached(this)?.let { guest.addAll(FexCatalog.environment(it)) }
|
||||
}
|
||||
FexCatalog.cached(this)?.let { guest.addAll(FexCatalog.environment(it)) }
|
||||
if (SessionState.mode == MODE_STEAM) {
|
||||
guest.add("BL_GAMESCOPE_STRETCH_16X9=" + (if (SessionPrefs.stretch16x9(this)) "1" else "0"))
|
||||
}
|
||||
@@ -737,9 +792,14 @@ class SessionService : Service() {
|
||||
guest.add("BL_FSYNC_FIRST=" + (if (SessionPrefs.fsyncFirst(this)) "1" else "0"))
|
||||
guest.add("BL_GAMESCOPE_REALTIME=" + (if (SessionPrefs.gamescopeRealtime(this)) "1" else "0"))
|
||||
if (SessionPrefs.cursorComposite(this)) guest.add("BL_CURSOR_COMPOSITE=1")
|
||||
if (com.droiddeck.launcher.core.ZramSupport.supported()) guest.add("BL_ZRAM=1")
|
||||
if (com.droiddeck.launcher.core.ZramSupport.supported()) {
|
||||
guest.add("BL_ZRAM=1")
|
||||
if (steamHere) SessionPrefs.ramCapMb(this).takeIf { it > 0 }?.let { guest.add("BL_RAM_CAP_MB=$it") }
|
||||
if (!SessionPrefs.zramClient(this)) guest.add("BL_ZRAM_CLIENT=0")
|
||||
}
|
||||
SessionPrefs.vramCapMb(this).takeIf { it > 0 }?.let { guest.add("BL_VRAM_MB=$it") }
|
||||
guest.add("BANNER_AUDIO_DIRECT_DECAY=0")
|
||||
val extra = extraEnv() + com.droiddeck.launcher.agent.AgentEnv.beginSession(this)
|
||||
val extra = extraEnv() + agentEnvironment
|
||||
if (extra.none { it.startsWith("TU_DEBUG=") }) guest.add("$GAME_TU_DEBUG=" + (tuOverride ?: if (tuDriver) "sysmem" else ""))
|
||||
extra.forEach { guest.add(it) }
|
||||
com.droiddeck.launcher.gpu.TpUbwcHint.forThisDevice(this)?.let { guest.add("${com.droiddeck.launcher.gpu.TpUbwcHint.ENV}=$it") }
|
||||
@@ -752,10 +812,11 @@ class SessionService : Service() {
|
||||
}
|
||||
|
||||
private fun noSteamGame(): Boolean =
|
||||
SessionState.mode == MODE_RUN && SessionState.program in setOf(NoSteamLaunch.PROTON_RUN, NoSteamLaunch.EPIC)
|
||||
SessionState.mode == MODE_RUN && SessionState.program in setOf(NoSteamLaunch.PROTON_RUN, NoSteamLaunch.EPIC, NoSteamLaunch.BATTLENET)
|
||||
|
||||
private fun startAudio(guest: MutableList<String>, sessionDir: File): PulseAudioComponent {
|
||||
val wantsDirectAudio = (SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP || noSteamGame()) &&
|
||||
private fun startAudio(guest: MutableList<String>, sessionDir: File, directAudioPack: Boolean): PulseAudioComponent {
|
||||
val wantsDirectAudio = directAudioPack &&
|
||||
(SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP || noSteamGame()) &&
|
||||
SessionPrefs.directAudio(this)
|
||||
val wantsMic = SessionPrefs.micEnabled(this) &&
|
||||
checkSelfPermission(android.Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED
|
||||
@@ -824,7 +885,7 @@ class SessionService : Service() {
|
||||
SessionState.deckPad = deckBinds.isNotEmpty()
|
||||
if (wantsDeck && !SessionState.deckPad) Log.w(TAG, "deck pad: not available this session; the pad stays an Xbox 360 controller")
|
||||
logControllersAtStart()
|
||||
com.droiddeck.launcher.input.FakeInputWriter.setLowLatency(SessionPrefs.lowLatencyController(this), SessionPrefs.lowLatencyTouch(this))
|
||||
com.droiddeck.launcher.input.FakeInputWriter.setLowLatency(SessionPrefs.lowLatency(this))
|
||||
if (uinput) {
|
||||
guest.add("FAKE_EVDEV_UINPUT=1")
|
||||
if (SessionState.deckPad) {
|
||||
@@ -1052,6 +1113,7 @@ class SessionService : Service() {
|
||||
if (!stillSameProcess()) return
|
||||
val tree = descendants(prootPid)
|
||||
if (!stillSameProcess()) return
|
||||
saveWineRegistries(tree)
|
||||
android.os.Process.sendSignal(prootPid, 15)
|
||||
if (!waitForExit(prootPid, GRACE_MS)) {
|
||||
if (!stillSameProcess()) return
|
||||
@@ -1068,6 +1130,31 @@ class SessionService : Service() {
|
||||
if (killed > 0) Log.i(TAG, "swept $killed process(es) proot left behind")
|
||||
}
|
||||
|
||||
private fun clearCachedApps() {
|
||||
val app = applicationContext
|
||||
Thread({
|
||||
val before = MemoryReadout.availableMb()
|
||||
val result = runCatching { com.droiddeck.launcher.core.WirelessAdbFix.clearCachedApps(app) }
|
||||
val after = MemoryReadout.availableMb()
|
||||
result.onSuccess { Log.i(TAG, "cached apps closed: available memory $before -> $after MB") }
|
||||
.onFailure { Log.w(TAG, "cached apps not closed: ${it.message}") }
|
||||
}, "clear-cached-apps").start()
|
||||
}
|
||||
|
||||
private fun saveWineRegistries(tree: List<Pair<Int, Long>>) {
|
||||
val servers = tree.filter { (pid, started) ->
|
||||
readStat(pid)?.second == started && WineProcesses.isWineserver(
|
||||
runCatching { File("/proc/$pid/cmdline").readBytes() }.getOrNull(),
|
||||
runCatching { File("/proc/$pid/comm").readText() }.getOrNull(),
|
||||
)
|
||||
}
|
||||
if (servers.isEmpty()) return
|
||||
servers.forEach { (pid, _) -> android.os.Process.sendSignal(pid, 15) }
|
||||
val deadline = System.currentTimeMillis() + WINE_SAVE_MS
|
||||
val saved = servers.count { (pid, _) -> waitForExit(pid, (deadline - System.currentTimeMillis()).coerceAtLeast(0)) }
|
||||
Log.i(TAG, "wineserver registry save: $saved of ${servers.size} exited after SIGTERM")
|
||||
}
|
||||
|
||||
private fun descendants(root: Int): List<Pair<Int, Long>> {
|
||||
val started = HashMap<Int, Long>()
|
||||
val children = HashMap<Int, MutableList<Int>>()
|
||||
@@ -1347,6 +1434,11 @@ class SessionService : Service() {
|
||||
}
|
||||
return
|
||||
}
|
||||
if (path == com.droiddeck.launcher.runtime.BattleNet.FEX_REQUEST) {
|
||||
File(dir, path).delete()
|
||||
com.droiddeck.launcher.runtime.BattleNet.answerFexRequest(this@SessionService, dir)
|
||||
return
|
||||
}
|
||||
if (path != null && path.startsWith("desktop-import-") && path.endsWith(".request")) {
|
||||
val request = File(dir, path)
|
||||
val text = runCatching { request.readText() }.getOrNull() ?: return
|
||||
@@ -1466,6 +1558,9 @@ class SessionService : Service() {
|
||||
SessionPrefs.SUSPEND_MANUAL -> manualPauseRequested && prepared && !downloadsBlockingSuspend
|
||||
else -> false
|
||||
}
|
||||
// A frozen game never sends the stop for a held rumble, so the keepalive would run on.
|
||||
val quietRumble = !screenOn || shouldSuspend || SessionState.suspended
|
||||
components.forEach { (it as? RumbleComponent)?.quiet(quietRumble) }
|
||||
if (freezePending && !shouldSuspend && !freezeCancelled) {
|
||||
freezeCancelled = true
|
||||
controller.cancelFreeze()
|
||||
@@ -1630,6 +1725,8 @@ class SessionService : Service() {
|
||||
runCatching { com.droiddeck.launcher.agent.AgentEnv.endSession(this) }
|
||||
.onFailure { Log.w(TAG, "clearing the agent's session environment", it) }
|
||||
releaseLocks()
|
||||
MemoryLog.stop()
|
||||
com.droiddeck.launcher.core.BackgroundAppLimit.restoreAsync(applicationContext)
|
||||
if (status == 0) {
|
||||
SessionEvents.transition(SessionPhase.IDLE, "session.stopped", mapOf("status" to status))
|
||||
} else {
|
||||
@@ -1683,7 +1780,8 @@ class SessionService : Service() {
|
||||
updateDownloadMonitoring()
|
||||
val stoppedGen = sessionGen
|
||||
val stoppedSession = SessionState.sessionId
|
||||
val launcherEnded = SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP || SessionState.program == NoSteamLaunch.EPIC
|
||||
val launcherEnded = SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP || SessionState.program == NoSteamLaunch.EPIC ||
|
||||
SessionState.program == NoSteamLaunch.BATTLENET
|
||||
SessionState.stopRequested = false
|
||||
GpuClockPin.stop(this)
|
||||
GameThreadHints.stop()
|
||||
@@ -1743,6 +1841,9 @@ class SessionService : Service() {
|
||||
private fun importLauncherGames() {
|
||||
runCatching { com.droiddeck.launcher.stores.epic.EpicClientLibrary.importClientGames(this) }
|
||||
.onFailure { Log.w(TAG, "client library scan failed: ${it.javaClass.simpleName}") }
|
||||
runCatching { com.droiddeck.launcher.stores.battlenet.BattleNetClient.syncAccount(this) }
|
||||
.onFailure { Log.w(TAG, "Battle.net sign-in check failed: ${it.javaClass.simpleName}") }
|
||||
com.droiddeck.launcher.stores.StoresState.notifyLibraryChanged(this)
|
||||
}
|
||||
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
@@ -1990,6 +2091,7 @@ class SessionService : Service() {
|
||||
private val STRAGGLERS = listOf("droiddeck-session", "gamescope", "Xwayland", "steamrtarm64",
|
||||
"steamwebhelper", "linuxfs/opt/android-host/proot", "/libproot.so", "pulseaudio/libpulseaudio.so")
|
||||
private const val GRACE_MS = 1200L
|
||||
private const val WINE_SAVE_MS = 3000L
|
||||
private const val STEAM_PICKUP_MS = 1500L
|
||||
private const val STEAM_EXIT_MS = 10_000L
|
||||
private const val GAME_LAUNCH_RETRY_MS = 250L
|
||||
@@ -2021,6 +2123,7 @@ class SessionService : Service() {
|
||||
fun start(
|
||||
context: Context, mode: String = MODE_STEAM, program: String? = null,
|
||||
steamUi: String? = null, steamUrl: String? = null, programArgs: Array<String>? = null,
|
||||
gameId: String? = null,
|
||||
displayId: Int = Display.DEFAULT_DISPLAY,
|
||||
) {
|
||||
SessionState.activityDisplayId = displayId
|
||||
@@ -2031,6 +2134,7 @@ class SessionService : Service() {
|
||||
if (programArgs != null) intent.putExtra(EXTRA_PROGRAM_ARGS, programArgs)
|
||||
if (steamUi != null) intent.putExtra(EXTRA_STEAM_UI, steamUi)
|
||||
if (steamUrl != null) intent.putExtra(EXTRA_STEAM_URL, steamUrl)
|
||||
if (gameId != null) intent.putExtra(EXTRA_GAME_ID, gameId)
|
||||
if (Build.VERSION.SDK_INT >= 26) context.startForegroundService(intent)
|
||||
else context.startService(intent)
|
||||
}
|
||||
|
||||
@@ -62,6 +62,8 @@ object SessionState {
|
||||
@Volatile
|
||||
var programArgs: List<String> = emptyList()
|
||||
@Volatile
|
||||
var gameId: String? = null
|
||||
@Volatile
|
||||
var steamUi: String? = null
|
||||
@Volatile
|
||||
var steamUrl: String? = null
|
||||
@@ -104,9 +106,6 @@ object SessionState {
|
||||
@Volatile
|
||||
var upscaleRatio: Float = 0f
|
||||
|
||||
@Volatile
|
||||
var fpsLimit: Int = 0
|
||||
|
||||
@Volatile
|
||||
var firstFrameSeen = false
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@ object SettingsReset {
|
||||
"orientation", "launcherFullscreen", "animations", "theme", "runSteamAtStartup", "addedGamesArt",
|
||||
"gameStoresEnabled", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature",
|
||||
"storesInstallLanguage",
|
||||
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "backActionsInverted", "touch", "osc", "shape", "steamController",
|
||||
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "backActionsInverted", "backDoubleTapMs", "touch", "osc", "shape", "steamController",
|
||||
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "unfoldedControlsWithController",
|
||||
"stretch16x9", "picturePosition",
|
||||
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
|
||||
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime",
|
||||
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "ramCapMb", "vramCapMb", "zramClient",
|
||||
"directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus",
|
||||
"noXalia", "fastSync", "fsyncFirst", "syncFallback", "prootNoSeccomp", "prootFastPath", "cursorComposite",
|
||||
"guestHostname", "fexPreset", "forceSsbs", "logs", "storageDiagnostics",
|
||||
@@ -29,7 +29,7 @@ object SettingsReset {
|
||||
)
|
||||
|
||||
internal val SESSION_PREFIXES = listOf(
|
||||
"resolutionCap.", "displayResolution.", "customRes.", "hdr.", "fpsLimit.", "suspendPolicy.",
|
||||
"resolutionCap.", "displayResolution.", "customRes.", "hdr.", "fpsLimit.", "performanceMode.", "suspendPolicy.",
|
||||
)
|
||||
|
||||
private val STEAM_TOUCH_KEYS = listOf("feedback", "autoFade", "gyro", "shake")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
internal object WineProcesses {
|
||||
private const val WINESERVER = "wineserver"
|
||||
|
||||
fun isWineserver(cmdline: ByteArray?, comm: String?): Boolean {
|
||||
val program = cmdline?.let { bytes ->
|
||||
val end = bytes.indexOf(0.toByte()).let { if (it < 0) bytes.size else it }
|
||||
String(bytes, 0, end, Charsets.UTF_8).substringAfterLast('/')
|
||||
}
|
||||
return program == WINESERVER || comm?.trim() == WINESERVER
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user