Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion daemon/src/main/kotlin/org/matrix/vector/daemon/VectorDaemon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@ object VectorDaemon {

@JvmStatic
fun main(args: Array<String>) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) }
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -750,6 +796,13 @@ private fun buildSections(
): List<Pair<String, List<InfoItem>>> {
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(
Expand Down Expand Up @@ -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
Expand All @@ -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,
),
),
Expand Down
5 changes: 5 additions & 0 deletions manager/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<string name="status_mismatched">Version mismatch</string>
<string name="status_checking">Checking…</string>
<string name="status_open_details">Open system status</string>
<!-- Inactive because nothing answered at all, which is not the framework reporting a failure -->
<string name="daemon_down_title">Vector\'s daemon is not running</string>
<string name="daemon_down_summary">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.</string>

<!-- Degraded causes, in the priority order the daemon reports them -->
<string name="issue_sepolicy_title">SELinux policy not loaded</string>
Expand Down Expand Up @@ -88,6 +91,8 @@
<string name="info_not_loaded">Not loaded</string>
<string name="info_injected">Injected</string>
<string name="info_not_injected">Not injected</string>
<!-- The value of a health row when there was no daemon to ask; the dash matches the others -->
<string name="info_daemon_not_running">— (daemon not running)</string>
<string name="status_notification">Status notification</string>
<string name="status_notification_summary">A persistent notification showing that Vector is running.</string>
<string name="force_launcher_icons">Stop apps hiding their launcher icons</string>
Expand Down
23 changes: 21 additions & 2 deletions zygisk/module/daemon
Original file line number Diff line number Diff line change
Expand Up @@ -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