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.
Stop re-prompting a TV that keeps saying not allowed
jesse-agent-23221298285f223
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/DeviceLink.kt b/adb/src/main/kotlin/app/tellyscope/adb/DeviceLink.ktindex a0ef5fe..6a16d99 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/DeviceLink.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/DeviceLink.kt@@ -15,9 +15,11 @@ import kotlin.time.Duration.Companion.seconds/*** One device's connection lifecycle: connect, stream stats while online, reconnect on its own* after the TV sleeps or drops off Wi-Fi. NOT_ALLOWED and NEEDS_PAIRING stop the loop until- * [connect] is called again; a device that was online before keeps retrying instead, since a TV- * waking up can stall the handshake exactly like an unanswered prompt. [knownGood] marks a device- * remembered from an earlier launch, which counts as online before.+ * [connect] is called again. A device that was online before gets [notAllowedLimit] tries first,+ * since a TV waking up can stall the handshake exactly like an unanswered prompt; past that it+ * stops, because each try puts a fresh "Allow debugging?" prompt on the TV (revoked access, a+ * reset, or Deny). [knownGood] marks a device remembered from an earlier launch, which counts as+ * online before.*/class DeviceLink(val host: String,@@ -27,6 +29,7 @@ class DeviceLink(private val monitorFor: (AdbShell) -> MonitorSource = { DeviceMonitor(it) },private val open: suspend (String, Int) -> ConnectResult = { h, p -> Connector.connect(h, p) },private val knownGood: Boolean = false,+ private val notAllowedLimit: Int = 3,) {private val _state = MutableStateFlow(DeviceState.FOUND)val state: StateFlow<DeviceState> = _state.asStateFlow()@@ -56,9 +59,12 @@ class DeviceLink(private suspend fun loop() {_state.value = _state.value.on(DeviceEvent.Connect)var wasOnline = knownGood+ var notAllowed = 0while (true) {- when (val r = open(host, port)) {- is ConnectResult.NotAllowed -> if (!wasOnline) {+ val r = open(host, port)+ notAllowed = if (r is ConnectResult.NotAllowed) notAllowed + 1 else 0+ when (r) {+ is ConnectResult.NotAllowed -> if (!wasOnline || notAllowed >= notAllowedLimit) {_state.value = _state.value.on(DeviceEvent.AuthTimedOut)return}diff --git a/adb/src/test/kotlin/app/tellyscope/adb/DeviceLinkTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/DeviceLinkTest.ktindex 3044656..5ff68d8 100644--- a/adb/src/test/kotlin/app/tellyscope/adb/DeviceLinkTest.kt+++ b/adb/src/test/kotlin/app/tellyscope/adb/DeviceLinkTest.kt@@ -24,14 +24,29 @@ class DeviceLinkTest {assertEquals(1, calls)}- @Test fun rememberedDeviceKeepsRetryingThroughNotAllowed() = runTest {- // After an app restart the TV may still be waking up: a stalled handshake isn't a refusal.+ @Test fun rememberedDeviceStopsAfterThreeNotAllowed() = runTest {+ // Each try shows "Allow debugging?" on the TV again, so a revoked key mustn't loop forever.var calls = 0val link = DeviceLink("tv", 5555, backgroundScope, open = { _, _ -> calls++; ConnectResult.NotAllowed }, knownGood = true)link.connect(); runCurrent()- advanceTimeBy(20_001)- assertEquals(DeviceState.WAITING, link.state.value)- assertTrue(calls >= 4)+ advanceTimeBy(60_000)+ assertEquals(DeviceState.NOT_ALLOWED, link.state.value)+ assertEquals(3, calls)+ }++ @Test fun unreachableResetsTheNotAllowedCount() = runTest {+ // A TV waking up: stalls and timeouts interleave, and it keeps retrying until it answers.+ val answers = ArrayDeque(listOf<ConnectResult>(+ ConnectResult.NotAllowed, ConnectResult.NotAllowed, ConnectResult.Unreachable("asleep"),+ ConnectResult.NotAllowed, ConnectResult.NotAllowed,+ ))+ var calls = 0+ val link = DeviceLink("tv", 5555, backgroundScope, knownGood = true,+ open = { _, _ -> calls++; answers.removeFirstOrNull() ?: ConnectResult.Unreachable("off") })+ link.connect(); runCurrent()+ advanceTimeBy(30_001)+ assertEquals(DeviceState.OFFLINE, link.state.value)+ assertTrue(calls > 5)}@Test fun dropsToOfflineThenReconnects() = runTest {@@ -70,7 +85,8 @@ class DeviceLinkTest {assertEquals(1, calls)}- @Test fun stalledHandshakeAfterSleepKeepsRetrying() = runTest {+ @Test fun notAllowedAfterADropStopsAfterThreeTries() = runTest {+ // Online once, then the key is revoked: three tries, then NOT_ALLOWED instead of a prompt every 5 s.var calls = 0val link = DeviceLink("tv", 5555, backgroundScope,@@ -78,9 +94,9 @@ class DeviceLinkTest {open = { _, _ -> if (calls++ == 0) ConnectResult.Online(FakeShell()) else ConnectResult.NotAllowed },)link.connect(); runCurrent()- advanceTimeBy(20_001)- assertEquals(DeviceState.OFFLINE, link.state.value)- assertTrue(calls >= 4)+ advanceTimeBy(60_000)+ assertEquals(DeviceState.NOT_ALLOWED, link.state.value)+ assertEquals(1 + 3, calls)}@Test fun disconnectClosesSessionAndResets() = runTest {diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.ktindex e008b86..5018cc5 100644--- a/app/src/main/java/app/tellyscope/MainActivity.kt+++ b/app/src/main/java/app/tellyscope/MainActivity.kt@@ -161,7 +161,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {confirm = vm::confirm,cancel = vm::cancel,undo = vm::undo,- reconnect = { state.selectedId?.let(vm::select) },+ reconnect = { state.selectedId?.let(vm::reconnect) },forget = vm::forget,),)diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex bc38ca0..a1851d0 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -103,6 +103,11 @@ class AdbDeviceSource(context: Context) : DeviceSource {scope.launch(Dispatchers.IO) { synchronized(store) { store.save(saved.values.sortedBy { it.host }) } }}+ override suspend fun reconnect(deviceId: String) {+ restored.await()+ links[deviceId]?.connect()+ }+override suspend fun forget(deviceId: String) {restored.await()watchers.remove(deviceId)?.cancel()@@ -270,7 +275,10 @@ class AdbDeviceSource(context: Context) : DeviceSource {return Device(id = id,hit = hits.getValue(id),- state = if (id in restoring && state != AdbState.ONLINE) DeviceState.Offline else when (state) {+ // Still waking up after launch reads as offline; a refusal shows as itself.+ state = if (id in restoring && state in setOf(AdbState.FOUND, AdbState.WAITING, AdbState.OFFLINE)) {+ DeviceState.Offline+ } else when (state) {AdbState.WAITING -> DeviceState.WaitingAdbState.ONLINE -> DeviceState.OnlineAdbState.OFFLINE -> DeviceState.Offlinediff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.ktindex e37b3ba..9a13817 100644--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt@@ -23,6 +23,9 @@ interface DeviceSource {/** Previously paired devices, including offline ones. */suspend fun known(): List<Device>+ /** Try a known TV again after it stopped at "not allowed": the TV shows its Allow prompt. */+ suspend fun reconnect(deviceId: String)+/** Stop reconnecting to a TV and drop it from the remembered list. */suspend fun forget(deviceId: String)diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.ktindex 2be2a6c..76695da 100644--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt@@ -94,6 +94,8 @@ class FakeDeviceSource(override suspend fun known(): List<Device> = remembered.values.toList()+ override suspend fun reconnect(deviceId: String) = Unit+override suspend fun forget(deviceId: String) {remembered.remove(deviceId)}diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.ktindex 62d14f3..9ad55f7 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt@@ -152,7 +152,11 @@ fun DeviceScreen(color = MaterialTheme.colorScheme.onSurfaceVariant,)}- if (offline) item { OfflineCard(device, state.now, actions.reconnect) }+ if (device.state == DeviceState.NotAllowed) {+ item { NotAllowedCard(actions.reconnect) }+ } else if (offline) {+ item { OfflineCard(device, state.now, actions.reconnect) }+ }item { StatGrid(ui.snapshot, Modifier.alpha(if (offline) 0.4f else 1f)) }ui.snapshot?.let { snap ->// The :adb source has no per-process list yet; no bars beats an empty card.@@ -263,6 +267,26 @@ private fun StateDot(state: DeviceState) {Box(Modifier.size(10.dp).clip(CircleShape).background(c))}+/** The TV refused (revoked access, a reset, or Deny); retrying stopped so the prompt doesn't nag. */+@Composable+private fun NotAllowedCard(onConnect: () -> Unit) {+ Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerHigh)) {+ Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {+ Text("The TV didn't allow this phone", style = MaterialTheme.typography.titleSmall)+ Text(+ "Its debugging access was turned off, reset, or denied. Tellyscope stopped asking so the TV isn't flooded with prompts.",+ style = MaterialTheme.typography.bodyMedium,+ )+ FilledTonalButton(onClick = onConnect) { Text("Connect again") }+ Text(+ "Then press Allow on the TV, and tick \"Always allow from this computer\".",+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ }+ }+}+@Composableprivate fun OfflineCard(device: Device, now: Long, onReconnect: () -> Unit) {Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerHigh)) {diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.ktindex 6dd5d11..4fc8dd8 100644--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt@@ -224,6 +224,15 @@ class TellyscopeViewModel(if (now.state == DeviceState.Online && before != DeviceState.Online) select(now.id)}+ /** Reconnect button: a TV stopped at "not allowed" asks again; an offline one restarts its stats. */+ fun reconnect(id: String) {+ viewModelScope.launch {+ source.reconnect(id)+ refreshDevices()+ select(id)+ }+ }+fun forget(id: String) {viewModelScope.launch {source.forget(id)diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.ktindex e063a52..7a900d1 100644--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt@@ -147,4 +147,12 @@ class ScreenshotTest {ScanUi(scanning = false, noLan = true, hits = listOf(chromecast), rows = mapOf(chromecast.ip to RowState.Found)),name = "10_scan_off_wifi",)++ @Test fun device_notAllowed() {+ val base = deviceState()+ val off = base.devices.last().copy(state = DeviceState.NotAllowed)+ shot("12_device_not_allowed") {+ DeviceScreen(base.copy(devices = base.devices.dropLast(1) + off, selectedId = off.id, device = DeviceUi()), DeviceActions())+ }+ }}