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.
Connect: a wireless-debugging TV that doesn't come online asks for the code
jesse-agent-36263c353ca9c23
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.ktindex 45b8e74..d7bdd50 100644--- a/app/src/main/java/app/tellyscope/ui/Copy.kt+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt@@ -179,6 +179,7 @@ object Copy {const val WRONG_CODE = "That code didn't work. Check the 6 digits on the TV and try again."const val UNREACHABLE = "The TV didn't answer. Check it's on and on the same Wi-Fi as this phone, then try again."+ const val PAIR_INSTEAD = "The TV didn't let this phone in yet. Pair it once with the code from the TV."data class Health(val ok: Boolean, val text: String)diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.ktindex 4f3854b..1a026b0 100644--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt@@ -29,6 +29,7 @@ import app.tellyscope.data.PhoneStorageimport app.tellyscope.data.PickedAppimport app.tellyscope.data.ScanEventimport app.tellyscope.data.ScanHit+import app.tellyscope.data.ScanKindimport app.tellyscope.data.ScanProgressimport app.tellyscope.data.Snapshotimport app.tellyscope.data.Suggestions@@ -246,11 +247,16 @@ class TellyscopeViewModel(// the rest answer NeedsPairing and get the code field.setRow(hit.ip, RowState.Waiting(clock()))viewModelScope.launch {- when (val r = withTimeoutOrNull(allowTimeoutMs) { source.connect(hit) }) {- is ConnectResult.Online -> online(r.device)- ConnectResult.NeedsPairing -> setRow(hit.ip, RowState.Code())- null, ConnectResult.NotAllowed, is ConnectResult.Unreachable, is ConnectResult.WrongCode ->- setRow(hit.ip, RowState.NotAllowed)+ val r = withTimeoutOrNull(allowTimeoutMs) { source.connect(hit) }+ when {+ r is ConnectResult.Online -> online(r.device)+ r == ConnectResult.NeedsPairing -> setRow(hit.ip, RowState.Code())+ // A wireless-debugging TV never shows the Allow box: whatever went wrong, the way in is the code.+ hit.kind == ScanKind.Wireless -> setRow(hit.ip, RowState.Code(+ error = if (r is ConnectResult.Unreachable) Copy.UNREACHABLE else Copy.PAIR_INSTEAD,+ detail = (r as? ConnectResult.Unreachable)?.message ?: (r as? ConnectResult.WrongCode)?.message,+ ))+ else -> setRow(hit.ip, RowState.NotAllowed)}}}@@ -267,7 +273,7 @@ class TellyscopeViewModel(is ConnectResult.Online -> online(r.device)is ConnectResult.WrongCode -> setRow(hit.ip, row.copy(busy = false, error = Copy.WRONG_CODE, detail = r.message))is ConnectResult.Unreachable -> setRow(hit.ip, row.copy(busy = false, error = Copy.UNREACHABLE, detail = r.message))- ConnectResult.NotAllowed -> setRow(hit.ip, RowState.NotAllowed)+ ConnectResult.NotAllowed -> setRow(hit.ip, row.copy(busy = false, error = Copy.PAIR_INSTEAD))ConnectResult.NeedsPairing -> setRow(hit.ip, row.copy(busy = false, error = "The TV still wants a code. Check the number on screen and try again."))}}diff --git a/app/src/test/java/app/tellyscope/WirelessConnectTest.kt b/app/src/test/java/app/tellyscope/WirelessConnectTest.ktnew file mode 100644index 0000000..f0ed22c--- /dev/null+++ b/app/src/test/java/app/tellyscope/WirelessConnectTest.kt@@ -0,0 +1,98 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope++import androidx.lifecycle.viewModelScope+import app.tellyscope.data.ConnectResult+import app.tellyscope.data.Device+import app.tellyscope.data.DeviceSource+import app.tellyscope.data.FakeDeviceSource+import app.tellyscope.data.ScanHit+import app.tellyscope.data.ScanKind+import app.tellyscope.ui.Copy+import app.tellyscope.ui.RowState+import app.tellyscope.ui.TellyscopeViewModel+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.ExperimentalCoroutinesApi+import kotlinx.coroutines.awaitCancellation+import kotlinx.coroutines.cancel+import kotlinx.coroutines.test.StandardTestDispatcher+import kotlinx.coroutines.test.TestScope+import kotlinx.coroutines.test.advanceTimeBy+import kotlinx.coroutines.test.resetMain+import kotlinx.coroutines.test.runCurrent+import kotlinx.coroutines.test.setMain+import org.junit.After+import org.junit.Assert.assertEquals+import org.junit.Before+import org.junit.Test++/** Every connect answers [result]; null hangs until the caller's timeout. */+private class Answers : DeviceSource by FakeDeviceSource(FakeDeviceSource.Scenario.Empty, clock = { 0L }) {+ var result: ConnectResult? = null++ override suspend fun known() = emptyList<Device>()++ override suspend fun connect(hit: ScanHit): ConnectResult = result ?: awaitCancellation()++ override suspend fun pair(hit: ScanHit, code: String): ConnectResult = result ?: awaitCancellation()+}++@OptIn(ExperimentalCoroutinesApi::class)+class WirelessConnectTest {+ private val dispatcher = StandardTestDispatcher()+ private val test = TestScope(dispatcher)+ private val source = Answers()+ private lateinit var vm: TellyscopeViewModel++ private val wireless = ScanHit("192.0.2.20", 46237, ScanKind.Wireless, "adb-1268-iFvH8u", "Sony")+ private val classic = ScanHit("192.0.2.21", 5555, ScanKind.Classic, null, null)++ @Before fun setUp() {+ Dispatchers.setMain(dispatcher)+ vm = TellyscopeViewModel(source, allowTimeoutMs = 60_000, clock = { 0L })+ }++ @After fun tearDown() {+ vm.viewModelScope.cancel()+ Dispatchers.resetMain()+ }++ private fun connect(hit: ScanHit): RowState? = with(test) {+ vm.connect(hit)+ runCurrent()+ advanceTimeBy(60_001)+ runCurrent()+ vm.state.value.scan.rows[hit.ip]+ }++ @Test fun wirelessTimeoutAsksForTheCode() {+ source.result = null+ assertEquals(RowState.Code(error = Copy.PAIR_INSTEAD), connect(wireless))+ }++ @Test fun wirelessUnreachableAsksForTheCode() {+ source.result = ConnectResult.Unreachable("connection refused")+ assertEquals(RowState.Code(error = Copy.UNREACHABLE, detail = "connection refused"), connect(wireless))+ }++ @Test fun wirelessNotAllowedAsksForTheCode() {+ source.result = ConnectResult.NotAllowed+ assertEquals(RowState.Code(error = Copy.PAIR_INSTEAD), connect(wireless))+ }++ @Test fun wirelessNotAllowedAfterPairingKeepsTheCode() = with(test) {+ source.result = ConnectResult.NeedsPairing+ connect(wireless)+ vm.codeChanged(wireless, "123456")+ source.result = ConnectResult.NotAllowed+ vm.pair(wireless)+ runCurrent()+ assertEquals(RowState.Code("123456", error = Copy.PAIR_INSTEAD), vm.state.value.scan.rows[wireless.ip])+ }++ @Test fun classicTimeoutIsStillTheAllowBox() {+ source.result = null+ assertEquals(RowState.NotAllowed, connect(classic))+ }+}