diff --git a/README.md b/README.md index 1473653c81..22fe4e442d 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Before Steam launches, you must turn off **Restrict child processes** in Develop ## Community -Join the [DroidDeck Discord](https://discord.gg/JRGAvawjsm) for help, Preview builds, and device reports. Bug reports go in its **#bug-reports** forum; attach the session folder from `Download/DroidDeck/` so the logs come with it. +Join the [DroidDeck Discord](https://discord.gg/JRGAvawjsm) for help, Preview builds, and device reports. Bug reports go in its **#bug-reports** forum; attach the zip from **Share logs** (Setup, or the session drawer) so the logs come with it. ## Build @@ -29,7 +29,7 @@ Run `tools/build_local.sh` with Docker, Java 17, the Android SDK/NDK, and `zstd` ## Limits -Compatibility and performance vary by device; hardware validation is limited. Desktop compositing uses software rendering. Firefox sandboxing is reduced under proot. See the session logs in `Download/DroidDeck/` when diagnosing problems. +Compatibility and performance vary by device; hardware validation is limited. Desktop compositing uses software rendering. Firefox sandboxing is reduced under proot. Logs are kept app-private (`files/logs/`, the last 30 sessions); **Share logs** packs the newest session, with the stores and tool logs, into one scrubbed zip. ## Credits and licence diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index aff3514d1b..0ef2f323b5 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -868,6 +868,8 @@ class MainActivity : ComponentActivity() { if (wanted.isNotEmpty()) requestPermissions(wanted.toTypedArray(), 1) // A session folder left without its ending - the process was killed - gets it now. if (!SessionState.running) Thread({ + com.droiddeck.launcher.session.LogMigration.run(this) + SessionLogShare.clear(this) SessionArtifacts.finishAbandoned(this) SessionArtifacts.scrubOlder(this) SessionArtifacts.prune(this) diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt index 80648e8875..2b8ba775b0 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.agent +import com.droiddeck.launcher.session.SessionPaths import android.Manifest import android.content.ContentProvider import android.content.ContentValues @@ -107,7 +108,7 @@ class AgentBridgeProvider : ContentProvider() { private fun state(context: Context): JSONObject { val runtimeVersion = LinuxRuntimeInstaller.installedVersion(context) - val dir = SessionState.logDirectory ?: SessionState.logFile?.parentFile ?: latestSessionDirectory() + val dir = SessionState.logDirectory ?: SessionState.logFile?.parentFile ?: SessionPaths.sessionFolders(context).lastOrNull() val session = JSONObject() .put("id", SessionState.sessionId ?: dir?.name ?: JSONObject.NULL) .put("phase", SessionState.phase.name) @@ -163,12 +164,6 @@ class AgentBridgeProvider : ContentProvider() { .put("session", session) } - private fun latestSessionDirectory(): File? { - val parent = LinuxRuntime.debugLogDir() - return parent.listFiles { file -> file.isDirectory && file.name.startsWith("session-") } - ?.maxWithOrNull(compareBy { it.lastModified() }.thenBy { it.name }) - } - private fun stop(context: Context): JSONObject { if (SessionState.running) { SessionService.stop(context) diff --git a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt index bac157b82e..b406212b41 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt @@ -212,6 +212,46 @@ object LogRedactor { src.forEachLine { line -> out.write(redact(line)); out.write("\n") } } + private val URL_IN_TEXT = Regex("""[A-Za-z][A-Za-z0-9+.\-]*://[^\s"'<>]+""") + /** A path segment that carries a signed token (a GOG secure link puts its token in the path). */ + private val TOKEN_SEGMENT = Regex("""(?i)(token|hdnts|hmac|signature|sig|exp)=""") + private val SHARE_KV = Regex("""(?i)(?}]{6,}""") + private val HEADER = Regex("""(?i)\b(authorization|cookie|set-cookie)(\s*:\s*).+""") + + /** + * The last pass for a file going into a shared zip: [redact], then every URL without its query, + * fragment and user:password and with any path segment that carries a token blanked, then the + * token-like values [redact] does not know (`__token__`, `f_token`, `hdnts`, OAuth `code=`) and + * Authorization / Cookie headers. A line already clean comes out unchanged. + */ + fun redactForShare(line: String): String { + if (line.isEmpty()) return line + return try { + var out = redact(line) + out = URL_IN_TEXT.replace(out) { m -> shareUrl(m.value) } + out = SHARE_KV.replace(out) { "${it.groupValues[1]}${it.groupValues[2]}" } + out = HEADER.replace(out) { "${it.groupValues[1]}${it.groupValues[2]}" } + out + } catch (t: Throwable) { + "" + } + } + + private fun shareUrl(url: String): String { + val schemeEnd = url.indexOf("://") + val rest = url.substring(schemeEnd + 3).substringBefore('#').substringBefore('?') + val slash = rest.indexOf('/') + val authority = (if (slash >= 0) rest.substring(0, slash) else rest).substringAfterLast('@') + val path = if (slash >= 0) rest.substring(slash) else "" + val cleanPath = path.split('/').joinToString("/") { seg -> if (TOKEN_SEGMENT.containsMatchIn(seg)) "" else seg } + return url.substring(0, schemeEnd) + "://" + authority + cleanPath + } + + /** [src]'s lines through [redactForShare], to [out]: the pass every text file in a shared zip gets. */ + fun scrubForShare(src: java.io.File, out: java.io.Writer) { + src.forEachLine { line -> out.write(redactForShare(line)); out.write("\n") } + } + /** [line] with every credential shape replaced. Null- and exception-safe by construction. */ fun redact(line: String): String { if (line.isEmpty()) return line diff --git a/app/src/main/java/com/droiddeck/launcher/files/FileManagerScreen.kt b/app/src/main/java/com/droiddeck/launcher/files/FileManagerScreen.kt index 9f9361ad7b..46f2f708b2 100644 --- a/app/src/main/java/com/droiddeck/launcher/files/FileManagerScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/files/FileManagerScreen.kt @@ -1020,7 +1020,8 @@ fun FileManagerScreen( // The ROMs folder chosen on the main screen: what the session shows as /root/ROMs. SessionPrefs.romsDir(context).takeIf { it.isNotEmpty() }?.let(::File)?.takeIf { it.isDirectory } ?.let { add(locItem(stringResource(R.string.fm_rail_roms), Icons.Filled.SportsEsports, it)) } - File("/storage/emulated/0/Download/DroidDeck").takeIf { it.isDirectory }?.let { add(locItem(stringResource(R.string.fm_rail_session_logs), Icons.Filled.Description, it)) } + // The app's own logs folder: private, which this file manager (the app itself) can read. + com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context).takeIf { it.isDirectory }?.let { add(locItem(stringResource(R.string.fm_rail_session_logs), Icons.Filled.Description, it)) } File("/storage/emulated/0/Pictures").takeIf { it.isDirectory }?.let { add(locItem(stringResource(R.string.fm_rail_pictures), Icons.Filled.Image, it)) } } val favItems = remember(favTick) { FavoritesStore.list(context).map(::File).filter { it.exists() } } diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/FlatpakManager.kt b/app/src/main/java/com/droiddeck/launcher/runtime/FlatpakManager.kt index 8f31e2d2f1..c5c1fa6db6 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/FlatpakManager.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/FlatpakManager.kt @@ -87,7 +87,7 @@ object FlatpakManager { ?.maxByOrNull { it.first }?.second } - /** Runs [argv] in the runtime, its output also in Download/DroidDeck/flatpak-.log. */ + /** Runs [argv] in the runtime, its output also in files/logs/tools/flatpak-.log. */ private fun runGuest(context: Context, argv: List, fakeRoot: Boolean, onLine: (String) -> Unit): Int { val name = "flatpak-" + (argv.getOrNull(2)?.takeIf { argv.getOrNull(1) == HELPER } ?: "setup") return GuestCommand.run(context, argv, fakeRoot, name, onLine = onLine) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt b/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt index a5a653c3e8..286059588f 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt @@ -17,7 +17,7 @@ object GuestCommand { /** * Runs [argv] and hands each output line to [onLine]; returns the exit status. [fakeRoot] is * for the package tools, which refuse any uid but 0. With [logName], everything the command - * says also goes to Download/DroidDeck/tools/.log beside the session logs, so a problem can + * says also goes to files/logs/tools/.log beside the session logs, so a problem can * be handed over like a session's. With [linkDir], hard links (which Android denies apps) * become symlinks to files proot keeps there (its link2symlink). */ @@ -25,7 +25,7 @@ object GuestCommand { linkDir: File? = null, onLine: (String) -> Unit): Int { val log = logName?.let { try { - File(File(LinuxRuntime.debugLogDir(), SessionPaths.TOOLS_DIR).apply { mkdirs() }, "$it.log").printWriter() + File(File(LinuxRuntime.logDir(context), SessionPaths.TOOLS_DIR).apply { mkdirs() }, "$it.log").printWriter() } catch (e: Exception) { null } } log?.println("== ${java.util.Date()} ${argv.joinToString(" ")}") diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java index 38a33980a3..082bf814e9 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -44,10 +44,20 @@ public final class LinuxRuntime { public static final String GUEST_RUNTIME_DIR = "/run/droiddeck"; private static final String SYSTEM_FONTS = "/system/fonts"; private static final String GUEST_SYSTEM_FONTS = "/usr/local/share/fonts/android"; - /** Where every Linux session's debug log lands: public, so a user can just hand the folder over. */ + /** The folder under Downloads where builds before private logs wrote them; read only to move them. */ public static final String DEBUG_LOG_DIR = "DroidDeck"; - public static File debugLogDir() { + /** + * Where every log lands: app-private, {@code files/logs}. Session folders, tools/ (one-off + * commands) and stores/ sit under it; the files directory is bound into every session at the + * same path, so the guest writes there too. Share logs is how a folder leaves the device. + */ + public static File logDir(Context context) { + return new File(context.getFilesDir(), "logs"); + } + + /** {@code Download/DroidDeck}, where earlier builds wrote logs. Only LogMigration reads it. */ + public static File legacyLogDir() { return new File(android.os.Environment.getExternalStoragePublicDirectory( android.os.Environment.DIRECTORY_DOWNLOADS), DEBUG_LOG_DIR); } diff --git a/app/src/main/java/com/droiddeck/launcher/session/LogMigration.kt b/app/src/main/java/com/droiddeck/launcher/session/LogMigration.kt new file mode 100644 index 0000000000..e5e1ba6a04 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/LogMigration.kt @@ -0,0 +1,64 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import android.util.Log +import com.droiddeck.launcher.core.FileUtils +import com.droiddeck.launcher.runtime.LinuxRuntime +import java.io.File + +/** + * Once, on the first start of a build with private logs: the session folders, tools/ and the loose + * tool logs that earlier builds left in `Download/DroidDeck/` move into `files/logs/`. Best effort: + * an item that cannot be moved stays where it is. Nothing else in that folder is touched - game + * save backups (Saves/) stay public - and after this pass the app never reads it again. + */ +object LogMigration { + private const val TAG = "LogMigration" + private const val MARKER = ".moved-from-downloads" + + @Synchronized + fun run(context: Context) { + val target = LinuxRuntime.logDir(context).apply { mkdirs() } + val marker = File(target, MARKER) + if (marker.exists()) return + val legacy = LinuxRuntime.legacyLogDir() + val items = if (legacy.isDirectory) legacy.listFiles() else emptyArray() + // Unreadable (no storage access yet): try again next start rather than give up on them. + if (items == null) { Log.w(TAG, "$legacy cannot be listed; logs there stay until it can"); return } + var moved = 0 + for (f in items) { + val isLog = SessionPaths.isSessionFolder(f) || + (f.isDirectory && f.name == SessionPaths.TOOLS_DIR) || + (f.isFile && f.name.endsWith(".log")) + if (!isLog) continue + val dest = File(if (f.isFile) File(target, SessionPaths.TOOLS_DIR).apply { mkdirs() } else target, f.name) + if (dest.exists() && f.name != SessionPaths.TOOLS_DIR) continue + if (move(f, dest)) moved++ else Log.w(TAG, "could not move ${f.name}; left in place") + } + try { marker.writeText("moved $moved item(s)\n") } catch (e: Exception) { Log.w(TAG, "could not mark the move: ${e.message}") } + if (moved > 0) Log.i(TAG, "moved $moved log item(s) from $legacy into $target") + } + + /** A rename where it works (same volume), else a copy then the source's removal; false = left as it was. */ + private fun move(src: File, dest: File): Boolean { + if (src.renameTo(dest)) return true + return try { + copy(src, dest) + FileUtils.delete(src) + true + } catch (e: Exception) { + Log.w(TAG, "copy of ${src.name} failed: ${e.message}") + false + } + } + + private fun copy(src: File, dest: File) { + if (src.isDirectory) { + dest.mkdirs() + src.listFiles()?.forEach { copy(it, File(dest, it.name)) } + } else { + dest.parentFile?.mkdirs() + src.inputStream().use { input -> dest.outputStream().use { input.copyTo(it) } } + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 500c2f7d33..6c2c03fe52 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -38,9 +38,9 @@ object SessionArtifacts { * Written by a session's own ending, and only when every file in the folder, subfolders * included (whatever the session script copied into steam/ and droiddeck-esync/ as well as what * the app wrote), went through the redactor without a failure. It lists each of those files - * with its size and modification time, under the redactor's rules version: a share copies a - * file as it is only when all three still match ([scrubbedFiles]), and scrubs anything else - - * a file added or changed since, a hidden one, or every file of a folder without it. + * with its size and modification time, under the redactor's rules version ([scrubbedFiles]). + * A share no longer relies on it: every text file goes through the share pass on the way into + * the zip regardless. */ const val SCRUBBED_TREE_MARKER = ".scrubbed-tree" @@ -75,7 +75,7 @@ object SessionArtifacts { @Synchronized fun scrubOlder(context: Context) { val current = SessionPaths.current() - val dirs = LinuxRuntime.debugLogDir().listFiles { f -> + val dirs = LinuxRuntime.logDir(context).listFiles { f -> SessionPaths.isSessionFolder(f) && f != current && !File(f, SCRUBBED_MARKER).exists() } ?: return if (dirs.isEmpty()) return @@ -223,7 +223,7 @@ object SessionArtifacts { */ @Synchronized fun finishAbandoned(context: Context) { - val parent = LinuxRuntime.debugLogDir() + val parent = LinuxRuntime.logDir(context) val abandoned = parent.listFiles { f -> SessionPaths.isSessionFolder(f) && !File(f, COMPLETE_MARKER).exists() }?.sortedWith(SessionPaths.chronological) ?: return @@ -282,9 +282,7 @@ object SessionArtifacts { val current = SessionPaths.current() val gone = SessionPaths.sessionFolders(context).filter { it != current } gone.forEach { com.droiddeck.launcher.core.FileUtils.delete(it) } - com.droiddeck.launcher.core.FileUtils.delete(File(LinuxRuntime.debugLogDir(), SessionPaths.TOOLS_DIR)) - // Before tools/, those logs sat loose beside the session folders. - LinuxRuntime.debugLogDir().listFiles { f -> f.isFile && f.name.endsWith(".log") }?.forEach { it.delete() } + com.droiddeck.launcher.core.FileUtils.delete(File(LinuxRuntime.logDir(context), SessionPaths.TOOLS_DIR)) Log.i(TAG, "cleared ${gone.size} session folder(s)") return gone.size } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 04dc792606..e768b6f69a 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -361,25 +361,9 @@ object SessionFiles { ).joinToString(newline) /** - * Where the session writes its log. Downloads is the point - a failed run is handed over as a - * folder rather than dug out of app-private storage - but the session script redirects its own - * output there with `exec`, and a redirection a non-interactive shell cannot open ends that - * shell. So a public directory is used only once it is proven writable; otherwise the app's - * own files directory, which is bound into the session anyway, stands in. + * Where the session writes its log: app-private `files/logs`, bound into the session at the same + * path, so the session script's own redirection always opens. A folder leaves the device only + * through Share logs, which scrubs every file again on the way into the zip. */ - fun logDirectory(context: Context): File { - val public = LinuxRuntime.debugLogDir() - if (public.isDirectory || public.mkdirs()) { - val probe = File(public, ".writable") - try { - if (probe.createNewFile() || probe.isFile) { - probe.delete() - return public - } - } catch (ignored: Exception) { - } - } - Log.w(TAG, "$public is not writable (storage permission?); logging to files/logs") - return File(context.filesDir, "logs").apply { mkdirs() } - } + fun logDirectory(context: Context): File = LinuxRuntime.logDir(context).apply { mkdirs() } } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt index c12a69f39d..85760c8224 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt @@ -18,9 +18,11 @@ import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream /** - * Zips the most recent session's log folder and hands it to Android's share sheet. Works where - * the folder could not be written to Downloads (no storage permission, or a device that refuses - * it) and landed in the app's private files instead, which a user cannot otherwise reach. + * Share logs: one zip, made when asked, of a session folder (the newest by default) with the last + * seven days of the stores' log and the one-off command logs beside it, handed to Android's share + * sheet. Logs live in app-private `files/logs`; this is how they leave the device. Every text file + * goes through [LogRedactor.redactForShare] on the way in, so even a file written before a rule + * existed is clean in the zip. The zip sits in `cache/share/` until the next share or app start. */ object SessionLogShare { private val main = Handler(Looper.getMainLooper()) @@ -62,7 +64,7 @@ object SessionLogShare { val files = folder.walkTopDown().filter { it.isFile } .filterNot { it.parentFile?.name == "steam" && it.length() > STEAM_LOG_MAX_BYTES }.toList() if (files.isEmpty()) return null - val out = File(context.cacheDir, "shared-logs").apply { deleteRecursively(); mkdirs() } + val out = shareDir(context).apply { deleteRecursively(); mkdirs() } val zip = File(out, "DroidDeck-${folder.name}.zip") // Scrubbed on the way into the zip: a session shared while it runs has not had its end-of- // session pass yet, and the redactor changes nothing in a line that is already clean. @@ -71,11 +73,11 @@ object SessionLogShare { // since, goes in as it is; anything else (added or changed since, hidden, or any file of a // session still running) is scrubbed again. Scrubbing tens of MB of the client's logs on // every share kept the share sheet from appearing for ten seconds or more. - val scrubbed = SessionArtifacts.scrubbedFiles(folder) val live = liveSteamLogs(context, folder) - // The stores' own log (last 7 days, app-private, already redacted), under stores/. - val storeLogs = com.droiddeck.launcher.stores.StoreLogFiles.files(context) - val total = (files + live + storeLogs).sumOf { it.length() }.coerceAtLeast(1L) + 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) var done = 0L var shown = -1 fun advance(f: File) { @@ -84,18 +86,20 @@ object SessionLogShare { if (percent != shown) { shown = percent; onProgress?.invoke(percent / 100f) } } ZipOutputStream(zip.outputStream().buffered()).use { z -> - files.forEach { f -> addEntry(z, folder.name + "/" + f.relativeTo(folder).path, f, f.relativeTo(folder).path in scrubbed); advance(f) } - live.forEach { f -> addEntry(z, folder.name + "/steam/" + f.name, f, false); advance(f) } - storeLogs.forEach { f -> addEntry(z, folder.name + "/stores/" + f.name, f, false); advance(f) } + files.forEach { f -> addEntry(z, folder.name + "/" + f.relativeTo(folder).path, f); advance(f) } + 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) } } return zip } - private fun addEntry(z: ZipOutputStream, name: String, f: File, scrubbed: Boolean) { + private fun addEntry(z: ZipOutputStream, name: String, f: File) { z.putNextEntry(ZipEntry(name)) - if (!scrubbed && LogRedactor.isText(f)) { + // Every text file, every time: the folder's own scrub may predate a rule. + if (LogRedactor.isText(f)) { val w = z.bufferedWriter() - LogRedactor.scrubTo(f, w) + LogRedactor.scrubForShare(f, w) w.flush() } else { f.inputStream().use { it.copyTo(z) } @@ -119,6 +123,25 @@ object SessionLogShare { /** The client's content and bootstrap logs grow large over months and say nothing about a session. */ private const val STEAM_LOG_MAX_BYTES = 8L * 1024 * 1024 + /** The stores' engine log, one file a day, under files/logs. */ + const val STORES_DIR = "stores" + private const val RECENT_DAYS = 7 + + private fun shareDir(context: Context): File = File(context.cacheDir, "share") + + /** The files in [dir] changed in the last [RECENT_DAYS] days. */ + private fun recent(dir: File): List { + val since = System.currentTimeMillis() - RECENT_DAYS * 86_400_000L + return dir.listFiles { f -> f.isFile && f.lastModified() >= since }?.sortedBy { it.name }.orEmpty() + } + + /** Deletes the last share's zip; at app start, so a zip never outlives the share it was made for. */ + fun clear(context: Context) { + shareDir(context).deleteRecursively() + // Where builds before this one put it. + File(context.cacheDir, "shared-logs").deleteRecursively() + } + fun shareIntent(context: Context, zip: File): Intent { val uri = FileProvider.getUriForFile(context, context.packageName + ".logs", zip) val send = Intent(Intent.ACTION_SEND) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt index 2b8f38eec4..5b94c6a44c 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt @@ -8,19 +8,20 @@ import java.util.Date import java.util.Locale /** - * One folder per session under `Download/DroidDeck/`, holding everything that session recorded, + * One folder per session under app-private `files/logs/`, holding everything that session recorded, * named for the day, that day's session number and what was run, so the one a report is about can * be picked out without opening any: * * ``` - * Download/DroidDeck/2026-09-30-03-steam/ + * files/logs/2026-09-30-03-steam/ * device.txt what this device is, and every setting the session ran with * session.log the guest session: proot, gamescope, the client's stdout * wayland.log the app's compositor * steam.log the Steam client's own log, scrubbed (Steam mode) * steam/ the rest of the client's logs, scrubbed (Steam mode) * desktop.log KWin, Plasma and the programs on it (desktop mode) - * Download/DroidDeck/tools/ one-off commands: Flatpak installs, AppImage imports + * files/logs/tools/ one-off commands: Flatpak installs, AppImage imports + * files/logs/stores/ the stores' engine log, one file a day * ``` * * Folders from before this naming (`session-20260930-180642`) are still recognised, shared and @@ -137,8 +138,7 @@ object SessionPaths { /** Every session folder in the places logs are written, oldest first. */ fun sessionFolders(context: Context): List = - listOf(com.droiddeck.launcher.runtime.LinuxRuntime.debugLogDir(), File(context.filesDir, "logs")) - .flatMap { parent -> parent.listFiles { f -> isSessionFolder(f) }?.toList() ?: emptyList() } + (com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context).listFiles { f -> isSessionFolder(f) }?.toList() ?: emptyList()) .sortedWith(chronological) internal fun slug(text: String): String = diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 2fd7b05c59..af23de85c2 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -493,7 +493,7 @@ object SessionPrefs { } /** - * Whether a session writes its folder under Download/DroidDeck. Off, the same logs are kept in + * Whether a session keeps its folder under files/logs. Off, the same logs are kept in * the app's cache for the session's lifetime (the scripts need somewhere to write) and thrown * away at the end, so nothing accumulates in Downloads. */ diff --git a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt index 850ef5059c..b4a0ef751d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt @@ -398,7 +398,7 @@ object WinComponents { * Downloads the component's package (.msi) or installer (.exe) into the runtime and has * droiddeck-msi-install lay it out in [staging]. Returns the installer's result (product, * version, counts, notes), or null and why. Everything the installer prints also goes to - * Download/DroidDeck/tools. + * files/logs/tools. */ private fun installPackage(context: Context, c: Component, step: Step, staging: File, onProgress: (Progress) -> Unit): Pair { val root = LinuxRuntime.rootDir(context) diff --git a/app/src/main/res/xml/log_share_paths.xml b/app/src/main/res/xml/log_share_paths.xml index cc98eee1e5..9bed7b6831 100644 --- a/app/src/main/res/xml/log_share_paths.xml +++ b/app/src/main/res/xml/log_share_paths.xml @@ -1,4 +1,4 @@ - + diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index 39978490a6..1d58f179fa 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -33,12 +33,13 @@ class SessionLogShareTest { "rules $rules\n" + files.joinToString("") { val f = File(folder, it); "${f.length()}\t${f.lastModified()}\t$it\n" }) } - @Test fun aRecordedUnchangedFileGoesInAsItIs() { + @Test fun aRecordedUnchangedFileIsScrubbedAgainOnTheWayIntoTheZip() { val folder = tmp.newFolder("2026-10-06-01-steam") - // Stands in for a file the ending scrubbed; the share must not pass it through again. + // A file the ending recorded as scrubbed still gets the share's final pass: the record + // may predate a rule, and a zip is the one way a log leaves the device. File(folder, "session.log").writeText("$secret\n") record(folder, "session.log") - assertTrue(zip(folder).getValue("session.log").contains(leaked)) + assertFalse(zip(folder).getValue("session.log").contains(leaked)) } @Test fun anythingTheRecordDoesNotVouchForIsScrubbed() { diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt new file mode 100644 index 0000000000..319b9ef3a9 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -0,0 +1,55 @@ +package com.droiddeck.launcher.session + +import com.droiddeck.launcher.runtime.LinuxRuntime +import java.io.File +import java.util.zip.ZipFile +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +/** A shared zip is scrubbed on the way in, whatever the files on disk still hold. */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33]) +class SessionLogShareZipTest { + private val app get() = RuntimeEnvironment.getApplication() + + @Test fun everyTextFileInTheZipIsScrubbedAndTheStoresAndToolsLogsComeAlong() { + val logs = LinuxRuntime.logDir(app) + val session = File(logs, "2026-10-08-01-steam").apply { mkdirs() } + // Written raw, as a file from before a rule existed would be. + File(session, "session.log").writeText( + "fetch https://gog-cdn-fastly.gog.com/token=nva=1791500000~dirs=/x~token=0a1b2c3d4e5f/content-system/v2/store/1/ab/cd/f\n" + + "fetch https://epicgames-download1.akamaized.net/Builds/Org/a/ChunksV4/12/ABCD.chunk?__token__=exp=1~hmac=deadbeefcafe\n" + + "login refresh_token=abcdef123456 user someone@example.com code=AUTHCODE123\n" + + "Authorization: Bearer abc.def.ghi\n" + + "kept: EResult 5, app 1086940, steamapps/common/Game\n" + ) + File(logs, "stores").apply { mkdirs() }.resolve("stores-2026-10-08.log").writeText("epic: f_token=zzzzzzzz12 window 32\n") + File(logs, SessionPaths.TOOLS_DIR).apply { mkdirs() }.resolve("flatpak-install.log").writeText("== install\nCookie: steamLoginSecure=76561198000000000%7C%7Ceyabc\n") + + val zip = SessionLogShare.zipFolder(app, session)!! + assertTrue(zip.path.startsWith(File(app.cacheDir, "share").path)) + val text = ZipFile(zip).use { z -> z.entries().toList().associate { e -> e.name to z.getInputStream(e).bufferedReader().readText() } } + assertTrue(text.keys.containsAll(listOf("2026-10-08-01-steam/session.log", "stores/stores-2026-10-08.log", "tools/flatpak-install.log"))) + val all = text.values.joinToString("\n") + for (secret in listOf("0a1b2c3d4e5f", "deadbeefcafe", "abcdef123456", "someone@example.com", "AUTHCODE123", "abc.def.ghi", "zzzzzzzz12", "eyabc")) { + assertFalse("$secret survived", all.contains(secret)) + } + // What makes a log worth reading stays. + assertTrue(all.contains("kept: EResult 5, app 1086940, steamapps/common/Game")) + assertTrue(all.contains("https://gog-cdn-fastly.gog.com/")) + + SessionLogShare.clear(app) + assertFalse(zip.exists()) + } + + @Test fun theSharePassChangesNothingInACleanLine() { + val line = "dxvk: Device 0x5 (Adreno 750) https://github.com/doitsujin/dxvk/releases code 403" + assertEquals(line, com.droiddeck.launcher.core.LogRedactor.redactForShare(line)) + } +} diff --git a/docs/development/flatpak.md b/docs/development/flatpak.md index 7ed3ae7257..dd7faae506 100644 --- a/docs/development/flatpak.md +++ b/docs/development/flatpak.md @@ -22,7 +22,7 @@ The script then unpacks them without hooks and checks what the binaries link. Li the Desktop package normally brings (PyGObject, json-glib, fuse3 and others) are fetched too, but only when their files are missing. Flathub is added as a per-user remote from a copy of its `.flatpakrepo` carried in the script, so that step needs no network. Every store command -writes its output to `Download/DroidDeck/flatpak-.log`, next to the session logs. The +writes its output to `files/logs/tools/flatpak-.log`, next to the session logs. The setup script also puts Flatpak's own error text in the failure message the app shows. ## bubblewrap without namespaces diff --git a/docs/progress-log.md b/docs/progress-log.md index 4c67247a6b..c2763adbd5 100644 --- a/docs/progress-log.md +++ b/docs/progress-log.md @@ -7,6 +7,28 @@ the timeline, then lessons and backlog. Companion to the README (what the app *d --- +## 2026-10-08 - `feat/private-logs`: every log in app-private storage, shared as one scrubbed zip + +- **Where logs live:** `files/logs/` (`LinuxRuntime.logDir`), nothing under `Download/DroidDeck` + any more. Session folders (`-NN-/`), `tools/` (GuestCommand, Flatpak, Windows + component installers) and `stores/` (the stores' engine log, one file a day) all sit there. The + files directory is bound into every session at the same path, so the session script, gamescope + and the guest tools write there as before. Thirty sessions kept; the Logs switch off still means + a cache folder deleted at session end. Game save backups stay public in `Download/DroidDeck/Saves`. +- **Moving the old ones:** on the first start of this build, session folders, `tools/` and loose + `*.log` files move from `Download/DroidDeck/` into `files/logs/` (rename, else copy and delete; + an item that fails stays). A marker records the pass; `Saves/` and anything else there is never + touched, and the app does not read `Download/DroidDeck/` again. +- **Share logs:** one zip in `cache/share/`, made on demand: the newest session folder (or the one + the session screen shares), the last seven days of `stores/` and `tools/`. Every text file goes + through `LogRedactor.redactForShare` on the way in - the existing rules (Steam tokens, JWTs, + SteamIDs, account names, emails, own addresses, MACs, serials) plus URLs without query, fragment + or userinfo and with token-bearing path segments blanked (GOG secure links), `__token__`, + `f_token`, `hdnts`, OAuth `code=`, and Authorization / Cookie headers - so a file written before a + rule existed is clean in the zip. The zip is deleted at the next share or app start. + `SessionLogShareTest` covers it. Nothing was relaxed: the per-session scrub, `scrubOlder` and + every existing rule stay as they were. +- **File manager:** the Session logs shortcut opens `files/logs` (the app reads its own storage). ## 2026-10-08 - `feat/stores`: GOG, Epic Games and Amazon Games in the launcher (in progress) A new **Stores** section - the three storefronts' libraries and public catalogs, one download