mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(droiddeckctl): logs latest works without root
`logs latest` pulled the session folder under getFilesDir(), which adb cannot read on an unrooted device, so it always failed with "Permission denied" and droiddeck-scenario kept no logs for failed runs. The agent bridge gets a `logs` method that writes the Share logs archive to the app's external files folder (agent-logs/), and droiddeckctl pulls that zip and unpacks it into the destination with the session's files at the top, as before. Builds without the method still get the old pull.
This commit is contained in:
1 parent
4b6cba0a6d
commit
2fb066507a
7 files changed
+128
-6
No files matched your search
@@ -18,6 +18,7 @@ import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntimeInstaller
|
||||
import com.droiddeck.launcher.session.SessionArtifacts
|
||||
import com.droiddeck.launcher.session.SessionEvents
|
||||
import com.droiddeck.launcher.session.SessionLogShare
|
||||
import com.droiddeck.launcher.session.SessionPhase
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
@@ -93,6 +94,7 @@ class AgentBridgeProvider : ContentProvider() {
|
||||
}
|
||||
"prefs" -> prefs(context, request)
|
||||
"glasses" -> glasses(context, request)
|
||||
"logs" -> logs(context)
|
||||
"access" -> JSONObject().put("ok", true).put("commands", AgentAccess.commandsAllowed(context))
|
||||
.put("debugBuild", BuildConfig.DEBUG).put("inbox", AgentEnv.inbox(context).absolutePath)
|
||||
else -> error("UNKNOWN_COMMAND", "Unknown agent command '$method'")
|
||||
@@ -197,9 +199,21 @@ class AgentBridgeProvider : ContentProvider() {
|
||||
private fun hex(text: String, max: Int): Int? =
|
||||
text.removePrefix("0x").removePrefix("0X").takeIf { it.isNotEmpty() }?.toIntOrNull(16)?.takeIf { it in 0..max }
|
||||
|
||||
private fun logDir(context: Context): File? =
|
||||
SessionState.logDirectory ?: SessionState.logFile?.parentFile ?: SessionPaths.sessionFolders(context).lastOrNull()
|
||||
|
||||
// The session folder is app-private, so adb pulls this copy from external files instead.
|
||||
private fun logs(context: Context): JSONObject {
|
||||
val dir = logDir(context)?.takeIf { it.isDirectory }
|
||||
?: return error("NO_SESSION_LOGS", "No session artifact directory is available")
|
||||
val zip = SessionLogShare.zipFolder(context, dir, File(context.getExternalFilesDir(null), "agent-logs"))
|
||||
?: return error("NO_SESSION_LOGS", "The session artifact directory is empty")
|
||||
return JSONObject().put("ok", true).put("command", "logs").put("sessionId", dir.name).put("zip", zip.absolutePath)
|
||||
}
|
||||
|
||||
private fun state(context: Context): JSONObject {
|
||||
val runtimeVersion = LinuxRuntimeInstaller.installedVersion(context)
|
||||
val dir = SessionState.logDirectory ?: SessionState.logFile?.parentFile ?: SessionPaths.sessionFolders(context).lastOrNull()
|
||||
val dir = logDir(context)
|
||||
val session = JSONObject()
|
||||
.put("id", SessionState.sessionId ?: dir?.name ?: JSONObject.NULL)
|
||||
.put("phase", SessionState.phase.name)
|
||||
|
||||
@@ -158,13 +158,14 @@ internal object EnhancedSessionLogShare {
|
||||
context: Context,
|
||||
folder: File,
|
||||
onProgress: ((Float) -> Unit)? = null,
|
||||
outputDirectory: File = SessionLogShare.shareDir(context),
|
||||
limits: EnhancedShareLimits = EnhancedShareLimits(maxFilesPerArchive = 512),
|
||||
): File? {
|
||||
if (!folder.isDirectory || Files.isSymbolicLink(folder.toPath()) ||
|
||||
limits.maxFilesPerArchive < 1 || limits.maxBytesPerFile < 1 || limits.maxBytesTotal < 1) {
|
||||
return null
|
||||
}
|
||||
val out = SessionLogShare.shareDir(context).apply { deleteRecursively(); mkdirs() }
|
||||
val out = outputDirectory.apply { deleteRecursively(); mkdirs() }
|
||||
val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context))
|
||||
val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = true)
|
||||
val candidates = discovery.candidates.filter { it.linePrefix == null }
|
||||
|
||||
@@ -75,8 +75,8 @@ object SessionLogShare {
|
||||
}
|
||||
|
||||
|
||||
fun zipFolder(context: Context, folder: File, onProgress: ((Float) -> Unit)? = null): File? {
|
||||
return EnhancedSessionLogShare.createLegacy(context, folder, onProgress)
|
||||
fun zipFolder(context: Context, folder: File, out: File = shareDir(context), onProgress: ((Float) -> Unit)? = null): File? {
|
||||
return EnhancedSessionLogShare.createLegacy(context, folder, onProgress, out)
|
||||
}
|
||||
|
||||
const val STORES_DIR = "stores"
|
||||
|
||||
Reference in new issue
Block a user