From 7138f95c909731d5482daaa4da16f161c8e7e41a Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 3 Dec 2026 12:45:41 -0500 Subject: [PATCH] fix(onboarding): no wireless-debugging step on first run when the session runs outside the child-process count (#3639) Before the runtime is installed, the rootfs has no native hook yet, so the child-process check assumed the next session would be counted and showed "Finish setup" for wireless debugging. The session stages the hook from the APK before it starts, so predict the next session from the setting and the rootfs loader instead; a runtime still to be installed will have one. --- .../com/droiddeck/launcher/runtime/GuestWorkers.kt | 9 +++++---- .../java/com/droiddeck/launcher/runtime/NativeGuest.kt | 10 ++++++++++ .../com/droiddeck/launcher/runtime/NativeGuestTest.kt | 8 ++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/GuestWorkers.kt b/app/src/main/java/com/droiddeck/launcher/runtime/GuestWorkers.kt index 4d6a1de6fb..b4843fc6df 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/GuestWorkers.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/GuestWorkers.kt @@ -395,9 +395,10 @@ object GuestWorkers { private set /** Whether the session runs its programs in workers: the native userland, and not turned off. */ - fun enabled(context: Context): Boolean = - android.os.Build.VERSION.SDK_INT >= 30 && com.droiddeck.launcher.session.SessionPrefs.childProcessHandoff(context) && - NativeGuest.enabled(context) + fun enabled(context: Context): Boolean = handoffAllowed(context) && NativeGuest.enabled(context) + + private fun handoffAllowed(context: Context): Boolean = + android.os.Build.VERSION.SDK_INT >= 30 && com.droiddeck.launcher.session.SessionPrefs.childProcessHandoff(context) /** How the running session's root was started: in a worker (true) or counted (false); null with none running. */ @Volatile var sessionRootUncounted: Boolean? = null @@ -408,7 +409,7 @@ object GuestWorkers { * the next one would start. */ fun limitHandled(context: Context): Boolean = - sessionRootUncounted ?: (NativeGuest.sessionMode != false && enabled(context)) + sessionRootUncounted ?: (NativeGuest.sessionMode != false && handoffAllowed(context) && NativeGuest.nextSession(context)) /** Whether pid is a program running in one of the workers. */ fun runsInWorker(pid: Int): Boolean = pid > 0 && synchronized(slots) { slots.any { it != null && it.started && it.pid == pid } } diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt b/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt index babaae550a..95a660eaf4 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt @@ -24,6 +24,16 @@ object NativeGuest { fun enabled(context: Context): Boolean = SessionPrefs.nativeUserland(context) && available(LinuxRuntime.rootDir(context)) + /** + * Whether the next session will start natively. The session stages the hook from the APK before + * it starts, so only the setting and the rootfs's loader decide, and a runtime still to be + * installed will have one. + */ + fun nextSession(context: Context): Boolean = + SessionPrefs.nativeUserland(context) && willRun(LinuxRuntime.rootDir(context), LinuxRuntime.isInstalled(context)) + + internal fun willRun(root: File, installed: Boolean): Boolean = !installed || loader(root) != null + /** The mode the running session started in; null between sessions. */ @Volatile var sessionMode: Boolean? = null diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt index d8ea5ee185..563b09dd36 100644 --- a/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt @@ -12,6 +12,14 @@ class NativeGuestTest { File(it, "usr/lib/ld-linux-aarch64.so.1").writeText("") } + @Test + fun aRuntimeStillToBeInstalledRunsTheNextSessionNatively() { + val empty = Files.createTempDirectory("native-root").toFile() + assertTrue(NativeGuest.willRun(empty, installed = false)) + assertEquals(false, NativeGuest.willRun(empty, installed = true)) + assertTrue(NativeGuest.willRun(rootWithLoader(), installed = true)) + } + @Test fun theSeccompSwitchNamesAHelperAndItsArgumentsInTheRootfs() { val root = Files.createTempDirectory("rootfs").toFile()