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.
Read again once no change runs, without a quiet period
jesse-agent-232846d787baf7c
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.kt b/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.ktindex abf35f3..73d727c 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.kt@@ -12,7 +12,6 @@ import java.io.IOExceptionimport java.time.YearMonthimport kotlin.time.ComparableTimeMarkimport kotlin.time.Duration-import kotlin.time.Duration.Companion.millisecondsimport kotlin.time.Duration.Companion.secondsimport kotlin.time.TimeMarkimport kotlin.time.TimeSource@@ -82,7 +81,7 @@ data class StatsProfile(val fastEvery: Duration, val processes: ProcessLevel, va* [changed] counts the ended changes to apps or storage, so what they touch is read again right after one.*/class StatsGate {- internal val running = MutableStateFlow(0)+ private val running = MutableStateFlow(0)val profile = MutableStateFlow(StatsProfile.ADVANCED)@@ -132,8 +131,6 @@ class DeviceMonitor(private val pingTimeout: Duration = 10.seconds,/** While a change runs, how often the TV is pinged instead of read. */private val pingEvery: Duration = 10.seconds,- /** How long changes must stay quiet, none running, before what they touched is read again. */- private val settle: Duration = 300.milliseconds,private val gate: StatsGate = StatsGate(),/** Times the tiers and network speed; tests pass the test scheduler's clock. */private val clock: TimeSource.WithComparableMarks = TimeSource.Monotonic,@@ -198,18 +195,12 @@ class DeviceMonitor(private fun TimeMark?.due(every: Duration) = this == null || elapsedNow() >= every/**- * Waits until no change runs and none has ended for [settle], and returns the count then: a- * Debloat, or taps on several rows, are read again once at the end rather than after each app.+ * Waits until no change runs, and returns the count then: a Debloat, one change around one per+ * app, is read again once at the end rather than after each app.*/private suspend fun settled(): Int {- while (true) {- awaitIdle()- val count = gate.changed.value- val stirred = withTimeoutOrNull(settle) {- combine(gate.changed, gate.running) { c, r -> c != count || r > 0 }.first { it }- }- if (stirred == null) return count- }+ awaitIdle()+ return gate.changed.value}/** Pings while a change runs, so one that dies mid-change still ends instead of hanging. */diff --git a/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.ktindex fc9a05b..bfe5ca3 100644--- a/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.kt+++ b/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.kt@@ -257,7 +257,7 @@ class DeviceMonitorTest {advanceTimeBy(1_000)gate.during(reread = true) { tv.ps = "PID USER RSS NAME\n" }- advanceTimeBy(301)+ runCurrent()assertEquals(emptyList(), readings.last().processes)}@@ -267,28 +267,27 @@ class DeviceMonitorTest {backgroundScope.launch { DeviceMonitor(tv, gate = gate, clock = testScheduler.timeSource).stats().collect {} }advanceTimeBy(1_000)val before = tv.ran.size- // Five apps turned off one by one, each its own change inside the batch, each slower than the settle.+ // Five apps turned off one by one, each its own change inside the batch.gate.during(reread = true) { repeat(5) { gate.during(reread = true) { delay(500) } } }- advanceTimeBy(301)+ runCurrent()val after = tv.ran.drop(before)assertEquals(1, after.count { it.startsWith("getprop") }, "ran: $after")assertEquals(1, after.count { it.startsWith("ps") }, "ran: $after")}- @Test fun quickTapsOnSeveralRowsShareOneRead() = runTest {+ @Test fun twoSeparateChangesAreReadTwice() = runTest {val gate = StatsGate().apply { profile.value = StatsProfile.APPS }val tv = PsTv("PID USER RSS NAME\n")backgroundScope.launch { DeviceMonitor(tv, gate = gate, clock = testScheduler.timeSource).stats().collect {} }advanceTimeBy(1_000)val before = tv.ran.size- repeat(5) {+ repeat(2) {gate.during(reread = true) {}advanceTimeBy(50)}- advanceTimeBy(301)val after = tv.ran.drop(before)- assertEquals(1, after.count { it.startsWith("getprop") }, "ran: $after")- assertEquals(1, after.count { it.startsWith("ps") }, "ran: $after")+ assertEquals(2, after.count { it.startsWith("getprop") }, "ran: $after")+ assertEquals(2, after.count { it.startsWith("ps") }, "ran: $after")}@Test fun clearingCachesShowsTheFreedStorageAtOnce() = runTest {@@ -305,7 +304,7 @@ class DeviceMonitorTest {assertEquals(Parsers.Storage(16000, 9800), readings.last().storage)gate.during(reread = true) { used = 7000 }- advanceTimeBy(301)+ runCurrent()assertEquals(Parsers.Storage(16000, 7000), readings.last().storage)}