fix(shortcuts): the companion no longer keeps DroidDeck running, so Cocoon stops calling it open (#2764)

* fix(shortcuts): the companion no longer keeps DroidDeck running, so Cocoon stops calling it open

* fix(shortcuts): reset the relay holder when it is installed again
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-17 10:03:25 -05:00
1 parent 51ec4a3029
commit 637f4b21ee
7 files changed
+86 -6

No files matched your search

@@ -43,6 +43,7 @@ class App : Application() {
if (process == "$packageName:vr_recovery" || process == "$packageName:rgb_diagnostic" ||
process == "$packageName:shortcuts_sync" || process == "$packageName:bottom_desktop") return
CrashHandler.install(this)
com.droiddeck.launcher.input.ShortcutsRelay.Holder.install(this)
com.droiddeck.launcher.agent.AgentHost.refresh(this)
com.droiddeck.launcher.agent.AgentTab.load(this)
com.droiddeck.launcher.ui.NavTabs.load(this)
@@ -37,7 +37,7 @@ object SteamIntegration {
locationOn = WifiDiscovery.locationEnabled(context),
brightness = Settings.System.canWrite(context),
home = HomeApp.isDefault(context),
shortcuts = shortcutsEnabled(context),
shortcuts = shortcutsEnabled(context) && shortcutsCurrent(context),
shortcutsRestricted = restrictedSettings(context),
suggested = !SessionPrefs.sessionPrefs(context).getBoolean("steam_integration_seen", false),
)
@@ -61,6 +61,10 @@ object SteamIntegration {
return enabled.split(':').any { ComponentName.unflattenFromString(it.trim()) == shortcutsComponent }
}
@Suppress("DEPRECATION")
fun shortcutsCurrent(context: Context): Boolean =
runCatching { context.packageManager.getPackageInfo(Relay.PACKAGE, 0).versionCode }.getOrDefault(0) >= Relay.VERSION
fun shortcutsListed(context: Context): Boolean =
context.getSystemService(android.view.accessibility.AccessibilityManager::class.java)
?.installedAccessibilityServiceList.orEmpty()
@@ -178,4 +178,56 @@ class ShortcutsRelay : Service(), InputManager.InputDeviceListener {
private companion object {
const val KEY_TIMEOUT_MS = 200L
}
// Frontends such as Cocoon treat a running player process as an open game, so the relay runs only while a screen is started.
object Holder : android.app.Application.ActivityLifecycleCallbacks, android.content.ServiceConnection {
private const val RELEASE_MS = 1_000L
private val handler = Handler(Looper.getMainLooper())
private var app: android.app.Application? = null
private var started = 0
private var bound = false
private val release = Runnable { unbind() }
fun install(application: android.app.Application) {
app?.unregisterActivityLifecycleCallbacks(this)
handler.removeCallbacks(release)
started = 0
bound = false
app = application
application.registerActivityLifecycleCallbacks(this)
}
override fun onActivityStarted(activity: android.app.Activity) {
started++
handler.removeCallbacks(release)
if (!bound) bind()
}
override fun onActivityStopped(activity: android.app.Activity) {
started = (started - 1).coerceAtLeast(0)
if (started == 0) handler.postDelayed(release, RELEASE_MS)
}
private fun bind() {
val context = app ?: return
if (runCatching { context.packageManager.getPackageInfo(Relay.PACKAGE, 0) }.isFailure) return
bound = runCatching {
context.bindService(Intent(context, ShortcutsRelay::class.java), this, Context.BIND_AUTO_CREATE)
}.getOrDefault(false)
}
private fun unbind() {
if (!bound) return
bound = false
runCatching { app?.unbindService(this) }
}
override fun onServiceConnected(name: android.content.ComponentName?, service: IBinder?) = Unit
override fun onServiceDisconnected(name: android.content.ComponentName?) = Unit
override fun onActivityCreated(activity: android.app.Activity, savedInstanceState: android.os.Bundle?) = Unit
override fun onActivityResumed(activity: android.app.Activity) = Unit
override fun onActivityPaused(activity: android.app.Activity) = Unit
override fun onActivitySaveInstanceState(activity: android.app.Activity, outState: android.os.Bundle) = Unit
override fun onActivityDestroyed(activity: android.app.Activity) = Unit
}
}