diff --git a/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt b/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt index 5bcc716d1e..7427eef05c 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt @@ -64,6 +64,19 @@ object PhantomProcessLimit { PhantomProcessStatus.UNCOUNTED else status } + /** The limit as the device sets it, whether or not the session keeps its programs out of the count. */ + fun setting(context: Context, sdk: Int = Build.VERSION.SDK_INT): PhantomProcessStatus = + if (sdk < Build.VERSION_CODES.S) PhantomProcessStatus.NOT_APPLICABLE else readSetting(context, sdk) + + /** + * Whether the session should run its programs in worker processes. Each worker is a process of + * the app, and frontends that track the app's processes (Cocoon gives up above 32) lose a game + * that runs in dozens, so with the limit off they run as ordinary children. Producer acquire + * fences need gamescope in a worker. + */ + fun workersWanted(setting: PhantomProcessStatus, producerFences: Boolean): Boolean = + setting != PhantomProcessStatus.DISABLED || producerFences + private fun readSetting(context: Context, sdk: Int): PhantomProcessStatus { if (usesDeviceConfig(sdk)) { val off = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean(PREF_ANDROID_12_OFF, false) 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 e3f7d0ba01..a0a2fb35fa 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/GuestWorkers.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/GuestWorkers.kt @@ -407,7 +407,10 @@ object GuestWorkers { 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) + android.os.Build.VERSION.SDK_INT >= 30 && com.droiddeck.launcher.session.SessionPrefs.childProcessHandoff(context) && + com.droiddeck.launcher.core.PhantomProcessLimit.workersWanted( + com.droiddeck.launcher.core.PhantomProcessLimit.setting(context), + com.droiddeck.launcher.session.SessionPrefs.producerAcquireFences(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 diff --git a/app/src/test/java/com/droiddeck/launcher/core/PhantomProcessLimitTest.kt b/app/src/test/java/com/droiddeck/launcher/core/PhantomProcessLimitTest.kt index 5ea537d73f..bfd4980989 100644 --- a/app/src/test/java/com/droiddeck/launcher/core/PhantomProcessLimitTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/core/PhantomProcessLimitTest.kt @@ -6,6 +6,16 @@ import org.junit.Assert.assertTrue import org.junit.Test class PhantomProcessLimitTest { + @Test + fun workersOnlyWhileAndroidCountsTheSessionsChildren() { + assertFalse(PhantomProcessLimit.workersWanted(PhantomProcessStatus.DISABLED, producerFences = false)) + assertTrue(PhantomProcessLimit.workersWanted(PhantomProcessStatus.DISABLED, producerFences = true)) + for (status in listOf(PhantomProcessStatus.ENABLED, PhantomProcessStatus.UNSET, PhantomProcessStatus.UNREADABLE, + PhantomProcessStatus.NOT_APPLICABLE)) { + assertTrue(status.name, PhantomProcessLimit.workersWanted(status, producerFences = false)) + } + } + @Test fun developerOptionsToggleAloneCountsAsOff() { assertEquals(PhantomProcessStatus.DISABLED, PhantomProcessLimit.status(null, "false"))