From 32c85dfba13c26a7dd09b6869d102f94bff405f0 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:56:09 -0400 Subject: [PATCH] fix(xbox): put the helper's sign-in failure code in the shared log (#1342) A user's log (#1300) showed "the Xbox helper stopped with exit code 1", but not why. Before it asks for the Microsoft page the helper can only fail while opening the credential store or registering the device, and it prints a code for that (NEXUS_CREDENTIAL_ERROR_V1 keyring-unavailable, device- authentication, ...). Sign-in runs in its own process, where StoresState.logLine writes no file, so that line only reached logcat. The sign-in window now writes the helper's known diagnostics to the stores log itself, and the credential bridge writes why it refused the helper there too. Lines are stamped by a shared StoreLogFiles.stamped. --- .../com/droiddeck/launcher/stores/StoreLogFiles.kt | 5 +++++ .../java/com/droiddeck/launcher/stores/StoresState.kt | 7 +------ .../droiddeck/launcher/stores/xbox/XboxCredentials.kt | 10 ++++++++-- .../launcher/stores/xbox/XboxLoginActivity.kt | 6 +++--- .../java/com/droiddeck/launcher/stores/xbox/Xodus.kt | 5 +++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt index 0af6590120..bd94cfc3bc 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt @@ -24,6 +24,11 @@ object StoreLogFiles { Thread({ android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND); r.run() }, "store-log-flush").apply { isDaemon = true } } + private val CLOCK = SimpleDateFormat("HH:mm:ss.SSS", Locale.US) + + /** Appends [text] with a time stamp. Works in any of the app's processes. */ + fun stamped(context: Context, text: String) = append(context, "${synchronized(CLOCK) { CLOCK.format(Date()) }} $text") + fun append(context: Context, line: String) { val app = context.applicationContext pending.add(line) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt index a28b0e8a48..317757a8bf 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt @@ -10,9 +10,6 @@ import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import com.droiddeck.launcher.stores.download.DownloadEntry -import java.text.SimpleDateFormat -import java.util.Date -import java.util.Locale object StoresState { private const val TAG = "Stores" @@ -262,7 +259,7 @@ object StoresState { val text = StoreLog.redactLine(raw) Log.i(TAG, text) val app = appContext ?: return - StoreLogFiles.append(app, "${synchronized(CLOCK) { CLOCK.format(Date()) }} $text") + StoreLogFiles.stamped(app, text) } private var appContext: Context? = null @@ -295,8 +292,6 @@ object StoresState { } }, name).start() } - - private val CLOCK = SimpleDateFormat("HH:mm:ss.SSS", Locale.US) } interface StoreBackend { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCredentials.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCredentials.kt index 40cd28225b..ffe4b9de6b 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCredentials.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxCredentials.kt @@ -29,10 +29,16 @@ internal class XboxCredentials(private val app: Context, expectedGeneration: Str } private fun rejected(reason: String): Boolean { - android.util.Log.w("XboxCredentials", "Rejected credential peer: $reason") + note("Rejected credential peer: $reason") return false } + /** Also written to the stores log: sign-in runs in its own process, where only that file reaches a shared log. */ + private fun note(text: String) { + android.util.Log.w("XboxCredentials", text) + com.droiddeck.launcher.stores.StoreLogFiles.stamped(app, "Xbox credentials: $text") + } + private fun authorized(pid: Int): Boolean { if (!bound.await(5, java.util.concurrent.TimeUnit.SECONDS) || closed) return rejected("unbound") val process = backend ?: return rejected("missing-child") @@ -88,7 +94,7 @@ internal class XboxCredentials(private val app: Context, expectedGeneration: Str answer(request) } }.getOrElse { - android.util.Log.w("XboxCredentials", "Credential request rejected: ${it.javaClass.simpleName}") + note("Credential request rejected: ${it.javaClass.simpleName}") JSONObject().put("ok", false) } runCatching { it.outputStream.write((reply.toString() + "\n").toByteArray()) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxLoginActivity.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxLoginActivity.kt index 218ab26ffc..bdfb27d09a 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxLoginActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/XboxLoginActivity.kt @@ -63,7 +63,8 @@ class XboxLoginActivity : ComponentActivity() { Xodus.start(applicationContext, listOf("--external-webview-stdio", "login"), credentialGeneration = accountGeneration).use { process -> child = process if (closed) return@use - Xodus.diagnostics(process) + // StoresState.logLine writes no file in this process, so the reason would miss the shared log. + Xodus.diagnostics(process) { logStep(it) } progress("waiting for the Xbox helper", "Waiting for the Xbox helper…") val timer = Thread({ runCatching { if (!process.process.waitFor(10, TimeUnit.MINUTES)) process.process.destroy() } @@ -153,8 +154,7 @@ class XboxLoginActivity : ComponentActivity() { private fun logStep(line: String) { val text = StoreLog.redactLine("Xbox sign-in: $line") Log.i(TAG, text) - val time = java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", java.util.Locale.US).format(java.util.Date()) - StoreLogFiles.append(applicationContext, "$time $text") + StoreLogFiles.stamped(applicationContext, text) } @SuppressLint("SetJavaScriptEnabled") diff --git a/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt b/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt index cf7686e0dd..fde5b0650c 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/xbox/Xodus.kt @@ -133,11 +133,12 @@ internal object Xodus { } } - fun diagnostics(child: Child): Thread = Thread({ + /** Passes the backend's known stderr diagnostics to [report]; other stderr text never leaves the process. */ + fun diagnostics(child: Child, report: (String) -> Unit = { com.droiddeck.launcher.stores.StoresState.logLine("Xbox: $it") }): Thread = Thread({ runCatching { child.process.errorStream.bufferedReader().useLines { lines -> lines.forEach { line -> if (line.matches(Regex("NEXUS_CREDENTIAL_ERROR_V1 [a-z-]{1,48}|NEXUS_LIBRARY_DIAGNOSTIC_V1 [a-z-]{1,48} [0-9]{1,3} [0-9]{1,6}|NEXUS_SESSION_DIAGNOSTIC_V1 [a-z-]{1,64}|Account library unavailable \\([a-z-]{1,64}\\); credentials and installed games are unchanged\\.|Account library timed out; installed games are unchanged\\.|Xbox profile is temporarily unavailable \\([a-z-]{1,48}\\); stored account is unchanged\\.|Xbox profile request timed out; stored account is unchanged\\."))) - com.droiddeck.launcher.stores.StoresState.logLine("Xbox: $line") + report(line) } } } }, "xbox-diagnostics").apply { start() }