mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
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.
This commit is contained in:
1 parent
f27d0b006f
commit
32c85dfba1
5 files changed
+20
-13
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()) }
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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() }
|
||||
|
||||
Reference in new issue
Block a user