mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
fix(session): Home suspends a game another app launched, so Cocoon can resume it (#2919)
* fix(session): Home suspends a game another app launched, so Cocoon can resume it A game launched from another front end (Cocoon, ES-DE, Daijisho...) or a home-screen shortcut went into picture in picture on Home. Cocoon brings a suspended player back by moving its task to the front, which Android ignores for a task in picture in picture, and the floating game covered Cocoon's Resume/Close bar. The game kept running instead of suspending, Cocoon's Resume did nothing, and the only way back was the picture itself. Automatic picture in picture now applies only to games DroidDeck launched itself. For games launched by another app (the existing returnHome launch), Home suspends the session, which is what Cocoon expects. The picture in picture button still works for those games. * fix(session): a new launch intent refreshes the automatic picture in picture rule at once
This commit is contained in:
1 parent
a29315f7e0
commit
56986b5999
4 files changed
+18
-2
No files matched your search
@@ -1028,7 +1028,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
kotlinx.coroutines.delay(2000)
|
||||
}
|
||||
}
|
||||
pip = com.droiddeck.launcher.session.SessionPipController(this, ::pipBounds, ::showPipUi)
|
||||
pip = com.droiddeck.launcher.session.SessionPipController(this, ::pipBounds, ::showPipUi) {
|
||||
intent.getBooleanExtra(EXTRA_RETURN_HOME, false)
|
||||
}
|
||||
surfaceView.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> pip.refresh() }
|
||||
pip.refresh()
|
||||
handleHomeGuideIntent(intent)
|
||||
@@ -5705,6 +5707,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (this.intent.getBooleanExtra(EXTRA_RETURN_HOME, false)) intent.putExtra(EXTRA_RETURN_HOME, true)
|
||||
if (!intent.hasExtra(EXTRA_LINK_TASK)) intent.putExtra(EXTRA_LINK_TASK, this.intent.getIntExtra(EXTRA_LINK_TASK, -1))
|
||||
setIntent(intent)
|
||||
if (::pip.isInitialized) pip.refresh(true)
|
||||
if (intent.getBooleanExtra(EXTRA_STEAMVR, false) && SessionState.mode == SessionService.MODE_STEAM) {
|
||||
SessionState.steamVr = true
|
||||
steamVrAutoTried = false
|
||||
|
||||
@@ -5,6 +5,11 @@ object PipPolicy {
|
||||
running && frameSeen && phase in setOf(SessionPhase.READY, SessionPhase.SUSPENDED) &&
|
||||
(!automatic || !suspended)
|
||||
|
||||
// A front end or shortcut that launched the game brings it back by moving its task to the
|
||||
// front, which Android ignores for a task in picture in picture, and draws its resume controls
|
||||
// where the picture would sit. Going home suspends the game for it instead.
|
||||
fun autoEnter(enabled: Boolean, launchedByAnotherApp: Boolean): Boolean = enabled && !launchedByAnotherApp
|
||||
|
||||
fun aspect(width: Int, height: Int): Pair<Int, Int> = when {
|
||||
width <= 0 || height <= 0 -> 16 to 9
|
||||
width.toDouble() / height > 2.39 -> 239 to 100
|
||||
|
||||
@@ -16,6 +16,7 @@ class SessionPipController(
|
||||
private val activity: SessionActivity,
|
||||
private val bounds: () -> Rect,
|
||||
private val showPipUi: (Boolean) -> Unit,
|
||||
private val launchedByAnotherApp: () -> Boolean = { false },
|
||||
) {
|
||||
var transitioning = false
|
||||
private set
|
||||
@@ -29,7 +30,8 @@ class SessionPipController(
|
||||
PipPolicy.eligible(SessionState.running, SessionState.firstFrameSeen, SessionState.phase,
|
||||
SessionState.suspended, automatic)
|
||||
|
||||
fun automatic() = !suppressAuto && SessionPrefs.pipAutoEnter(activity) && eligible(true)
|
||||
fun automatic() = !suppressAuto && PipPolicy.autoEnter(SessionPrefs.pipAutoEnter(activity), launchedByAnotherApp()) &&
|
||||
eligible(true)
|
||||
|
||||
fun refresh(force: Boolean = false) {
|
||||
if (!supported(activity)) return
|
||||
|
||||
@@ -18,6 +18,12 @@ class PipPolicyTest {
|
||||
assertFalse(PipPolicy.eligible(true, false, SessionPhase.SUSPENDED, true, false))
|
||||
}
|
||||
|
||||
@Test fun goingHomeFloatsOnlyGamesDroidDeckLaunchedItself() {
|
||||
assertTrue(PipPolicy.autoEnter(enabled = true, launchedByAnotherApp = false))
|
||||
assertFalse(PipPolicy.autoEnter(enabled = true, launchedByAnotherApp = true))
|
||||
assertFalse(PipPolicy.autoEnter(enabled = false, launchedByAnotherApp = false))
|
||||
}
|
||||
|
||||
@Test fun aspectRatiosStayWithinAndroidLimitsWithoutChangingNormalContent() {
|
||||
assertEquals(1920 to 1080, PipPolicy.aspect(1920, 1080))
|
||||
assertEquals(239 to 100, PipPolicy.aspect(5760, 1080))
|
||||
|
||||
Reference in new issue
Block a user