From e71c37b34f333cc178d8983747b2b58f0c802b72 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:16:11 -0500 Subject: [PATCH 1/4] Expose Battle.net launcher in Library and restore Stores to More (#3285) --- .../com/droiddeck/launcher/ui/LibraryPage.kt | 13 ++++++-- .../java/com/droiddeck/launcher/ui/NavTabs.kt | 2 +- .../launcher/ui/LibraryVisibilityTest.kt | 31 ++++++++++++++++--- .../com/droiddeck/launcher/ui/NavTabsTest.kt | 12 +++---- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt index ed5d2f9cf6..f7bd8e9f20 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt @@ -374,7 +374,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, .map { it.store.id }.toSet() val sources = librarySources( all, storeTabs.map { it.store.id }, - listOfNotNull(Store.ITCH.id.takeIf { itchSignedIn && !soundMode }, Store.GAMEJOLT.id.takeIf { gameJoltSignedIn && !soundMode }, Library.ADDED.takeIf { stores }).toSet() + signInChips, + listOfNotNull(Store.ITCH.id.takeIf { itchSignedIn && !soundMode }, Store.GAMEJOLT.id.takeIf { gameJoltSignedIn && !soundMode }, Library.ADDED.takeIf { stores }, Store.BATTLENET.id.takeIf { stores }).toSet() + signInChips, favorites, concealed, offStores = if (soundMode) emptySet() else storeTabs.filterNot { it.shown }.map { it.store.id }.toSet(), places = if (soundMode) DEFAULT_LIBRARY_PLACES else StoreTabsState.libraryPlaces, @@ -632,7 +632,8 @@ private fun LibraryGrid( // A search that matches nothing keeps the toolbar, so the search can still be cleared. val customEmpty = !soundMode && source == Library.ADDED && visible.isEmpty() && hiddenUninstalled == 0 && LibraryView.query.isBlank() val splash = !soundMode && (signInStore != null || customEmpty) - val headerItems = (if (splash) 1 else 2) + (if (sizesPending) 1 else 0) + syncing.size + val showHeader = !splash || source == Store.BATTLENET.id + val headerItems = (if (showHeader) 2 else 1) + (if (sizesPending) 1 else 0) + syncing.size val expanded = showUninstalled == true val notInstalled = if (expanded) visible.count { !it.installed } else hiddenUninstalled val toggleAt = when { @@ -766,7 +767,7 @@ private fun LibraryGrid( Box(Modifier.onSizeChanged { chipsH = it.height }) { Rise(0) { if (soundMode) header() else filters() } } } val splashHeight = with(density) { (gridH - chipsH).toDp() - 28.dp }.coerceAtLeast(300.dp) - if (!splash) item(key = if (soundMode) "filters" else "header", span = { GridItemSpan(maxLineSpan) }) { Rise(1) { if (soundMode) filters() else header() } } + if (showHeader) item(key = if (soundMode) "filters" else "header", span = { GridItemSpan(maxLineSpan) }) { Rise(1) { if (soundMode) filters() else header() } } for ((store, line) in syncing) item(key = "sync-${store.id}", span = { GridItemSpan(maxLineSpan) }) { Column(verticalArrangement = Arrangement.spacedBy(4.dp), modifier = Modifier.fillMaxWidth()) { Text(store.shortLabel + " ยท " + line, fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) @@ -882,6 +883,12 @@ private fun LibraryHeader( clearSearchFocus = searchCleared, inlineWhenStacked = true, lead = soundLead, ) { + if (!soundMode && !s.shortcutPicker && source == Store.BATTLENET.id) { + SecondaryButton( + stringResource(R.string.bnet_open), enabled = !s.busy && DevPreview.library == LibraryPreview.OFF, + compact = true, modifier = Modifier.testTag("library-battlenet-open"), onClick = a.onBattleNet, + ) + } if (soundMode) HeaderIconButton(stringResource(R.string.soundtracks_saved), Icons.Filled.BookmarkBorder, "collections", onClick = onCollections) if (!soundMode && DeveloperTools.on && DevPreview.shortcuts) LibraryPreviewButton() DisplayButton() diff --git a/app/src/main/java/com/droiddeck/launcher/ui/NavTabs.kt b/app/src/main/java/com/droiddeck/launcher/ui/NavTabs.kt index 19b6ced051..2fa5d01cbd 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/NavTabs.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/NavTabs.kt @@ -27,7 +27,7 @@ internal object DeveloperTools { internal object NavTabs { const val MORE = "more" val ALL = listOf("steam", "desktop", "games", "downloads", "setup", "updates", "stores", "soundtracks", "components", "storage", "sync", "decky", "boot-movies", "android-apps", "agent") - val DEFAULT_SHELVED = setOf("soundtracks", "components", "storage", "sync", "decky", "boot-movies", "agent") + val DEFAULT_SHELVED = setOf("stores", "soundtracks", "components", "storage", "sync", "decky", "boot-movies", "agent") val DEFAULT_HIDDEN = setOf("android-apps", "agent") private val SHELVED_WHEN_NEW = setOf("storage", "sync", "decky", "boot-movies", "agent") private val OLD_ORDER = listOf("steam", "games", "soundtracks", "stores", "downloads", "desktop", "agent", "components", "android-apps", "storage", "sync", "setup", "updates") diff --git a/app/src/test/java/com/droiddeck/launcher/ui/LibraryVisibilityTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/LibraryVisibilityTest.kt index 4123ac826c..87e1d0bbb3 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/LibraryVisibilityTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/LibraryVisibilityTest.kt @@ -11,6 +11,7 @@ import androidx.compose.runtime.snapshots.Snapshot import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertIsNotEnabled import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onNodeWithContentDescription @@ -195,13 +196,32 @@ class LibraryVisibilityTest { compose.onNodeWithText("Uninstalled GOG").assertExists() } - private fun show() { + @Test fun battleNetHasAnOpenClientActionEvenWithoutInstalledGames() { + var opened = 0 + show(actions(onBattleNet = { opened++ })) + compose.onNodeWithTag("library-battlenet-open").assertDoesNotExist() + compose.onNodeWithTag("library-source-battlenet").performClick() + compose.mainClock.advanceTimeBy(1_000) + compose.onNodeWithTag("library-battlenet-open").assertIsDisplayed().performClick() + assertEquals(1, opened) + compose.onNodeWithTag("library-source-steam").performClick() + compose.mainClock.advanceTimeBy(1_000) + compose.onNodeWithTag("library-battlenet-open").assertDoesNotExist() + } + + @Test fun battleNetOpenIsDisabledWhileBusy() { + LibraryView.source = Store.BATTLENET.id + show(frontState = state(busy = true)) + compose.onNodeWithTag("library-battlenet-open").assertIsNotEnabled() + } + + private fun show(frontActions: FrontEndActions = actions(), frontState: FrontEndState = state()) { compose.mainClock.autoAdvance = false compose.setContent { key(generation) { DroidDeckTheme { CompositionLocalProvider(LocalFrontFocus provides FrontFocus()) { FocusGlideHost { Box(Modifier.fillMaxSize()) { - LibraryPage(state(), actions(), "games", {}, Modifier.fillMaxSize()) + LibraryPage(frontState, frontActions, "games", {}, Modifier.fillMaxSize()) StepsLayer(Offset.Zero) } } } @@ -216,15 +236,16 @@ class LibraryVisibilityTest { assertEquals(show, SessionPrefs.libraryShowUninstalled(ctx)) } - private fun state(games: List = listOf(Library.SteamGame(440, "Installed Steam game", null, "internal"))) = FrontEndState( - installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1, + private fun state(games: List = listOf(Library.SteamGame(440, "Installed Steam game", null, "internal")), busy: Boolean = false) = FrontEndState( + installed = "r9", ready = true, available = null, busy = busy, stage = "", percent = -1, desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "", romsDir = null, logsEnabled = false, steamGames = games, emulators = emptyList(), running = null, ) - private fun actions() = FrontEndActions( + private fun actions(onBattleNet: () -> Unit = {}) = FrontEndActions( + onBattleNet = onBattleNet, onPlay = {}, onPlayDesktopUi = {}, onSteamGame = {}, onDesktop = {}, onEmulator = {}, onRom = {}, onResume = {}, onSteamSettings = {}, onDesktopSettings = {}, onInstallPackage = {}, onRemovePackage = {}, onRuntime = {}, onFrameGenPick = {}, diff --git a/app/src/test/java/com/droiddeck/launcher/ui/NavTabsTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/NavTabsTest.kt index a04579033c..72546927c7 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/NavTabsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/NavTabsTest.kt @@ -40,8 +40,8 @@ class NavTabsTest { } @Test fun aFreshInstallShowsTheDefaultBarMoreAndHiddenTabs() { - assertEquals(listOf("steam", "desktop", "games", "downloads", "setup", "updates", "stores", NavTabs.MORE), navigationKeys(state())) - assertEquals(listOf("soundtracks", "components", "storage", "sync", "decky", "boot-movies"), NavTabs.more(state())) + assertEquals(listOf("steam", "desktop", "games", "downloads", "setup", "updates", NavTabs.MORE), navigationKeys(state())) + assertEquals(listOf("stores", "soundtracks", "components", "storage", "sync", "decky", "boot-movies"), NavTabs.more(state())) assertEquals(TabPlace.HIDDEN, NavTabs.place(state(), "android-apps")) assertEquals(TabPlace.HIDDEN, NavTabs.place(state(), "agent")) assertFalse(com.droiddeck.launcher.agent.AgentTab.shown) @@ -66,13 +66,13 @@ class NavTabsTest { @Test fun showingMusicOnceKeepsItShownAfterReload() { place("soundtracks", TabPlace.BAR) NavTabs.load(ctx) - assertEquals(listOf("steam", "desktop", "games", "downloads", "setup", "updates", "stores", "soundtracks", NavTabs.MORE), navigationKeys(state())) + assertEquals(listOf("steam", "desktop", "games", "downloads", "setup", "updates", "soundtracks", NavTabs.MORE), navigationKeys(state())) } @Test fun shelvedTabsLeaveTheBarAndAddMoreAtTheEnd() { place("desktop", TabPlace.MORE) val s = state() - assertEquals(listOf("desktop", "soundtracks", "components", "storage", "sync", "decky", "boot-movies"), NavTabs.more(s)) + assertEquals(listOf("desktop", "stores", "soundtracks", "components", "storage", "sync", "decky", "boot-movies"), NavTabs.more(s)) assertEquals(NavTabs.MORE, navigationKeys(s).last()) assertFalse("desktop" in navigationKeys(s)) } @@ -85,14 +85,14 @@ class NavTabsTest { } @Test fun resettingPutsBackTheDefaultLayout() { - place("stores", TabPlace.MORE) + place("stores", TabPlace.BAR) place("updates", TabPlace.HIDDEN) moveTab("downloads", -1) assertFalse(NavTabs.isDefault()) NavTabs.reset(ctx) NavTabs.load(ctx) assertTrue(NavTabs.isDefault()) - assertEquals(listOf("steam", "desktop", "games", "downloads", "setup", "updates", "stores", NavTabs.MORE), navigationKeys(state())) + assertEquals(listOf("steam", "desktop", "games", "downloads", "setup", "updates", NavTabs.MORE), navigationKeys(state())) } @Test fun anOldLayoutKeepsWhatItsSwitchesShowed() { From bdd3d247c395c809d2e6730c481a96510eae184c Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:17:07 -0500 Subject: [PATCH 2/4] Start the DroidDeck HUD unlocked on a fresh install (#3251) --- .../java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt | 2 +- .../main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt | 2 +- .../java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt index 719aae8d7f..fbd14aea93 100644 --- a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt +++ b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudConfig.kt @@ -5,7 +5,7 @@ import com.droiddeck.launcher.session.SessionPrefs internal object DroidDeckHudConfig { val DEFAULTS: Map = linkedMapOf( - "hudSize" to "minimal", "hudLocked" to "1", "hudHold" to "collapse", "hudSnap" to "1", "hudScale" to "100", "hudDock" to "none", "hudOpacity" to "80", "hudColor" to "mid", + "hudSize" to "minimal", "hudLocked" to "0", "hudHold" to "collapse", "hudSnap" to "1", "hudScale" to "100", "hudDock" to "none", "hudOpacity" to "80", "hudColor" to "mid", "hudOutline" to "40", "hudOutlineAccent" to "1", "showGpuModel" to "1", "showGPULoad" to "1", "showCPUUsage" to "1", "showCPULoad" to "1", "showPerCore" to "1", "showTemp" to "1", "showBatteryTemp" to "1", "showGpuTemp" to "0", diff --git a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt index bd04d149a2..f58320bc8e 100644 --- a/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt +++ b/app/src/main/java/com/droiddeck/launcher/hud/DroidDeckHudView.kt @@ -349,7 +349,7 @@ class DroidDeckHudView(context: Context) : View(context) { showProton = switchOn("showProton") showSession = switchOn("showSession") tempDisplay = HudMetrics.TempDisplay.from(cfg) - lockController.setLocked(cfg.get("hudLocked", "1") == "1") + lockController.setLocked(cfg.get("hudLocked", "0") == "1") lockController.setHoldLocks(cfg.get("hudHold", "collapse") == DroidDeckHudConfig.HOLD_LOCKS) dock = DroidDeckHudDock.from(cfg.get("hudDock", "none")) diff --git a/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt b/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt index f638ea4afe..54d3e5584e 100644 --- a/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/hud/DroidDeckHudPanelTest.kt @@ -34,8 +34,8 @@ class DroidDeckHudPanelTest { assertEquals(DroidDeckHudSize.MINIMAL, DroidDeckHudSize.from(DroidDeckHudConfig.DEFAULTS["hudSize"])) } - @Test fun theHudStartsLocked() { - assertEquals("1", DroidDeckHudConfig.DEFAULTS["hudLocked"]) + @Test fun theHudStartsUnlocked() { + assertEquals("0", DroidDeckHudConfig.DEFAULTS["hudLocked"]) } @Test fun aLongPressCollapsesTheHudUnlessTheUserChoseToLockWithIt() { From cc045463737487efd554f8b2492a2ad6e1bb979f Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:17:31 -0500 Subject: [PATCH 3/4] fix(logs): game debug logs turn off after the session, and a badge shows while they are on (#3239) --- .../launcher/session/BuildWatermarkSetting.kt | 4 + .../launcher/session/SessionPaths.kt | 7 ++ .../launcher/session/SessionPrefs.kt | 10 ++- .../droiddeck/launcher/ui/BuildWatermark.kt | 13 ++- app/src/main/res/values/strings.xml | 2 +- .../session/GameDebugLogsExpiryTest.kt | 88 +++++++++++++++++++ 6 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/session/GameDebugLogsExpiryTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/session/BuildWatermarkSetting.kt b/app/src/main/java/com/droiddeck/launcher/session/BuildWatermarkSetting.kt index 98239f8eb0..cf31b02404 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/BuildWatermarkSetting.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/BuildWatermarkSetting.kt @@ -39,6 +39,10 @@ internal object BuildWatermarkSetting { throw error } } + notifyChanged(context) + } + + fun notifyChanged(context: Context) { context.sendBroadcast(Intent(CHANGED).setPackage(context.packageName)) } } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt index 69cb7d4fae..d8117ae714 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt @@ -26,6 +26,9 @@ object SessionPaths { @Volatile private var startedAt = 0L + @Volatile + private var debugLogsContext: Context? = null + @Synchronized fun beginOrCurrent(context: Context, label: String? = null): File { dir?.let { if (it.isDirectory) return it } @@ -44,6 +47,7 @@ object SessionPaths { startedAt = System.currentTimeMillis() if (!made.isDirectory && !made.mkdirs()) Log.e(TAG, "could not create $made") dir = made + debugLogsContext = if (SessionPrefs.gameDebugLogsEnabled(context)) context.applicationContext else null if (enhanced && !EnhancedDiagnostics.consumeInto(context, made)) { Log.e(TAG, "could not activate enhanced diagnostics for $made") } @@ -65,6 +69,9 @@ object SessionPaths { val taken = dir dir = null if (taken != null) ended = taken + val expiring = debugLogsContext + debugLogsContext = null + if (taken != null && expiring != null) SessionPrefs.expireGameDebugLogs(expiring) return taken } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index b5794eff94..5d545c0b66 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -1228,7 +1228,7 @@ object SessionPrefs { oldValue = logsEnabled(context), newValue = on, newEffective = gameDebugLogsEffective(context, on, gameDebugLogsEnabled(context)), - ) + ).also { if (it) BuildWatermarkSetting.notifyChanged(context) } } fun gameDebugLogsEnabled(context: Context): Boolean = @@ -1241,7 +1241,13 @@ object SessionPrefs { oldValue = gameDebugLogsEnabled(context), newValue = on, newEffective = gameDebugLogsEffective(context, logsEnabled(context), on), - ) + ).also { if (it) BuildWatermarkSetting.notifyChanged(context) } + } + + /** The setting lasts for the session that started with it on; the next session's start republishes the environment. */ + internal fun expireGameDebugLogs(context: Context) { + prefs(context).edit().putBoolean("gameDebugLogsEnabled", false).apply() + runCatching { BuildWatermarkSetting.notifyChanged(context) } } private fun setLogPreference( diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BuildWatermark.kt b/app/src/main/java/com/droiddeck/launcher/ui/BuildWatermark.kt index 446420806c..c916b3f7ad 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BuildWatermark.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BuildWatermark.kt @@ -81,10 +81,13 @@ object BuildWatermark { if (activity is QuestXrActivity) return val decor = activity.window.decorView as? ViewGroup ?: return decor.findViewWithTag(TAG)?.let(decor::removeView) - if (!com.droiddeck.launcher.session.SessionPrefs.buildWatermarkEnabled(activity)) return - val lab = com.droiddeck.launcher.lab.LabOverlay.active?.let { "LAB | ${truncate(it.label)}" } - val build = lineProvider().orEmpty() - val content = (listOfNotNull(lab) + build).ifEmpty { return } + val prefs = com.droiddeck.launcher.session.SessionPrefs + val debugLogs = if (prefs.logsEnabled(activity) && prefs.gameDebugLogsEnabled(activity)) DEBUG_LOGS_LINE else null + val build = if (prefs.buildWatermarkEnabled(activity)) { + listOfNotNull(com.droiddeck.launcher.lab.LabOverlay.active?.let { "LAB | ${truncate(it.label)}" }) + + lineProvider().orEmpty() + } else emptyList() + val content = (build + listOfNotNull(debugLogs)).ifEmpty { return } val margin = (8 * activity.resources.displayMetrics.density).toInt() decor.addView( MarkView(activity, content).apply { tag = TAG }, @@ -96,6 +99,8 @@ object BuildWatermark { ) } + internal const val DEBUG_LOGS_LINE = "GAME DEBUG LOGS ON | slows games" + private const val TAG = "build-watermark" private class MarkView(context: Context, private val lines: List) : View(context) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cc7f0aca34..e5d43de074 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -966,7 +966,7 @@ Games and compatibility All bundles Game debug logs - Include Proton, Wine and graphics diagnostics on the next game launch. Can reduce performance and use more storage. + Include Proton, Wine and graphics diagnostics on the next game launch. Turns itself off when that session ends. Can reduce performance and use more storage. Restart this session to save game debug logs Couldn\'t update logging. Check the switch and try again. Debugging tools diff --git a/app/src/test/java/com/droiddeck/launcher/session/GameDebugLogsExpiryTest.kt b/app/src/test/java/com/droiddeck/launcher/session/GameDebugLogsExpiryTest.kt new file mode 100644 index 0000000000..9642b27462 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/GameDebugLogsExpiryTest.kt @@ -0,0 +1,88 @@ +package com.droiddeck.launcher.session + +import android.app.Activity +import android.app.Application +import android.content.Context +import android.os.Looper +import android.view.View +import com.droiddeck.launcher.ui.BuildWatermark +import org.junit.After +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.Robolectric +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.Shadows.shadowOf +import org.robolectric.annotation.Config +import org.robolectric.annotation.ConscryptMode +import org.robolectric.annotation.GraphicsMode +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@ConscryptMode(ConscryptMode.Mode.OFF) +@GraphicsMode(GraphicsMode.Mode.LEGACY) +@Config(sdk = [34], manifest = Config.NONE, application = Application::class) +class GameDebugLogsExpiryTest { + private val context get() = RuntimeEnvironment.getApplication() + private val prefs get() = context.getSharedPreferences("session", Context.MODE_PRIVATE) + + @Before fun reset() { + SessionPaths.take() + prefs.edit().clear().commit() + listOf("build-watermark", "build-watermark.lock").forEach { File(context.filesDir, it).delete() } + } + + @After fun end() { + SessionPaths.take() + } + + private fun setDebugLogs(on: Boolean) = prefs.edit().putBoolean("gameDebugLogsEnabled", on).commit() + + @Test fun settingTurnsOffWhenTheSessionItStartedWithEnds() { + setDebugLogs(true) + SessionPaths.beginOrCurrent(context, "steam") + assertTrue(SessionPrefs.gameDebugLogsEnabled(context)) + SessionPaths.take() + assertFalse(SessionPrefs.gameDebugLogsEnabled(context)) + } + + @Test fun settingStaysOnForTheSessionRunningWhenItWasEnabled() { + SessionPaths.beginOrCurrent(context, "steam") + setDebugLogs(true) + SessionPaths.take() + assertTrue(SessionPrefs.gameDebugLogsEnabled(context)) + SessionPaths.beginOrCurrent(context, "steam") + SessionPaths.take() + assertFalse(SessionPrefs.gameDebugLogsEnabled(context)) + } + + @Test fun settingThatWasOffStaysOff() { + SessionPaths.beginOrCurrent(context, "steam") + SessionPaths.take() + assertFalse(SessionPrefs.gameDebugLogsEnabled(context)) + } + + @Test fun badgeShowsWhileOnEvenWithTheBuildWatermarkOff() { + BuildWatermark.install(context) + SessionPrefs.setBuildWatermarkEnabled(context, false) + val activity = Robolectric.buildActivity(Activity::class.java).setup() + try { + assertNull(activity.get().window.decorView.findViewWithTag("build-watermark")) + setDebugLogs(true) + BuildWatermarkSetting.notifyChanged(context) + shadowOf(Looper.getMainLooper()).idle() + assertNotNull(activity.get().window.decorView.findViewWithTag("build-watermark")) + SessionPaths.beginOrCurrent(context, "steam") + SessionPaths.take() + shadowOf(Looper.getMainLooper()).idle() + assertNull(activity.get().window.decorView.findViewWithTag("build-watermark")) + } finally { + activity.pause().stop().destroy() + } + } +} From aef4a11595e517ae002d42b651d45888aa825b3c Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:18:05 -0500 Subject: [PATCH 4/4] fix(agent): the setup install stops when every update attempt fails (#3176) --- .../droiddeck/launcher/agent/AgentSetup.kt | 17 ++++--- .../agent/AgentSetupInstallScriptTest.kt | 50 +++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/agent/AgentSetupInstallScriptTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt index 573814f00c..4a2e07b45b 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt @@ -126,6 +126,16 @@ object AgentSetup { Thread({ for ((step, command) in probes) probe(app, harness, step, command) }, "agent-checks").start() } + /** The last failed refresh ends the script: the installs after it would run from stale indexes and could report success. */ + internal fun installScript(harnessInstall: String) = "set -e; export DEBIAN_FRONTEND=noninteractive; " + + "apt() { apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=30 \"\$@\"; }; " + + "dpkg --configure -a || echo 'Some packages are not configured yet; repairing dependencies'; " + + "for i in 1 2 3; do apt -o APT::Update::Error-Mode=any update -q && break; " + + "[ \$i = 3 ] && { echo 'Some package sources could not be refreshed'; exit 1; }; " + + "echo 'Some package sources could not be refreshed; retrying'; sleep 3; done; " + + "apt -f install -y --fix-missing; " + + "apt install -y --no-install-recommends git gh adb curl ca-certificates python3; $harnessInstall" + fun runsAsRoot(step: Step) = step == Step.INSTALL /** Runs [step]'s action. [CONNECTION] is the app's own pairing flow, so the caller opens it. */ @@ -140,12 +150,7 @@ object AgentSetup { val command = override ?: when (step) { Step.CONNECTION -> return Step.INSTALL -> { - listOf("sh", "-c", "set -e; export DEBIAN_FRONTEND=noninteractive; " + - "apt() { apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=30 \"\$@\"; }; " + - "dpkg --configure -a || echo 'Some packages are not configured yet; repairing dependencies'; " + - "for i in 1 2 3; do apt -o APT::Update::Error-Mode=any update -q && break; echo 'Some package sources could not be refreshed; retrying'; sleep 3; done; " + - "apt -f install -y --fix-missing; " + - "apt install -y --no-install-recommends git gh adb curl ca-certificates python3; ${harness.install}") + listOf("sh", "-c", installScript(harness.install)) } Step.SIGN_IN -> harness.signIn Step.GITHUB -> listOf("dd-gh-login") diff --git a/app/src/test/java/com/droiddeck/launcher/agent/AgentSetupInstallScriptTest.kt b/app/src/test/java/com/droiddeck/launcher/agent/AgentSetupInstallScriptTest.kt new file mode 100644 index 0000000000..bc36c84fe6 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/agent/AgentSetupInstallScriptTest.kt @@ -0,0 +1,50 @@ +package com.droiddeck.launcher.agent + +import java.io.File +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Assume.assumeTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder + +class AgentSetupInstallScriptTest { + @get:Rule val tmp = TemporaryFolder() + + private fun run(updateSucceedsOnCall: Int): Pair> { + val sh = listOf("/bin/sh", "/usr/bin/sh").firstOrNull { File(it).canExecute() } + assumeTrue(sh != null) + val bin = tmp.newFolder("bin") + val calls = File(tmp.root, "calls") + fun tool(name: String, body: String) = File(bin, name).apply { writeText("#!/bin/sh\n$body\n"); setExecutable(true) } + tool("dpkg", "exit 0") + tool("sleep", "exit 0") + tool("apt-get", """ + echo "${'$'}*" >> '${calls.path}' + case "${'$'}*" in + *" update "*) n=${'$'}(grep -c ' update ' '${calls.path}'); [ "${'$'}n" -ge $updateSucceedsOnCall ] ;; + *) exit 0 ;; + esac + """.trimIndent()) + val child = ProcessBuilder(sh, "-c", AgentSetup.installScript("echo harness-installed >> '${calls.path}'")) + .apply { environment()["PATH"] = bin.path + File.pathSeparator + System.getenv("PATH") } + .redirectErrorStream(true).start() + child.inputStream.readBytes() + val exit = child.waitFor() + return exit to (if (calls.exists()) calls.readLines() else emptyList()) + } + + @Test fun theInstallStopsWhenEveryUpdateAttemptFails() { + val (exit, calls) = run(updateSucceedsOnCall = 99) + assertTrue(exit != 0) + assertEquals(3, calls.count { " update " in "$it " }) + assertTrue(calls.none { "install" in it }) + } + + @Test fun theInstallContinuesWhenALaterUpdateAttemptSucceeds() { + val (exit, calls) = run(updateSucceedsOnCall = 3) + assertEquals(0, exit) + assertTrue(calls.any { "install -y --no-install-recommends" in it }) + assertTrue("harness-installed" in calls.last()) + } +}