feat: add build watermark toggle for Lab, test, and local builds (#2488)

This commit is contained in:
KeegantheVeganat0r authored and GitHub committed 2026-11-11 22:28:59 -05:00
1 parent 02a5be62da
commit 7da27d4ff4
41 files changed
+281 -16

No files matched your search

@@ -593,6 +593,7 @@ class FrontEndActivity : ComponentActivity() {
private var vacDiagnostics by mutableStateOf(false)
private var agentCommands by mutableStateOf(false)
private var graphicsLogs by mutableStateOf(false)
private var buildWatermark by mutableStateOf(true)
private var steamGpuDrawing by mutableStateOf(false)
private var bridgeFellBack by mutableStateOf(false)
private var bridgeFellBackMemory by mutableStateOf(false)
@@ -1178,6 +1179,7 @@ class FrontEndActivity : ComponentActivity() {
gameDebugLogsEnabled = gameDebugLogsEnabled, gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart,
vacDiagnostics = vacDiagnostics, agentCommands = agentCommands,
graphicsLogs = graphicsLogs, steamGpuDrawing = steamGpuDrawing, bridgeFellBack = bridgeFellBack, bridgeFellBackMemory = bridgeFellBackMemory,
buildWatermark = buildWatermark,
clearCachedApps = clearCachedApps, adbPaired = adbPaired, memoryHud = memoryHud, backgroundAppLimit = backgroundAppLimit,
tpUbwcMode = drivers.tpUbwcModeForDevice(), tpUbwcRestartRequired = drivers.tpUbwcRestartRequired(), canRestartApp = !runtimeChangesBlocked(),
steamGames = steamGames, steamGamesX64 = steamGamesX64, emulators = emulatorList, running = runningLabel,
@@ -1416,6 +1418,11 @@ class FrontEndActivity : ComponentActivity() {
SessionPrefs.setDetailedGraphicsLogs(this, !SessionPrefs.detailedGraphicsLogs(this))
graphicsLogs = SessionPrefs.detailedGraphicsLogs(this)
},
onBuildWatermark = {
SessionPrefs.setBuildWatermarkEnabled(this, !SessionPrefs.buildWatermarkEnabled(this))
buildWatermark = SessionPrefs.buildWatermarkEnabled(this)
com.droiddeck.launcher.ui.BuildWatermark.refresh(this)
},
onVacDiagnostics = {
SessionPrefs.setVacDiagnostics(this, !SessionPrefs.vacDiagnostics(this))
vacDiagnostics = SessionPrefs.vacDiagnostics(this)
@@ -2867,6 +2874,7 @@ class FrontEndActivity : ComponentActivity() {
vacDiagnostics = SessionPrefs.vacDiagnostics(this)
agentCommands = com.droiddeck.launcher.agent.AgentAccess.commandsEnabled(this)
graphicsLogs = SessionPrefs.detailedGraphicsLogs(this)
buildWatermark = SessionPrefs.buildWatermarkEnabled(this)
steamGpuDrawing = SessionPrefs.steamGpuCompositing(this)
bridgeFellBack = SessionPrefs.bridgeFellBack(this)
bridgeFellBackMemory = SessionPrefs.bridgeFellBackForMemory(this)
@@ -0,0 +1,44 @@
package com.droiddeck.launcher.session
import android.content.Context
import android.content.Intent
import android.util.AtomicFile
import java.io.File
internal object BuildWatermarkSetting {
const val CHANGED = "com.droiddeck.launcher.BUILD_WATERMARK_CHANGED"
private fun file(context: Context) = AtomicFile(File(context.filesDir, "build-watermark"))
private val processLock = Any()
private fun <T> locked(context: Context, action: () -> T): T = synchronized(processLock) {
File(context.filesDir, "build-watermark.lock").outputStream().channel.use { channel ->
channel.lock().use { action() }
}
}
fun enabled(context: Context): Boolean = try {
locked(context) {
// SharedPreferences caches are process-local; read the shared file on every refresh.
file(context).readFully().decodeToString() != "off"
}
} catch (_: java.io.IOException) {
context.getSharedPreferences("session", Context.MODE_PRIVATE).getBoolean("buildWatermark", true)
}
fun setEnabled(context: Context, on: Boolean) {
locked(context) {
val target = file(context)
val stream = target.startWrite()
try {
stream.write((if (on) "on" else "off").toByteArray())
target.finishWrite(stream)
} catch (error: Throwable) {
target.failWrite(stream)
throw error
}
}
context.sendBroadcast(Intent(CHANGED).setPackage(context.packageName))
}
}
@@ -1048,6 +1048,13 @@ object SessionPrefs {
prefs(context).edit().putBoolean("vac_diagnostics", on).apply()
}
fun buildWatermarkEnabled(context: Context): Boolean =
BuildWatermarkSetting.enabled(context)
fun setBuildWatermarkEnabled(context: Context, on: Boolean) {
BuildWatermarkSetting.setEnabled(context, on)
}
private fun resolutionCap(context: Context, mode: String): Int = prefs(context).getInt("resolutionCap.$mode", 720)
fun resolutionChosen(context: Context, mode: String): Boolean =
@@ -23,7 +23,7 @@ object SettingsReset {
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "ramCapMb", "vramCapMb", "zramClient",
"directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus",
"noXalia", "fastSync", "fsyncFirst", "syncFallback", "prootNoSeccomp", "prootFastPath", "nativeUserland", "cursorComposite",
"guestHostname", "fexPreset", "forceSsbs", "logs", "gameDebugLogsEnabled", "enhancedDiagnosticsNext", "storageDiagnostics",
"guestHostname", "fexPreset", "forceSsbs", "logs", "gameDebugLogsEnabled", "enhancedDiagnosticsNext", "storageDiagnostics", "buildWatermark",
"upscaler", "upscaleSharpness", "screenEffects", "textureAnisotropy", "textureLodBias",
"steamDownloadsInBackground", "steam_offline", "bootMovie", "bootMovieSound", "bootMovieVolume", "bootMovieSeconds",
"bootMovieApplyNext", "bootMovieSteamSeen",
@@ -43,6 +43,7 @@ object SettingsReset {
var ok = true
val session = context.getSharedPreferences("session", Context.MODE_PRIVATE)
session.edit().apply { session.all.keys.filter { isSessionSetting(it) }.forEach { remove(it) } }.commit()
BuildWatermarkSetting.setEnabled(context, true)
ControllerPrefs.resetAll(context)
InputProfiles.resetAll(context)
context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().clear().commit()
@@ -2,7 +2,12 @@ package com.droiddeck.launcher.ui
import android.app.Activity
import android.app.Application
import android.content.BroadcastReceiver
import android.content.Intent
import android.content.IntentFilter
import android.content.Context
import androidx.core.content.ContextCompat
import com.droiddeck.launcher.session.BuildWatermarkSetting
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Typeface
@@ -14,11 +19,14 @@ import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import java.util.WeakHashMap
import com.droiddeck.launcher.BuildConfig
import com.droiddeck.launcher.QuestXrActivity
object BuildWatermark {
private const val TITLE_LIMIT = 80
private val activities = WeakHashMap<Activity, Unit>()
internal var lineProvider: () -> List<String>? = { lines() }
fun lines(
pr: Int = BuildConfig.PR_NUMBER,
@@ -38,33 +46,56 @@ object BuildWatermark {
if (text.length <= TITLE_LIMIT) text else text.take(TITLE_LIMIT - 1).trimEnd() + "…"
fun install(app: Application) {
val lab = com.droiddeck.launcher.lab.LabOverlay.active?.let { "LAB | ${truncate(it.label)}" }
val lines = (listOfNotNull(lab) + lines().orEmpty()).ifEmpty { return }
ContextCompat.registerReceiver(
app,
object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { refresh(context) }
},
IntentFilter(BuildWatermarkSetting.CHANGED),
"${app.packageName}.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION",
null,
ContextCompat.RECEIVER_NOT_EXPORTED,
)
app.registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
if (activity is QuestXrActivity) return
val decor = activity.window.decorView as? ViewGroup ?: return
if (decor.findViewWithTag<View>(TAG) != null) return
val margin = (8 * activity.resources.displayMetrics.density).toInt()
decor.addView(
MarkView(activity, lines).apply { tag = TAG },
FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM or Gravity.END,
).apply { setMargins(margin, margin, margin, margin) },
)
synchronized(activities) { activities[activity] = Unit }
update(activity)
}
override fun onActivityStarted(activity: Activity) = Unit
override fun onActivityResumed(activity: Activity) = Unit
override fun onActivityResumed(activity: Activity) { update(activity) }
override fun onActivityPaused(activity: Activity) = Unit
override fun onActivityStopped(activity: Activity) = Unit
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit
override fun onActivityDestroyed(activity: Activity) = Unit
override fun onActivityDestroyed(activity: Activity) { synchronized(activities) { activities.remove(activity) } }
})
}
fun refresh(context: Context) {
val current = synchronized(activities) { activities.keys.toList() }
current.forEach(::update)
}
private fun update(activity: Activity) {
if (activity is QuestXrActivity) return
val decor = activity.window.decorView as? ViewGroup ?: return
decor.findViewWithTag<View>(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 margin = (8 * activity.resources.displayMetrics.density).toInt()
decor.addView(
MarkView(activity, content).apply { tag = TAG },
FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM or Gravity.END,
).apply { setMargins(margin, margin, margin, margin) },
)
}
private const val TAG = "build-watermark"
private class MarkView(context: Context, private val lines: List<String>) : View(context) {
@@ -108,6 +108,7 @@ class FrontEndState(
val vacDiagnostics: Boolean = false,
val agentCommands: Boolean = false,
val graphicsLogs: Boolean = false,
val buildWatermark: Boolean = true,
val steamGpuDrawing: Boolean = false,
val bridgeFellBack: Boolean = false,
val bridgeFellBackMemory: Boolean = false,
@@ -247,6 +248,7 @@ class FrontEndActions(
val onVacDiagnostics: () -> Unit = {},
val onAgentCommands: () -> Unit = {},
val onGraphicsLogs: () -> Unit = {},
val onBuildWatermark: () -> Unit = {},
val onSteamGpuDrawing: () -> Unit = {},
val onClearCachedApps: (Boolean) -> Unit = {},
val onMemoryHud: (String) -> Unit = {},
@@ -92,6 +92,7 @@ class UpdatesActions(
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
@Composable
internal fun UpdatesPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier) {
val host = rememberMenuHost()
val u = s.updates
val ua = a.updates
val me = remember { AppUpdates.installed() }
@@ -128,6 +129,12 @@ internal fun UpdatesPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie
Box(Modifier.weight(1.15f)) { StatusPanel(s, u, ua, me) }
}
}
Box(Modifier.padding(top = 18.dp)) {
ToggleRow(
host, "build-watermark", stringResource(R.string.setup_build_watermark),
stringResource(R.string.setup_build_watermark_hint), s.buildWatermark,
) { a.onBuildWatermark() }
}
}
}
}