From bd85bc419fd7caf0f4fafba1679a38581a646c14 Mon Sep 17 00:00:00 2001 From: zzzzyppp Date: Tue, 10 Nov 2026 23:38:00 +0800 Subject: [PATCH] Improve daemon failure observability and manager diagnostics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Manager: track whether the daemon was actually reachable and render "— (daemon not running)" plus a DaemonDownCard when it was not, instead of presenting default HealthIssue values as the framework's own report. - Daemon: log lock contention separately from IO/SELinux failures, and use a neutral message when another daemon already holds the lock. - Launcher: keep the parent shell, capture stderr to /data/adb/lspd/log/bootstrap.log, append "vectord exited with code N", and propagate the exit status instead of discarding all launch evidence. No sepolicy, native, API, or ABI changes; no automatic restart or forced activation. --- .../org/matrix/vector/daemon/VectorDaemon.kt | 10 +- .../matrix/vector/daemon/data/FileSystem.kt | 5 + .../manager/ui/screens/home/HomeViewModel.kt | 18 ++++ .../ui/screens/home/SystemStatusScreen.kt | 97 ++++++++++++++++--- manager/src/main/res/values/strings.xml | 5 + zygisk/module/daemon | 23 ++++- 6 files changed, 141 insertions(+), 17 deletions(-) diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorDaemon.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorDaemon.kt index 3444e1c41c..21a07723fc 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorDaemon.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorDaemon.kt @@ -81,7 +81,15 @@ object VectorDaemon { @JvmStatic fun main(args: Array) { - if (!FileSystem.tryLock()) kotlin.system.exitProcess(0) + // The daemon's own log is not opened until later in main, so a start that stopped here exited 0 + // a fraction of a second after the module started it and left nothing anywhere: the boot simply + // had no daemon. The line claims only what is known here — tryLock answers false both for a lock + // another process holds and for a lock file that could not be opened at all — and FileSystem + // logs which of the two it was before returning. + if (!FileSystem.tryLock()) { + Log.w(TAG, "Could not acquire the daemon lock; exiting") + kotlin.system.exitProcess(0) + } // `activity` is system_server's own, registered long after the specialization in which the // module comes looking for us, so at boot nothing answers it and a binder there means someone diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/data/FileSystem.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/data/FileSystem.kt index 215e3f6b9f..d76ff4833e 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/data/FileSystem.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/data/FileSystem.kt @@ -183,6 +183,7 @@ object FileSystem { // A daemon that loses the race exits in a moment anyway, but it closes its own // descriptor on the way rather than leave that to the finalizer this method exists // not to depend on. + Log.w(TAG, "Lock $lockPath is held by another process") channel.close() return@runCatching false } @@ -194,6 +195,10 @@ object FileSystem { }) true } + // A refusal is the answer to "why is there no daemon" as often as a held lock is, and it + // used to be indistinguishable from one: the false went to the caller, the caller exited + // 0, and the boot was quiet. The exception is what tells the two apart. + .onFailure { Log.w(TAG, "Could not lock $lockPath", it) } .getOrDefault(false) } diff --git a/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/HomeViewModel.kt b/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/HomeViewModel.kt index 725ff534dc..aeb2359967 100644 --- a/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/HomeViewModel.kt +++ b/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/HomeViewModel.kt @@ -46,6 +46,18 @@ data class FrameworkStatus( val dex2oatWrapperState: Int = IManagerService.DEX2OAT_OK, val sepolicyLoaded: Boolean = false, val systemServerInjected: Boolean = false, + /** + * Whether the two booleans above are answers rather than defaults. + * + * Both default to false, so the status page used to render "not loaded" and "not injected" for + * a framework it had never asked: two refusals that name the wrong fault on a device whose + * daemon cannot start — a root implementation that loads its kernel module after boot leaves + * post-fs-data unrun, so no policy is applied and nothing rendezvouses — and that hide the one + * fact the manager does hold, which is that nothing was asked. Unlike [daemonUsable], which + * asks whether the daemon can be used, this asks whether it was asked: + * [FrameworkState.Checking] is false here and true there. + */ + val daemonReachable: Boolean = false, /** * Which build the running framework is: what commit it came from and where it was built. * @@ -384,6 +396,9 @@ class HomeViewModel( // interface, which is not the same thing as there being no framework — and saying "not // activated" for it sends the reader to reinstall something that is already running. val mismatch = ServiceLocator.peerMismatch.value + // daemonReachable keeps its false default here on purpose: there is no daemon, so the + // two health booleans were never read and the status page must say so instead of + // presenting their defaults as the framework's own report. _status.value = FrameworkStatus( state = @@ -443,6 +458,9 @@ class HomeViewModel( dex2oatWrapperState = dex2oat, sepolicyLoaded = sepolicy, systemServerInjected = systemServer, + // The binder answered, so the two booleans above are this framework's report and + // the status page may render them as such. + daemonReachable = true, ) if (versionCode > 0) { diff --git a/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/SystemStatusScreen.kt b/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/SystemStatusScreen.kt index f63f0dd9c9..0b4b4b4f95 100644 --- a/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/SystemStatusScreen.kt +++ b/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/SystemStatusScreen.kt @@ -71,6 +71,7 @@ import org.matrix.vector.manager.data.model.XposedApi import org.matrix.vector.manager.data.log.CrashReport import org.matrix.vector.manager.data.model.buildStamp import org.matrix.vector.manager.data.repository.ManagerInstallStep +import org.matrix.vector.manager.ui.components.FrameworkState import org.matrix.vector.ui.SnackbarTone import org.matrix.vector.ui.SharedSnackbarHost import org.matrix.vector.ui.copyToClipboard @@ -182,6 +183,14 @@ fun SystemStatusScreen( contentPadding = PaddingValues(start = 20.dp, end = 20.dp, top = 8.dp, bottom = 24.dp), verticalArrangement = Arrangement.spacedBy(2.dp), ) { + // First, because everything under it is unanswered: the page reads as a report, and a + // reader who sees one has to know whether there was anything to report on. + if (status.state == FrameworkState.Inactive) { + item(key = "daemon") { + DaemonDownCard() + Spacer(Modifier.height(4.dp)) + } + } if (status.issues.isNotEmpty()) { items(status.issues, key = { it.name }) { issue -> IssueCard(issue) } item { Spacer(Modifier.height(4.dp)) } @@ -537,6 +546,43 @@ private fun IssueCard(issue: HealthIssue) { } } +/** + * The reason nothing else on this page is a report: there is no daemon. + * + * The state is in the header already; what the card adds is the two checks worth making, in the + * order they are worth making, because "not activated" on its own invites a reinstall that would + * change nothing. The second is the one a root implementation that loads its kernel module after + * boot creates for itself: that boot's post-fs-data was skipped, so nothing applied Vector's policy + * and nothing was started, and only a boot stage that runs again replays it — a soft reboot, or the + * root manager's post-fs-data replay — because a cold reboot reloads the kernel module and lands in + * the same late-load. + */ +@Composable +private fun DaemonDownCard() { + OutlinedCard(modifier = Modifier.fillMaxWidth()) { + Row(modifier = Modifier.padding(16.dp), verticalAlignment = Alignment.Top) { + Icon( + Icons.Rounded.WarningAmber, + contentDescription = null, + tint = MaterialTheme.colorScheme.tertiary, + ) + Spacer(Modifier.padding(horizontal = 6.dp)) + Column { + Text( + stringResource(R.string.daemon_down_title), + style = MaterialTheme.typography.titleSmall, + ) + Spacer(Modifier.height(4.dp)) + Text( + stringResource(R.string.daemon_down_summary), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + } + } +} + /** * The manager's own crashes, which nothing else on the device keeps. * @@ -750,6 +796,13 @@ private fun buildSections( ): List>> { val unknown = "—" fun str(id: Int) = context.getString(id) + // What the health rows below say when there was no daemon to ask. Their three values default + // to false, false and DEX2OAT_OK, which render as two failures and one success for a framework + // that was never queried — the shape of a device where nothing started at all. The reason is + // named only on Inactive, which is a missing daemon; Checking and Mismatched say what they mean + // in the header already, and a bare dash there does not guess at it. + val unasked = + if (status.state == FrameworkState.Inactive) str(R.string.info_daemon_not_running) else unknown return listOf( str(R.string.info_section_build) to listOf( @@ -788,20 +841,32 @@ private fun buildSections( listOfNotNull( InfoItem( str(R.string.info_selinux), - str( - if (status.sepolicyLoaded) R.string.info_loaded - else R.string.info_not_loaded - ), - health = if (status.sepolicyLoaded) Health.Good else Health.Bad, + when { + !status.daemonReachable -> unasked + status.sepolicyLoaded -> str(R.string.info_loaded) + else -> str(R.string.info_not_loaded) + }, + health = + when { + !status.daemonReachable -> Health.Neutral + status.sepolicyLoaded -> Health.Good + else -> Health.Bad + }, monospace = false, ), InfoItem( str(R.string.info_system_server), - str( - if (status.systemServerInjected) R.string.info_injected - else R.string.info_not_injected - ), - health = if (status.systemServerInjected) Health.Good else Health.Bad, + when { + !status.daemonReachable -> unasked + status.systemServerInjected -> str(R.string.info_injected) + else -> str(R.string.info_not_injected) + }, + health = + when { + !status.daemonReachable -> Health.Neutral + status.systemServerInjected -> Health.Good + else -> Health.Bad + }, monospace = false, ), // Omitted below Android 10, where there is no wrapper to report on: the daemon only @@ -812,11 +877,15 @@ private fun buildSections( else InfoItem( str(R.string.info_dex2oat), - dex2oatLabel(context, status.dex2oatWrapperState), + if (!status.daemonReachable) unasked + else dex2oatLabel(context, status.dex2oatWrapperState), health = - if (status.dex2oatWrapperState == IManagerService.DEX2OAT_OK) - Health.Good - else Health.Bad, + when { + !status.daemonReachable -> Health.Neutral + status.dex2oatWrapperState == IManagerService.DEX2OAT_OK -> + Health.Good + else -> Health.Bad + }, monospace = false, ), ), diff --git a/manager/src/main/res/values/strings.xml b/manager/src/main/res/values/strings.xml index 4ae291426e..19d8d0fa01 100644 --- a/manager/src/main/res/values/strings.xml +++ b/manager/src/main/res/values/strings.xml @@ -33,6 +33,9 @@ Version mismatch Checking… Open system status + + Vector\'s daemon is not running + Nothing on this page could be asked of Vector, so the rows that report on the framework do not know the answer. Check that the Vector module is installed and enabled in your root manager. If the root implementation loads its kernel module after boot — KernelSU and SukiSU call this late-load — that boot skipped the post-fs-data stage, so Vector\'s policy was never applied and nothing was started; soft reboot once after loading the module (or use the root manager\'s post-fs-data replay) — a cold reboot reloads the kernel module and repeats the late-load — then open this page again. SELinux policy not loaded @@ -88,6 +91,8 @@ Not loaded Injected Not injected + + — (daemon not running) Status notification A persistent notification showing that Vector is running. Stop apps hiding their launcher icons diff --git a/zygisk/module/daemon b/zygisk/module/daemon index 79a70d7991..c7fab9e798 100644 --- a/zygisk/module/daemon +++ b/zygisk/module/daemon @@ -49,5 +49,24 @@ fi [ "$debug" = "true" ] && log -p d -t "Vector" "Starting daemon $*" -# Launch the daemon -exec /system/bin/app_process $java_options /system/bin --nice-name=vectord org.matrix.vector.daemon.VectorDaemon "$@" >/dev/null 2>&1 +# Where a start that dies on the way up leaves a word. The daemon opens its own log only after +# main has begun, so a classpath the runtime refuses, a crash in main, or a start that ends before +# main used to arrive at /dev/null and nothing else: the boot then simply had no daemon and no way +# to say why. The file sits in the daemon's own log directory, which the next boot rotates with the +# rest of it. +logDir="/data/adb/lspd/log" +bootstrapLog="$logDir/bootstrap.log" +mkdir -p "$logDir" 2>/dev/null +# In a subshell, so an unwritable path costs the log and not the daemon: a redirection that fails +# on the launch below would end the script before app_process starts. +( : >>"$bootstrapLog" ) 2>/dev/null || bootstrapLog=/dev/null + +# Launch the daemon, and keep this shell as its parent. exec would hand the script's PID and its +# exit status to app_process, and the starts worth explaining are the ones that end before main +# writes a line: they leave no stderr, only a status the exec would carry away. The parent waits +# while the daemon runs, writes the status down, and exits with it — one small process, not a +# second daemon. +/system/bin/app_process $java_options /system/bin --nice-name=vectord org.matrix.vector.daemon.VectorDaemon "$@" >/dev/null 2>>"$bootstrapLog" +status=$? +echo "vectord exited with code $status" >>"$bootstrapLog" 2>/dev/null +exit $status