From 565bd7c6b148b70ced51bd56ee0a8f3ee681b6d6 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Sat, 5 Dec 2026 16:24:52 -0500 Subject: [PATCH 1/8] fix(storage): record all-files access in session logs and warn when added games need it (#3470) * fix(storage): record all-files access in session logs and warn when added games need it * Cover all added games in storage access diagnostics --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> --- .../droiddeck/launcher/core/DeviceReport.kt | 1 + .../launcher/files/AllFilesAccess.kt | 9 ++++++++ .../launcher/session/SessionService.kt | 11 +++++++-- .../launcher/files/AllFilesAccessTest.kt | 23 +++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt index d94fbbb587..4beeec8d45 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt @@ -192,6 +192,7 @@ object DeviceReport { val fs = StatFs(Environment.getExternalStorageDirectory().path) k("Shared storage free", FileUtils.sizeToString(fs.availableBlocksLong * fs.blockSizeLong)) } + k("All files access", runCatching { com.droiddeck.launcher.files.AllFilesAccess.state() }.getOrNull()) h("GPU") k("KGSL gpu_model", readSys("/sys/class/kgsl/kgsl-3d0/gpu_model")) diff --git a/app/src/main/java/com/droiddeck/launcher/files/AllFilesAccess.kt b/app/src/main/java/com/droiddeck/launcher/files/AllFilesAccess.kt index 2c9529f4ed..94ea2e33f9 100644 --- a/app/src/main/java/com/droiddeck/launcher/files/AllFilesAccess.kt +++ b/app/src/main/java/com/droiddeck/launcher/files/AllFilesAccess.kt @@ -14,6 +14,15 @@ object AllFilesAccess { fun missing(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean = sdk >= Build.VERSION_CODES.R && !granted() + fun state(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): String = when { + sdk < Build.VERSION_CODES.R -> "not needed" + granted() -> "granted" + else -> "missing" + } + + fun mayHideFilesIn(path: String, sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean = + covers(path) && missing(sdk, granted) + /** Whether reading [path] takes all-files access: shared storage, outside the per-app folders directly under a volume's root, which Android always lets the app use. */ fun covers(path: String): Boolean { val inside = VOLUME.matchEntire(path)?.groupValues?.get(2) ?: return false diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 67992024db..5ad8fe253e 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -1355,10 +1355,17 @@ class SessionService : Service() { if (controllersOn) components.add(RumbleComponent().also { it.attach(this) }) val home = File(LinuxRuntime.rootDir(this), "root") File(home, "Storage").mkdirs() + val addedExeFolders = com.droiddeck.launcher.frontend.AddedExes.list(this).map { File(it.folder) }.distinctBy { it.path } + val addedGameRoots = com.droiddeck.launcher.frontend.AddedGames.roots(this) + val addedFolders = (addedExeFolders + addedGameRoots.map { it.host }).distinctBy { it.path } + for (folder in addedFolders) { + if (com.droiddeck.launcher.files.AllFilesAccess.mayHideFilesIn(folder.path)) + Log.w(TAG, "added games: Android may hide .exe files in $folder because All files access is missing") + } if (sharedStorage != null) { binds.add(sharedStorage.path + ":/root/Storage") } else { - for (folder in com.droiddeck.launcher.frontend.AddedExes.list(this).map { File(it.folder) }.distinctBy { it.path }) { + for (folder in addedExeFolders) { val guest = com.droiddeck.launcher.frontend.AddedGames.guestPath(this, folder) ?: continue if (!guest.startsWith("/root/Storage/") || !folder.isDirectory) continue File(LinuxRuntime.rootDir(this), guest.removePrefix("/")).mkdirs() @@ -1409,7 +1416,7 @@ class SessionService : Service() { Log.w(TAG, "storage diagnostics: selected library could not be identified; metadata snapshot only") } } - for (root in com.droiddeck.launcher.frontend.AddedGames.roots(this)) { + for (root in addedGameRoots) { if (root.host.isDirectory && root.host.canRead()) { File(LinuxRuntime.rootDir(this), root.guest.removePrefix("/")).mkdirs() binds.add(root.host.path + ":" + root.guest) diff --git a/app/src/test/java/com/droiddeck/launcher/files/AllFilesAccessTest.kt b/app/src/test/java/com/droiddeck/launcher/files/AllFilesAccessTest.kt index 0737cac0f7..25655e7547 100644 --- a/app/src/test/java/com/droiddeck/launcher/files/AllFilesAccessTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/files/AllFilesAccessTest.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.files +import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test @@ -37,4 +38,26 @@ class AllFilesAccessTest { assertFalse(AllFilesAccess.covers("/storage/1A2B-3C4D/Android/obb/com.droiddeck.launcher")) assertFalse(AllFilesAccess.covers("/data/user/0/com.droiddeck.launcher/files")) } + + @Test + fun stateNamesWhatTheReportShows() { + assertEquals("not needed", AllFilesAccess.state(sdk = 29) { false }) + assertEquals("missing", AllFilesAccess.state(sdk = 34) { false }) + assertEquals("granted", AllFilesAccess.state(sdk = 34) { true }) + } + + @Test + fun sharedStorageMayHideFilesOnlyWithoutAccess() { + assertTrue(AllFilesAccess.mayHideFilesIn("/storage/emulated/0", sdk = 34) { false }) + assertTrue(AllFilesAccess.mayHideFilesIn("/storage/1A2B-3C4D/Games", sdk = 34) { false }) + assertFalse(AllFilesAccess.mayHideFilesIn("/storage/emulated/0", sdk = 34) { true }) + assertFalse(AllFilesAccess.mayHideFilesIn("/storage/emulated/0", sdk = 29) { false }) + } + + @Test + fun appFoldersAndPrivateStorageNeverHideFiles() { + assertFalse(AllFilesAccess.mayHideFilesIn("/storage/emulated/0/Android/data/com.droiddeck.launcher/files", sdk = 34) { false }) + assertFalse(AllFilesAccess.mayHideFilesIn("/data/user/0/com.droiddeck.launcher/files/Games", sdk = 34) { false }) + assertFalse(AllFilesAccess.mayHideFilesIn("/mnt/media_rw/1A2B-3C4D", sdk = 34) { false }) + } } From 3b0c0d3496fe8c5ae82d9048b8dac1eaa8035dd4 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 5 Dec 2026 16:30:37 -0500 Subject: [PATCH 2/8] Add landscape-only fullscreen for launcher and sessions (#3764) Add portrait-aware fullscreen for launcher and sessions --- .../droiddeck/launcher/FrontEndActivity.kt | 31 +++++++++++++---- .../com/droiddeck/launcher/SessionActivity.kt | 33 ++++++++++++++----- .../launcher/session/FullscreenMode.kt | 18 ++++++++++ .../launcher/session/SessionPrefs.kt | 17 ++++++++-- .../launcher/session/SettingsReset.kt | 2 +- .../droiddeck/launcher/ui/FrontEndScreen.kt | 12 +++++-- .../droiddeck/launcher/ui/FrontEndSetup.kt | 17 +++++++--- .../droiddeck/launcher/ui/SessionOverlay.kt | 7 ++++ .../droiddeck/launcher/ui/SettingsIndex.kt | 3 +- app/src/main/res/values/strings.xml | 3 ++ docs/settings-map.md | 3 +- 11 files changed, 117 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/session/FullscreenMode.kt diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 8c9657f1f5..9a109df4d2 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -52,6 +52,7 @@ import com.droiddeck.launcher.ui.ComponentsPage import com.droiddeck.launcher.session.GameSaves import com.droiddeck.launcher.session.SessionLogShare import com.droiddeck.launcher.session.SessionPaths +import com.droiddeck.launcher.session.FullscreenMode import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.session.SteamRepair import com.droiddeck.launcher.session.LaunchCoordinator @@ -208,7 +209,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) private var launcherOrientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER) private var homePage by mutableStateOf(com.droiddeck.launcher.core.AppUiPrefs.HOME_PAGE_STEAM) - private var launcherFullscreen by mutableStateOf(true) + private var launcherFullscreenMode by mutableStateOf(FullscreenMode.ALWAYS) + private var sessionFullscreenMode by mutableStateOf(FullscreenMode.ALWAYS) private var launcherFrost by mutableStateOf(false) private var frostWallpaper by mutableStateOf(true) private var frostCards by mutableStateOf(true) @@ -1366,8 +1368,12 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet orientation = SessionPrefs.orientation(this) launcherOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this) requestedOrientation = launcherOrientation + launcherFullscreenMode = SessionPrefs.launcherFullscreenMode(this) + sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this) + applyLauncherFullscreen() homePage = com.droiddeck.launcher.core.AppUiPrefs.homePage(this) - launcherFullscreen = SessionPrefs.launcherFullscreen(this) + launcherFullscreenMode = SessionPrefs.launcherFullscreenMode(this) + sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this) launcherFrost = SessionPrefs.launcherFrost(this) frostWallpaper = SessionPrefs.frostWallpaper(this) frostCards = SessionPrefs.frostCards(this) @@ -1482,7 +1488,8 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet orientation = orientation, launcherOrientation = launcherOrientation, homePage = homePage, - launcherFullscreen = launcherFullscreen, + launcherFullscreenMode = launcherFullscreenMode, + sessionFullscreenMode = sessionFullscreenMode, launcherFrost = launcherFrost, frostWallpaper = frostWallpaper, frostCards = frostCards, @@ -1816,11 +1823,15 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet homePage = value }, onControllerHaptics = { on -> SessionPrefs.setControllerHaptics(this, on); controllerHaptics = on }, - onLauncherFullscreen = { on -> - SessionPrefs.setLauncherFullscreen(this, on) - launcherFullscreen = on + onLauncherFullscreenMode = { mode -> + SessionPrefs.setLauncherFullscreenMode(this, mode) + launcherFullscreenMode = mode applyLauncherFullscreen() }, + onSessionFullscreenMode = { mode -> + SessionPrefs.setSessionFullscreenMode(this, mode) + sessionFullscreenMode = mode + }, onLauncherFrost = { on -> SessionPrefs.setLauncherFrost(this, on) launcherFrost = on @@ -2152,7 +2163,13 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet private fun frostShown(): Boolean = launcherFrost && frostWallpaper && frost.prepared && frost.available && theme != com.droiddeck.launcher.ui.Themes.TRUE_BLACK - private fun applyLauncherFullscreen() { + override fun onConfigurationChanged(newConfig: android.content.res.Configuration) { + super.onConfigurationChanged(newConfig) + applyLauncherFullscreen(newConfig) + } + + private fun applyLauncherFullscreen(config: android.content.res.Configuration = resources.configuration) { + val launcherFullscreen = launcherFullscreenMode.hidesSystemBars(config.orientation) @Suppress("DEPRECATION") window.decorView.systemUiVisibility = if (launcherFullscreen) { (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 732b26620a..371d200f47 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -128,6 +128,7 @@ import com.droiddeck.launcher.session.GpuClockPin import com.droiddeck.launcher.session.GameProfileFollowState import com.droiddeck.launcher.session.GameProfileInventoryCache import com.droiddeck.launcher.session.GameProfileRefreshState +import com.droiddeck.launcher.session.FullscreenMode import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.session.SessionEvents import com.droiddeck.launcher.session.SessionArtifacts @@ -643,6 +644,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var drawerControllerActive by mutableStateOf(false) private var backHold by mutableStateOf(true) private var dockedMenuController by mutableStateOf(false) + private var sessionFullscreenMode by mutableStateOf(FullscreenMode.ALWAYS) private var sessionOrientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) private var dualScreenSessionMode by mutableStateOf(com.droiddeck.launcher.input.DualScreen.MODE_AUTO) private var backActionsInverted by mutableStateOf(false) @@ -940,7 +942,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } applyFollowChoice() applyFollowOrientation(resources.configuration) - goFullscreen() + sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this) + applySessionFullscreen() volumeControlStream = android.media.AudioManager.STREAM_MUSIC displayManager = getSystemService(DISPLAY_SERVICE) as DisplayManager refreshSecondScreenDisplays() @@ -2103,6 +2106,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde onPause = ::pauseNow, paused = SessionState.suspended || SessionState.manualPause, onResume = { SessionService.resume(this@SessionActivity) }, + fullscreenMode = sessionFullscreenMode, + onFullscreenMode = { mode -> + SessionPrefs.setSessionFullscreenMode(this@SessionActivity, mode) + sessionFullscreenMode = mode + applySessionFullscreen() + }, orientation = sessionOrientation, onOrientation = { value -> when (SessionState.mode) { @@ -3309,6 +3318,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde override fun onConfigurationChanged(newConfig: android.content.res.Configuration) { super.onConfigurationChanged(newConfig) + if (!pipUi && !isInPictureInPictureMode) applySessionFullscreen(newConfig) picturePosition = SessionPrefs.picturePosition(this, picturePortrait(newConfig)) if (refreshActivityDisplayId() && started) { SessionService.setActivityDisplay(this, sessionActivityDisplayId) @@ -6669,6 +6679,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde uiHandler.removeCallbacks(questSteamVrRequest) if (com.droiddeck.launcher.session.QuestExperimental.isSupported()) uiHandler.post(questSteamVrRequest) if (runtimeRemovalBlocked) return + sessionFullscreenMode = SessionPrefs.sessionFullscreenMode(this) + if (!pipUi && !isInPictureInPictureMode) applySessionFullscreen() if (!SessionState.suspended) pausedFrame = null com.droiddeck.launcher.ui.Motion.refresh(this) refreshHomeApp() @@ -7382,7 +7394,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (hasFocus && airTriggersOpen) RedMagicAirTriggers.open(this) if (hasFocus && !pipUi) { retryFieldKeyboard(true) - goFullscreen() + applySessionFullscreen() refreshClipboard() } updatePointerCapture() @@ -7392,19 +7404,24 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (resumed) sessionClipboard.refresh() } - private fun goFullscreen() { + private fun applySessionFullscreen(config: android.content.res.Configuration = resources.configuration) { + val fullscreen = sessionFullscreenMode.hidesSystemBars(config.orientation) + if (fullscreen) window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) + else window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) @Suppress("DEPRECATION") - window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + window.decorView.systemUiVisibility = if (fullscreen) (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) + or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) else View.SYSTEM_UI_FLAG_LAYOUT_STABLE if (Build.VERSION.SDK_INT >= 28) { window.attributes = window.attributes.apply { - layoutInDisplayCutoutMode = if (Build.VERSION.SDK_INT >= 30) - WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS - else WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + layoutInDisplayCutoutMode = when { + !fullscreen -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT + Build.VERSION.SDK_INT >= 30 -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS + else -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + } } } } diff --git a/app/src/main/java/com/droiddeck/launcher/session/FullscreenMode.kt b/app/src/main/java/com/droiddeck/launcher/session/FullscreenMode.kt new file mode 100644 index 0000000000..9d3cdd2e21 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/FullscreenMode.kt @@ -0,0 +1,18 @@ +package com.droiddeck.launcher.session + +import android.content.res.Configuration +import androidx.annotation.StringRes +import com.droiddeck.launcher.R + +enum class FullscreenMode(@StringRes val label: Int) { + ALWAYS(R.string.widgets_on), + LANDSCAPE_ONLY(R.string.setup_fullscreen_landscape_only), + OFF(R.string.widgets_off); + + fun hidesSystemBars(orientation: Int): Boolean = + this == ALWAYS || (this == LANDSCAPE_ONLY && orientation == Configuration.ORIENTATION_LANDSCAPE) + + companion object { + fun fromStored(value: String?): FullscreenMode? = entries.firstOrNull { it.name == value } + } +} 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 24ed5f199b..e42c8f48a5 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -112,10 +112,21 @@ object SessionPrefs { else -> false } - fun launcherFullscreen(context: Context): Boolean = prefs(context).getBoolean("launcherFullscreen", true) + fun launcherFullscreenMode(context: Context): FullscreenMode { + val preferences = prefs(context) + return FullscreenMode.fromStored(preferences.getString("launcherFullscreenMode", null)) + ?: if (preferences.getBoolean("launcherFullscreen", true)) FullscreenMode.ALWAYS else FullscreenMode.OFF + } - fun setLauncherFullscreen(context: Context, on: Boolean) { - prefs(context).edit().putBoolean("launcherFullscreen", on).apply() + fun setLauncherFullscreenMode(context: Context, mode: FullscreenMode) { + prefs(context).edit().putString("launcherFullscreenMode", mode.name).apply() + } + + fun sessionFullscreenMode(context: Context): FullscreenMode = + FullscreenMode.fromStored(prefs(context).getString("sessionFullscreenMode", null)) ?: FullscreenMode.ALWAYS + + fun setSessionFullscreenMode(context: Context, mode: FullscreenMode) { + prefs(context).edit().putString("sessionFullscreenMode", mode.name).apply() } fun launcherFrost(context: Context): Boolean = prefs(context).getBoolean("launcherFrost", false) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt index e4fb6ed9c3..c9852d4b8b 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt @@ -12,7 +12,7 @@ object SettingsReset { private const val TAG = "SettingsReset" internal val SESSION_KEYS = setOf( - "orientation", "launcherFullscreen", "launcherFrost", "frostWallpaper", "frostCards", "frostTransparency", "frostCardTransparency", "controllerHaptics", "animations", "lowStorageWarning", "theme", "runSteamAtStartup", "startupSession", "addedGamesArt", + "orientation", "launcherFullscreen", "launcherFullscreenMode", "sessionFullscreenMode", "launcherFrost", "frostWallpaper", "frostCards", "frostTransparency", "frostCardTransparency", "controllerHaptics", "animations", "lowStorageWarning", "theme", "runSteamAtStartup", "startupSession", "addedGamesArt", "drawerWidthDp", "dualScreenMode", "dualScreenSessionMode", "dualScreenLauncher", "dualScreenSessionControls", "androidTextFieldKeyboard", "soundtracksIngame", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature", "storesInstallLanguage", diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 917a46e71d..ff50841c75 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -88,6 +88,7 @@ import com.droiddeck.launcher.input.SecondScreenDisplay import com.droiddeck.launcher.core.DownloadSource import com.droiddeck.launcher.core.PhantomProcessLimit import com.droiddeck.launcher.core.PhantomProcessStatus +import com.droiddeck.launcher.session.FullscreenMode import com.droiddeck.launcher.session.SessionPrefs import kotlin.math.roundToInt import kotlinx.coroutines.withTimeoutOrNull @@ -176,7 +177,8 @@ class FrontEndState( val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, val launcherOrientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER, val homePage: String = com.droiddeck.launcher.core.AppUiPrefs.HOME_PAGE_STEAM, - val launcherFullscreen: Boolean = true, + val launcherFullscreenMode: FullscreenMode = FullscreenMode.ALWAYS, + val sessionFullscreenMode: FullscreenMode = FullscreenMode.ALWAYS, val launcherFrost: Boolean = false, val frostWallpaper: Boolean = true, val frostCards: Boolean = true, @@ -288,7 +290,8 @@ class FrontEndActions( val onOrientation: (Int) -> Unit = {}, val onLauncherOrientation: (Int) -> Unit = {}, val onHomePage: (String) -> Unit = {}, - val onLauncherFullscreen: (Boolean) -> Unit = {}, + val onLauncherFullscreenMode: (FullscreenMode) -> Unit = {}, + val onSessionFullscreenMode: (FullscreenMode) -> Unit = {}, val onLauncherFrost: (Boolean) -> Unit = {}, val onFrostWallpaper: (Boolean) -> Unit = {}, val onFrostCards: (Boolean) -> Unit = {}, @@ -711,9 +714,12 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com if (anyFocused) return } } + val launcherFullscreen = s.launcherFullscreenMode.hidesSystemBars( + androidx.compose.ui.platform.LocalConfiguration.current.orientation, + ) androidx.compose.foundation.layout.BoxWithConstraints( modifier = Modifier.fillMaxSize().background(if (LocalFrost.current != null) Color.Transparent else colors.background) - .windowInsetsPadding(if (s.launcherFullscreen) WindowInsets.displayCutout else WindowInsets.systemBars) + .windowInsetsPadding(if (launcherFullscreen) WindowInsets.displayCutout else WindowInsets.systemBars) .onFocusChanged { anyFocused = it.hasFocus }, ) { val bottomNavigation = maxHeight > maxWidth diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 4047781350..0cda817452 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -85,6 +85,7 @@ import com.droiddeck.launcher.core.DeviceSupport import com.droiddeck.launcher.core.DownloadSource import com.droiddeck.launcher.core.PhantomProcessLimit import com.droiddeck.launcher.core.PhantomProcessStatus +import com.droiddeck.launcher.session.FullscreenMode import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.stores.download.StoreDownloadTier import com.droiddeck.launcher.R @@ -586,11 +587,17 @@ internal fun SetupPanel( SessionPrefs.setOrientation(ctx, "desktop", value) }, ) - ToggleRow( - host, "launcher-fullscreen", stringResource(R.string.setup_fullscreen), - if (s.launcherFullscreen) stringResource(R.string.setup_fullscreen_on) else stringResource(R.string.setup_fullscreen_off), - s.launcherFullscreen, - ) { a.onLauncherFullscreen(it) } + val fullscreenModes = FullscreenMode.entries.map { it to stringResource(it.label) } + ChoiceRow( + host, "launcher-fullscreen", stringResource(R.string.setup_launcher_fullscreen), + stringResource(R.string.setup_fullscreen_on), + fullscreenModes, s.launcherFullscreenMode, onPick = a.onLauncherFullscreenMode, + ) + ChoiceRow( + host, "session-fullscreen", stringResource(R.string.setup_session_fullscreen), + stringResource(R.string.setup_fullscreen_on), + fullscreenModes, s.sessionFullscreenMode, onPick = a.onSessionFullscreenMode, + ) ToggleRow( host, "page-swipe", stringResource(R.string.setup_page_swipe), stringResource(R.string.setup_page_swipe_hint), PageSwipe.on, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index a2647da77f..6e843c212d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -177,6 +177,7 @@ import com.droiddeck.launcher.gpu.ScreenEffectLooks import com.droiddeck.launcher.gpu.Cardboard import com.droiddeck.launcher.gpu.SteamVr import com.droiddeck.launcher.gpu.ScreenEffects +import com.droiddeck.launcher.session.FullscreenMode import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.session.ComponentsManager import com.droiddeck.launcher.input.PC_KEY_GROUP_IDS @@ -406,6 +407,8 @@ class DrawerActions( val paused: Boolean = false, val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, val onOrientation: (Int) -> Unit = {}, + val fullscreenMode: FullscreenMode = FullscreenMode.ALWAYS, + val onFullscreenMode: (FullscreenMode) -> Unit = {}, val onResume: () -> Unit = {}, val onPipAutoEnter: (Boolean) -> Unit = {}, val unfoldedControls: Boolean? = null, @@ -1009,6 +1012,10 @@ private fun DrawerDisplayPage(host: MenuHost, a: DrawerActions, track: (String) if (a.gameZoomAvailable) GameZoomRow(a.gameZoom, track, a.onGameZoom) ChoiceRow(host, "orientation", stringResource(R.string.setup_session_orientation), null, orientations, a.orientation, chipModifier = track("orientation"), onPick = a.onOrientation) + ChoiceRow(host, "session-fullscreen", stringResource(R.string.setup_session_fullscreen), + stringResource(R.string.setup_fullscreen_on), + FullscreenMode.entries.map { it to stringResource(it.label) }, a.fullscreenMode, + chipModifier = track("session-fullscreen"), onPick = a.onFullscreenMode) if (a.steam) PicturePositionRow(host, a.picturePosition, track("picture-position"), onPick = a.onPicturePosition) } val filters = SessionPrefs.upscalerChoices(LocalContext.current) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt index 5983063e1e..f9bc7c1663 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsIndex.kt @@ -116,7 +116,8 @@ internal object SettingsIndex { s(SettingsSection.LAUNCHER, R.string.setup_home, "home screen", "launcher"), s(SettingsSection.LAUNCHER, R.string.setup_launcher_orientation, "rotate", "portrait"), s(SettingsSection.LAUNCHER, R.string.setup_session_orientation, "rotate", "portrait"), - s(SettingsSection.LAUNCHER, R.string.setup_fullscreen), + s(SettingsSection.LAUNCHER, R.string.setup_launcher_fullscreen, "status bar", "navigation bar", "portrait"), + s(SettingsSection.LAUNCHER, R.string.setup_session_fullscreen, "status bar", "navigation bar", "portrait"), s(SettingsSection.LAUNCHER, R.string.setup_page_swipe, "gesture"), s(SettingsSection.LAUNCHER, R.string.setup_controller_haptics, "vibration", "rumble"), s(SettingsSection.LAUNCHER, R.string.setup_dual_screen_launcher, "thor", "second screen", "bottom screen"), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c9a8dd1d3d..26c5d04baa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1042,6 +1042,9 @@ Landscape Reverse landscape Fullscreen + Launcher fullscreen + Session fullscreen + Landscape only Hides the Android status and navigation bars Shows the Android status and navigation bars Swipe between pages diff --git a/docs/settings-map.md b/docs/settings-map.md index aface4f407..e3138eee65 100644 --- a/docs/settings-map.md +++ b/docs/settings-map.md @@ -45,7 +45,8 @@ Links of the form `droiddeck://settings/
` open a Settings section direc | Use as Home screen | Settings › Launcher (`droiddeck://settings/launcher`) | home screen, launcher | | Launcher orientation | Settings › Launcher (`droiddeck://settings/launcher`) | rotate, portrait | | Session orientation | Settings › Launcher (`droiddeck://settings/launcher`) | rotate, portrait | -| Fullscreen | Settings › Launcher (`droiddeck://settings/launcher`) | | +| Launcher fullscreen | Settings › Launcher (`droiddeck://settings/launcher`) | status bar, navigation bar, portrait | +| Session fullscreen | Settings › Launcher (`droiddeck://settings/launcher`) | status bar, navigation bar, portrait | | Swipe between pages | Settings › Launcher (`droiddeck://settings/launcher`) | gesture | | Controller haptics | Settings › Launcher (`droiddeck://settings/launcher`) | vibration, rumble | | Dual screen launcher | Settings › Launcher (`droiddeck://settings/launcher`) | thor, second screen, bottom screen | From 423f600d4b9aeafbd3afdd4f5c2535192ea94a5b Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 5 Dec 2026 16:31:37 -0500 Subject: [PATCH 3/8] Match the Dev Harness dropdown to the usage tracker (#3762) Match the agent model picker to the usage panel --- .../java/com/droiddeck/launcher/ui/AgentPanels.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AgentPanels.kt b/app/src/main/java/com/droiddeck/launcher/ui/AgentPanels.kt index a462fca130..db538977f5 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AgentPanels.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AgentPanels.kt @@ -67,13 +67,18 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.withContext +@Composable +private fun agentPanelFrame(): Modifier = + Modifier.fillMaxWidth().clip(Shape14).background(MaterialTheme.colorScheme.surface) + .border(1.dp, LocalPalette.current.line, Shape14).padding(horizontal = 14.dp, vertical = 10.dp) + /** The model, reasoning effort, permissions and plan mode for the next turns; a conversation keeps going with whatever is chosen. */ @Composable internal fun AgentModelPicker() { val context = LocalContext.current val pal = LocalPalette.current val models = remember(AgentHost.harness) { AgentHost.models(context) } - Column(Modifier.fillMaxWidth().padding(bottom = 10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) { + Column(agentPanelFrame(), verticalArrangement = Arrangement.spacedBy(10.dp)) { Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.horizontalScroll(rememberScrollState())) { val choices = listOf(AgentHarness.Model("", stringResource(R.string.agent_model_default))) + models for (choice in choices) { @@ -269,12 +274,8 @@ internal fun AgentProcessList(modifier: Modifier) { @Composable internal fun AgentUsage() { val context = LocalContext.current - val colors = MaterialTheme.colorScheme val pal = LocalPalette.current - Column( - Modifier.fillMaxWidth().clip(Shape14).background(colors.surface).border(1.dp, pal.line, Shape14).padding(horizontal = 14.dp, vertical = 10.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - ) { + Column(agentPanelFrame(), verticalArrangement = Arrangement.spacedBy(8.dp)) { if (AgentHost.window > 0) UsageRow( stringResource(R.string.agent_usage_context), stringResource(R.string.agent_usage_of, tokens(AgentHost.context), tokens(AgentHost.window)), From 16ea8d9168c9b2cdbb21c2c071c1757f7b88c311 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 5 Dec 2026 17:19:51 -0500 Subject: [PATCH 4/8] Use a keypad for wireless debugging pairing codes (#3766) * Use a keypad for wireless debugging pairing codes * Make wireless pairing keys legible in SystemUI * Fit both keypad rows in the heads-up notification * Find the verified loopback ADB port after pairing * Post the pairing keypad as a separate heads-up alert * Keep the pairing keypad accessible and recover rotated ADB ports * Show how to keep the pairing popup open --- README.md | 7 + .../droiddeck/launcher/core/WirelessAdbFix.kt | 32 ++++- .../core/WirelessAdbPairingService.kt | 129 ++++++++++++++---- .../launcher/core/WirelessPairingKeypad.kt | 29 ++++ .../res/color/wireless_pairing_key_text.xml | 5 + .../res/drawable/wireless_pairing_key.xml | 15 ++ .../res/drawable/wireless_pairing_panel.xml | 5 + .../res/layout/wireless_pairing_keypad.xml | 38 ++++++ app/src/main/res/values-ar/strings.xml | 1 - app/src/main/res/values-b+es+419/strings.xml | 1 - app/src/main/res/values-bg/strings.xml | 1 - app/src/main/res/values-cs/strings.xml | 1 - app/src/main/res/values-da/strings.xml | 1 - app/src/main/res/values-de/strings.xml | 1 - app/src/main/res/values-el/strings.xml | 1 - app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-fi/strings.xml | 1 - app/src/main/res/values-fr/strings.xml | 1 - app/src/main/res/values-hi/strings.xml | 1 - app/src/main/res/values-hu/strings.xml | 1 - app/src/main/res/values-in/strings.xml | 1 - app/src/main/res/values-it/strings.xml | 1 - app/src/main/res/values-ja/strings.xml | 1 - app/src/main/res/values-ko/strings.xml | 1 - app/src/main/res/values-ms/strings.xml | 1 - app/src/main/res/values-nb/strings.xml | 1 - app/src/main/res/values-nl/strings.xml | 1 - app/src/main/res/values-pl/strings.xml | 1 - app/src/main/res/values-pt-rPT/strings.xml | 1 - app/src/main/res/values-pt/strings.xml | 1 - app/src/main/res/values-ro/strings.xml | 1 - app/src/main/res/values-ru/strings.xml | 1 - app/src/main/res/values-sv/strings.xml | 1 - app/src/main/res/values-th/strings.xml | 1 - app/src/main/res/values-tr/strings.xml | 1 - app/src/main/res/values-uk/strings.xml | 1 - app/src/main/res/values-vi/strings.xml | 1 - app/src/main/res/values-zh-rCN/strings.xml | 1 - app/src/main/res/values-zh-rHK/strings.xml | 1 - app/src/main/res/values-zh-rTW/strings.xml | 1 - .../main/res/values/pairing_keypad_styles.xml | 19 +++ app/src/main/res/values/strings.xml | 7 +- .../launcher/core/WirelessAdbReconnectTest.kt | 57 ++++++++ .../core/WirelessPairingKeypadTest.kt | 38 ++++++ 44 files changed, 346 insertions(+), 67 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/core/WirelessPairingKeypad.kt create mode 100644 app/src/main/res/color/wireless_pairing_key_text.xml create mode 100644 app/src/main/res/drawable/wireless_pairing_key.xml create mode 100644 app/src/main/res/drawable/wireless_pairing_panel.xml create mode 100644 app/src/main/res/layout/wireless_pairing_keypad.xml create mode 100644 app/src/main/res/values/pairing_keypad_styles.xml create mode 100644 app/src/test/java/com/droiddeck/launcher/core/WirelessAdbReconnectTest.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/core/WirelessPairingKeypadTest.kt diff --git a/README.md b/README.md index 021fed17b3..d6616b1ab7 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,13 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V +
+Setup and tools + +- The wireless debugging pairing keypad was inspired by Ryan Retro’s Handheld Toolkit. + +
+ ## Star history diff --git a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbFix.kt b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbFix.kt index 64087a24f3..e9f8bbdfaa 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbFix.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbFix.kt @@ -119,7 +119,7 @@ object WirelessAdbFix { * socket table, and mDNS often advertises nothing, so the ephemeral range Linux gives adbd is * scanned on loopback (closed ports refuse at once) and the open ports are tried with our key. */ - private fun loopbackAdbPort(app: Context): Int? { + private fun loopbackAdbPort(app: Context, exclude: Int? = null): Int? { val open = java.util.concurrent.ConcurrentLinkedQueue() val workers = 32 val range = EPHEMERAL_PORTS @@ -127,7 +127,7 @@ object WirelessAdbFix { Thread { var port = range.first + worker while (port <= range.last) { - if (answers(LOOPBACK, port, 150)) open += port + if (port != exclude && answers(LOOPBACK, port, 150)) open += port port += workers } }.apply { start() } @@ -162,8 +162,28 @@ object WirelessAdbFix { }.getOrDefault(address is Inet4Address) fun localConnectPort(context: Context): Int? = - tlsPortProperty() - ?: findConnectPort(context, LOOPBACK) + discoverConnectPort(context, LOOPBACK) + + private fun discoverConnectPort(context: Context, host: String, exclude: Int? = null): Int? = + chooseConnectPort(host, exclude, + property = ::tlsPortProperty, + advertised = { acceptable -> findConnectPort(context, host, accept = acceptable) }, + answers = { port -> answers(host, port) }, + // Some local devices never advertise their connect port. Try only + // loopback and require the app's existing paired key to authenticate. + authenticatedLocal = { loopbackAdbPort(context.applicationContext, exclude) }, + ) + + internal fun chooseConnectPort( + host: String, exclude: Int?, + property: () -> Int?, advertised: ((Int) -> Boolean) -> Int?, + answers: (Int) -> Boolean, authenticatedLocal: () -> Int?, + ): Int? { + val local = host == LOOPBACK + val acceptable: (Int) -> Boolean = { port -> port != exclude && (!local || answers(port)) } + val propertyPort = if (local) property()?.takeIf(acceptable) else null + return propertyPort ?: advertised(acceptable) ?: if (local) authenticatedLocal() else null + } private fun tlsPortProperty(): Int? = runCatching { Class.forName("android.os.SystemProperties").getMethod("get", String::class.java) @@ -301,14 +321,14 @@ object WirelessAdbFix { if (cachedPort != null) { val cachedResult = runCatching { action(appContext, saved.host, cachedPort) } if (cachedResult.isSuccess) return - val discoveredPort = findConnectPort(appContext, saved.host) + val discoveredPort = discoverConnectPort(appContext, saved.host, exclude = cachedPort) if (discoveredPort != null && discoveredPort != cachedPort) { action(appContext, saved.host, discoveredPort) } else { cachedResult.getOrThrow() } } else { - val discoveredPort = findConnectPort(appContext, saved.host) + val discoveredPort = discoverConnectPort(appContext, saved.host) ?: error(appContext.getString(R.string.adbfix_enter_address)) action(appContext, saved.host, discoveredPort) } diff --git a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt index f7097dce7c..d1e2d911e8 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/WirelessAdbPairingService.kt @@ -4,20 +4,23 @@ import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent -import android.app.RemoteInput import android.app.Service import android.content.Context import android.content.Intent +import android.net.Uri import android.net.nsd.NsdManager import android.net.nsd.NsdServiceInfo import android.os.Build import android.os.Handler import android.os.IBinder import android.os.Looper +import android.util.TypedValue +import android.widget.RemoteViews import com.droiddeck.launcher.FrontEndActivity import com.droiddeck.launcher.R import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import java.util.UUID class WirelessAdbPairingService : Service() { override fun attachBaseContext(newBase: android.content.Context) = @@ -37,6 +40,8 @@ class WirelessAdbPairingService : Service() { private var discovery: NsdManager.DiscoveryListener? = null private var pairingHost: String? = null private var pairingPort: Int? = null + private val keypad = WirelessPairingKeypad() + private var keypadToken = UUID.randomUUID().toString() @Volatile private var working = false @Volatile private var limitEnabled = false @Volatile private var session = 0 @@ -46,13 +51,21 @@ class WirelessAdbPairingService : Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { when (intent?.action) { - ACTION_CODE -> { - val code = RemoteInput.getResultsFromIntent(intent)?.getCharSequence(KEY_CODE) - ?.filter(Char::isDigit)?.toString().orEmpty() - onCode(code) + ACTION_KEYPAD -> { + if (intent.data?.host == keypadToken && current.value is Stage.CodeNeeded && !working) { + val key = intent.data?.lastPathSegment?.toIntOrNull() + if (key == WirelessPairingKeypad.SUBMIT) { + if (keypad.ready && pairingPort != null) onCode(keypad.digits) + } else if (key != null && keypad.press(key)) { + show(current.value, quietUpdate = true) + } + } else if (current.value == Stage.Idle) { + stopSelf(startId) + } } ACTION_CANCEL -> finish(Stage.Idle) - else -> begin(intent?.getBooleanExtra(EXTRA_ENABLE_LIMIT, false) == true) + null -> begin(intent?.getBooleanExtra(EXTRA_ENABLE_LIMIT, false) == true) + else -> if (discovery == null && !working) stopSelf(startId) } return START_NOT_STICKY } @@ -60,11 +73,13 @@ class WirelessAdbPairingService : Service() { private fun begin(enableLimit: Boolean) { if (working) return session++ + resetKeypad() limitEnabled = enableLimit pairingHost = null pairingPort = null working = false publish(Stage.Waiting) + getSystemService(NotificationManager::class.java)?.cancel(KEYPAD_NOTIFICATION_ID) startForeground(NOTIFICATION_ID, notification(Stage.Waiting)) startDiscovery() main.removeCallbacks(timeout) @@ -101,9 +116,13 @@ class WirelessAdbPairingService : Service() { if (!WirelessAdbFix.isLocalAddress(address)) return main.post { if (owner != session || working || current.value == Stage.Done) return@post + val endpointChanged = pairingHost != address.hostAddress || pairingPort != serviceInfo.port pairingHost = address.hostAddress pairingPort = serviceInfo.port - if (current.value !is Stage.CodeNeeded) show(Stage.CodeNeeded()) + if (endpointChanged) { + resetKeypad() + show(Stage.CodeNeeded()) + } } } } @@ -117,11 +136,12 @@ class WirelessAdbPairingService : Service() { show(Stage.Waiting) return } - if (code.length != 6) { + if (code.length != WirelessPairingKeypad.LENGTH) { show(Stage.CodeNeeded(getString(R.string.adbpair_six_digits))) return } working = true + resetKeypad() val owner = session val enable = limitEnabled show(Stage.Working(getString(R.string.adbpair_pairing))) @@ -155,17 +175,34 @@ class WirelessAdbPairingService : Service() { }, "wireless-adb-pairing").start() } - private fun show(stage: Stage) { + private fun show(stage: Stage, quietUpdate: Boolean = false) { publish(stage) - getSystemService(NotificationManager::class.java)?.notify(NOTIFICATION_ID, notification(stage)) + val manager = getSystemService(NotificationManager::class.java) ?: return + if (stage is Stage.CodeNeeded) { + // A new high-priority notification can pop over Settings. Updating the + // quiet foreground-service notification can leave the keypad in the shade. + // End any previous indeterminate progress even if this is a code retry. + if (!quietUpdate) manager.notify(NOTIFICATION_ID, notification(stage, foregroundCodeEntry = true)) + manager.notify(KEYPAD_NOTIFICATION_ID, notification(stage, quietUpdate)) + } else { + manager.cancel(KEYPAD_NOTIFICATION_ID) + manager.notify(NOTIFICATION_ID, notification(stage, quietUpdate)) + } + } + + private fun resetKeypad() { + keypad.clear() + keypadToken = UUID.randomUUID().toString() } private fun finish(stage: Stage) { session++ + resetKeypad() main.removeCallbacks(timeout) stopDiscovery() publish(stage) val manager = getSystemService(NotificationManager::class.java) + manager?.cancel(KEYPAD_NOTIFICATION_ID) if (stage is Stage.Done || stage is Stage.Failed) { manager?.notify(NOTIFICATION_ID, notification(stage)) stopForeground(STOP_FOREGROUND_DETACH) @@ -183,13 +220,16 @@ class WirelessAdbPairingService : Service() { } override fun onDestroy() { + getSystemService(NotificationManager::class.java)?.cancel(KEYPAD_NOTIFICATION_ID) main.removeCallbacks(timeout) stopDiscovery() if (current.value.let { it is Stage.Waiting || it is Stage.CodeNeeded || it is Stage.Working }) publish(Stage.Idle) super.onDestroy() } - private fun notification(stage: Stage): Notification { + private fun notification( + stage: Stage, quietUpdate: Boolean = false, foregroundCodeEntry: Boolean = false, + ): Notification { val manager = getSystemService(NotificationManager::class.java) manager?.createNotificationChannel(NotificationChannel(CHANNEL_ID, getString(R.string.adbpair_channel_name), NotificationManager.IMPORTANCE_HIGH).apply { @@ -205,7 +245,7 @@ class WirelessAdbPairingService : Service() { PendingIntent.FLAG_IMMUTABLE) val cancel = PendingIntent.getService(this, 1, Intent(this, WirelessAdbPairingService::class.java).setAction(ACTION_CANCEL), PendingIntent.FLAG_IMMUTABLE) - val quiet = stage == Stage.Waiting || stage == Stage.Idle || stage is Stage.Working + val quiet = foregroundCodeEntry || stage == Stage.Waiting || stage == Stage.Idle || stage is Stage.Working val builder = Notification.Builder(this, if (quiet) PROGRESS_CHANNEL_ID else CHANNEL_ID) .setSmallIcon(R.drawable.ic_stat_session) .setContentIntent(open) @@ -220,19 +260,31 @@ class WirelessAdbPairingService : Service() { .setOnlyAlertOnce(true) .addAction(Notification.Action.Builder(null, getString(R.string.common_cancel), cancel).build()) is Stage.CodeNeeded -> { - val reply = PendingIntent.getService(this, 2, - Intent(this, WirelessAdbPairingService::class.java).setAction(ACTION_CODE), - if (Build.VERSION.SDK_INT >= 31) PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT - else PendingIntent.FLAG_UPDATE_CURRENT) - val input = RemoteInput.Builder(KEY_CODE).setLabel(getString(R.string.adbpair_code_label)).build() - val text = stage.error ?: getString(R.string.adbpair_code_hint) builder - .setContentTitle(getString(if (stage.error == null) R.string.adbpair_title_code else R.string.adbpair_title_retry)) - .setContentText(text) - .setStyle(Notification.BigTextStyle().bigText(text)) + .setContentTitle(getString(if (foregroundCodeEntry) R.string.adbpair_title_pair + else if (stage.error == null) R.string.adbpair_title_code else R.string.adbpair_title_retry)) + .setContentIntent(null) + .setVisibility(Notification.VISIBILITY_SECRET) + .setLocalOnly(true) .setOngoing(true) - .addAction(Notification.Action.Builder(null, getString(R.string.adbpair_enter_code), reply).addRemoteInput(input).build()) - .addAction(Notification.Action.Builder(null, getString(R.string.common_cancel), cancel).build()) + .setOnlyAlertOnce(foregroundCodeEntry || quietUpdate) + if (!foregroundCodeEntry) { + // Keep the keypad separate from status/install notifications. Android owns + // the heads-up timeout; the drawer remains usable without expanding a group. + builder.setGroup(KEYPAD_GROUP) + .addAction(Notification.Action.Builder(null, getString(R.string.common_cancel), cancel).build()) + if (stage.error != null && pairingPort == null) { + builder.setContentText(stage.error) + .setStyle(Notification.BigTextStyle().bigText(stage.error)) + } else { + builder.setStyle(Notification.DecoratedCustomViewStyle()) + .setCustomBigContentView(pairingKeypad()) + .setCustomHeadsUpContentView(pairingKeypad(keyHeightDp = 24)) + if (Build.VERSION.SDK_INT >= 31) { + builder.setCustomContentView(pairingKeypad(keyHeightDp = 21)) + } + } + } } is Stage.Working -> builder .setContentTitle(getString(R.string.adbpair_title_working)) @@ -254,14 +306,39 @@ class WirelessAdbPairingService : Service() { return builder.build() } + private fun pairingKeypad(keyHeightDp: Int? = null): RemoteViews = RemoteViews(packageName, R.layout.wireless_pairing_keypad).apply { + val ids = intArrayOf(R.id.pair_key_0, R.id.pair_key_1, R.id.pair_key_2, R.id.pair_key_3, R.id.pair_key_4, + R.id.pair_key_5, R.id.pair_key_6, R.id.pair_key_7, R.id.pair_key_8, R.id.pair_key_9, + R.id.pair_key_delete, R.id.pair_key_submit) + ids.forEachIndexed { key, id -> + if (keyHeightDp != null && Build.VERSION.SDK_INT >= 31) { + // Fit both rows inside the system template's heads-up or collapsed height. + setViewLayoutHeight(id, keyHeightDp.toFloat(), TypedValue.COMPLEX_UNIT_DIP) + setViewLayoutMargin(id, RemoteViews.MARGIN_TOP, 1f, TypedValue.COMPLEX_UNIT_DIP) + setViewLayoutMargin(id, RemoteViews.MARGIN_BOTTOM, 1f, TypedValue.COMPLEX_UNIT_DIP) + setTextViewTextSize(id, TypedValue.COMPLEX_UNIT_SP, if (keyHeightDp < 24) 14f else 15f) + } + val intent = Intent(this@WirelessAdbPairingService, WirelessAdbPairingService::class.java) + .setAction(ACTION_KEYPAD) + .setData(Uri.Builder().scheme("droiddeck-pairing").authority(keypadToken).appendPath(key.toString()).build()) + val press = PendingIntent.getService(this@WirelessAdbPairingService, key, intent, PendingIntent.FLAG_IMMUTABLE) + setOnClickPendingIntent(id, press) + } + setTextViewText(R.id.pair_key_code, keypad.display) + setContentDescription(R.id.pair_key_code, getString(R.string.adbpair_keypad_entered, keypad.digits.length)) + setBoolean(R.id.pair_key_delete, "setEnabled", keypad.digits.isNotEmpty()) + setBoolean(R.id.pair_key_submit, "setEnabled", keypad.ready && pairingPort != null) + } + companion object { private const val CHANNEL_ID = "wireless-adb-pairing" private const val PROGRESS_CHANNEL_ID = "wireless-adb-pairing-progress" private const val NOTIFICATION_ID = 3 + private const val KEYPAD_NOTIFICATION_ID = 3403 + private const val KEYPAD_GROUP = "wireless-adb-keypad" private const val PAIRING_TYPE = "_adb-tls-pairing._tcp" - private const val ACTION_CODE = "com.droiddeck.launcher.action.WIRELESS_ADB_CODE" + private const val ACTION_KEYPAD = "com.droiddeck.launcher.action.WIRELESS_ADB_KEYPAD" private const val ACTION_CANCEL = "com.droiddeck.launcher.action.WIRELESS_ADB_CANCEL" - private const val KEY_CODE = "code" private const val EXTRA_ENABLE_LIMIT = "enable_limit" private const val TIMEOUT_MS = 5 * 60_000L @@ -288,7 +365,7 @@ class WirelessAdbPairingService : Service() { fun notificationsEnabled(context: Context): Boolean = context.getSystemService(NotificationManager::class.java)?.areNotificationsEnabled() != false && !channelBlocked(context) - /** The code is typed into a notification on this channel; a channel the user switched off leaves pairing with nothing to type into. */ + /** Pairing needs this notification channel to show the keypad over Android Settings. */ fun channelBlocked(context: Context): Boolean = context.getSystemService(NotificationManager::class.java)?.getNotificationChannel(CHANNEL_ID)?.importance == NotificationManager.IMPORTANCE_NONE diff --git a/app/src/main/java/com/droiddeck/launcher/core/WirelessPairingKeypad.kt b/app/src/main/java/com/droiddeck/launcher/core/WirelessPairingKeypad.kt new file mode 100644 index 0000000000..942911a78d --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/core/WirelessPairingKeypad.kt @@ -0,0 +1,29 @@ +package com.droiddeck.launcher.core + +internal class WirelessPairingKeypad { + var digits = "" + private set + val ready: Boolean get() = digits.length == LENGTH + val display: String get() = digits.padEnd(LENGTH, '–') + + fun press(key: Int): Boolean { + val next = when { + key == DELETE -> digits.dropLast(1) + key in 0..9 && !ready -> digits + key + else -> digits + } + if (next == digits) return false + digits = next + return true + } + + fun clear() { + digits = "" + } + + companion object { + const val LENGTH = 6 + const val DELETE = 10 + const val SUBMIT = 11 + } +} diff --git a/app/src/main/res/color/wireless_pairing_key_text.xml b/app/src/main/res/color/wireless_pairing_key_text.xml new file mode 100644 index 0000000000..62b63fbefb --- /dev/null +++ b/app/src/main/res/color/wireless_pairing_key_text.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/wireless_pairing_key.xml b/app/src/main/res/drawable/wireless_pairing_key.xml new file mode 100644 index 0000000000..51bffe4ff2 --- /dev/null +++ b/app/src/main/res/drawable/wireless_pairing_key.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/wireless_pairing_panel.xml b/app/src/main/res/drawable/wireless_pairing_panel.xml new file mode 100644 index 0000000000..4e88b9b826 --- /dev/null +++ b/app/src/main/res/drawable/wireless_pairing_panel.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/wireless_pairing_keypad.xml b/app/src/main/res/layout/wireless_pairing_keypad.xml new file mode 100644 index 0000000000..159a4e75fd --- /dev/null +++ b/app/src/main/res/layout/wireless_pairing_keypad.xml @@ -0,0 +1,38 @@ + + + + +