Debloat your Android TV, install apps, browse and transfer files on it, all from your phone. Just 3 MB, no tracking, no root, no PC.
Switch to plain ps only on a reply without process rows, not a blank one
jesse-agent-362acefa315b893
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.kt b/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.ktindex c1057dd..d0234eb 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.kt@@ -206,12 +206,16 @@ class DeviceMonitor(return procs.map { p -> AppProcess(p.pid, p.name, Parsers.owner(p, packages, known), p.cpuPercent, p.rssKb) } to screen}- /** Set once `ps -o` printed nothing usable; plain `ps` from then on. */+ /** Set once `ps -o` answered without a single process row; plain `ps` from then on. */private var plainPs = falseprivate suspend fun readPs(): List<Parsers.Process>? {if (!plainPs) {- val procs = Parsers.psProcesses(run(Commands.LIGHT) ?: return null)+ val out = run(Commands.LIGHT) ?: return null+ // A blank reply is a hiccup that skips the sample. Plain `ps` lists only the shell's own+ // processes on toybox, so it's only for a `ps` that answers but ignores `-o`.+ if (out.isBlank()) return null+ val procs = Parsers.psProcesses(out)if (procs.isNotEmpty()) return procsplainPs = true}diff --git a/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.ktindex e59866d..bcd448a 100644--- a/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.kt+++ b/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.kt@@ -165,7 +165,7 @@ class DeviceMonitorTest {}/** Answers `ps -A -o` with [ps], plain `ps` with [plain]; `top` and `dumpsys` are logged and answered empty. */- private class PsTv(val ps: String, val plain: String = "") : AdbShell {+ private class PsTv(var ps: String, val plain: String = "") : AdbShell {val ran = mutableListOf<String>()override suspend fun shell(command: String): ShellResult {@@ -207,6 +207,18 @@ class DeviceMonitorTest {assertTrue("ps" in tv.ran)}+ @Test fun aBlankPsReplyDoesNotSwitchToPlainPs() = runTest {+ val gate = StatsGate().apply { profile.value = StatsProfile.OVERVIEW }+ val tv = PsTv("")+ val readings = mutableListOf<Stats>()+ backgroundScope.launch { DeviceMonitor(tv, gate = gate, clock = testScheduler.timeSource).stats().collect { readings += it } }+ runCurrent()+ tv.ps = "PID USER RSS NAME\n2201 u0_a87 319488 com.google.android.youtube.tv\n"+ advanceTimeBy(2_001)+ assertEquals(listOf(2201), readings.last().processes.map { it.pid })+ assertTrue("ps" !in tv.ran, "ran: ${tv.ran}")+ }+@Test fun openingAdvancedReadsTheFullListAtOnce() = runTest {// From Apps, whose round is 10 s: the switch doesn't wait that out.val gate = StatsGate().apply { profile.value = StatsProfile.APPS }