fix(session): picture in picture keeps the DroidDeck front end behind the game (#2559)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-13 07:40:20 -05:00
1 parent c57cc33125
commit d058bab64f
3 files changed
+24 -4

No files matched your search

@@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionState
class HomeActivity : Activity() {
override fun attachBaseContext(newBase: android.content.Context) {
@@ -18,7 +19,7 @@ class HomeActivity : Activity() {
}
private fun routeHome() {
val destination = if (HomeApp.isActiveSteamSession()) {
val destination = if (HomeApp.isActiveSteamSession() && !SessionState.pipActive) {
Intent(this, SessionActivity::class.java)
.setAction(SessionService.ACTION_HOME_GUIDE)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
@@ -32,7 +33,8 @@ class HomeActivity : Activity() {
}
}
}
startActivity(destination)
if (SessionState.pipActive && destination.component?.className == FrontEndActivity::class.java.name) HomeApp.showFrontEnd(this, destination)
else startActivity(destination)
finish()
}
}
@@ -258,6 +258,19 @@ object HomeApp {
fun isActiveSteamSession(): Boolean =
SessionState.running && SessionState.mode == SessionService.MODE_STEAM
fun showFrontEnd(context: Context, intent: Intent = Intent(context, FrontEndActivity::class.java)) {
val frontEnd = FrontEndActivity::class.java.name
val tasks = runCatching { context.getSystemService(android.app.ActivityManager::class.java)?.appTasks }.getOrNull().orEmpty()
val own = tasks.firstOrNull { task ->
runCatching { task.taskInfo.let { it.baseIntent.component?.className == frontEnd && it.topActivity?.className == frontEnd } }
.getOrDefault(false)
}
val launch = Intent(intent).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
if (own != null && runCatching { own.startActivity(context, launch, null) }.isSuccess) return
// The session task shares the front end's affinity, so without MULTIPLE_TASK the front end lands inside the session's PiP window.
context.startActivity(launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK))
}
fun openSystemHomeSettings(context: Context) {
try {
context.startActivity(settingsIntent())
@@ -21,6 +21,7 @@ class SessionPipController(
private set
private var suppressAuto = false
private var visit = false
private var requested = false
private var lastParams = ""
val floating get() = transitioning || activity.isInPictureInPictureMode
@@ -47,7 +48,7 @@ class SessionPipController(
return builder.build()
}
fun enter() {
fun enter(explicit: Boolean = true) {
if (!eligible()) {
Toast.makeText(activity, R.string.pip_not_ready, Toast.LENGTH_SHORT).show()
return
@@ -59,8 +60,10 @@ class SessionPipController(
return
}
prepare()
requested = explicit
val entered = runCatching { activity.enterPictureInPictureMode(params(bounds())) }.getOrDefault(false)
if (!entered) {
requested = false
restore()
Toast.makeText(activity, R.string.pip_unavailable, Toast.LENGTH_SHORT).show()
}
@@ -68,7 +71,7 @@ class SessionPipController(
fun leaving() {
if (!automatic() || !allowed()) return
if (Build.VERSION.SDK_INT < 31) enter() else prepare()
if (Build.VERSION.SDK_INT < 31) enter(explicit = false) else prepare()
}
private fun prepare() {
@@ -85,6 +88,8 @@ class SessionPipController(
showPipUi(true)
SessionService.beginPip(activity)
SessionService.setActivityVisible(activity, true)
if (requested) runCatching { com.droiddeck.launcher.HomeApp.showFrontEnd(activity) }
requested = false
} else restore()
refresh(true)
}