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.
Install's version check redials a link dropped behind the picker
jesse-agent-2323edfdbf93a93
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b7fa4b2..34192f3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,6 +17,7 @@ until this file has a section for its version.- **Fixed:** Apps without a name no longer show a Java class name. [#303](../../pull/303)- **Fixed:** Philips Help stays on; turning it off broke the HDMI input picker. [#299](../../pull/299)- **Fixed:** On Android 7 and older, Clear caches says it needs Android 8 instead of erroring. [#304](../../pull/304)+- **Fixed:** Picking an app to install right after the TV's link dropped no longer fails with "Lost the TV partway through"; a file the phone can't read, or a TV that doesn't answer, now says which. [#305](../../pull/305)## 0.14.0 — 2026-10-30diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex 03a77a9..58115e5 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -81,7 +81,10 @@ import app.tellyscope.adb.ScanHit as AdbHit* [DeviceSource] on real TVs through `:adb`. Device id is the TV's IP. Wi-Fi name, signal, MAC and* link speed are empty for now. App names and icons come from the label helper through [AppNames].*/-class AdbDeviceSource(context: Context) : DeviceSource {+class AdbDeviceSource(+ context: Context,+ private val connector: suspend (String, Int) -> AdbConnectResult = { h, p -> Connector.connect(h, p) },+) : DeviceSource {private val appContext = context.applicationContext/** Our text in the app's language now, for what's saved: History labels, names stored with data. */private fun UiText.text(): String = this.resolve(appContext.resources)@@ -150,7 +153,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {private fun link(host: String, port: Int, first: AdbConnectResult?, knownGood: Boolean, loggedOutAt: Long? = null) {var pending = firstval link = DeviceLink(host, port, scope, knownGood = knownGood, open = { h, p ->- pending?.also { pending = null } ?: Connector.connect(h, p)+ pending?.also { pending = null } ?: connector(h, p)})link.gate.profile.value = statsFor?.takeIf { it.first == host }?.second ?: StatsProfile.OTHERlink.gate.paused.value = paused@@ -314,7 +317,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {emit(ScanEvent.Done)}- override suspend fun connect(hit: ScanHit): ConnectResult = when (val r = Connector.connect(hit.ip, hit.port)) {+ override suspend fun connect(hit: ScanHit): ConnectResult = when (val r = connector(hit.ip, hit.port)) {is AdbConnectResult.Online -> {hits[hit.ip] = hitrestoring -= hit.ip@@ -1109,7 +1112,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {private suspend fun disabledPackages(deviceId: String) =Parsers.packages(session(deviceId).shell("pm list packages -d").output).map { it.name }.toSet()- override suspend fun installed(deviceId: String, packageName: String) = Sideload(session(deviceId)).installed(packageName)+ override suspend fun installed(deviceId: String, packageName: String) = Sideload(liveSession(deviceId)).installed(packageName)override suspend fun install(deviceId: String,@@ -1139,7 +1142,8 @@ class AdbDeviceSource(context: Context) : DeviceSource {* The session for a file the user just picked. While the system picker is up the app is in the* background, where Android cuts its network after a few seconds and no stats read notices: back* in the app, the old session is dead (#290, #296). A quick shell call tells; a dead link starts- * over and the transfer waits for the new session.+ * over and the transfer waits for the new session. The install's version check is the first call+ * after the picker, so it goes through here too.*/private suspend fun liveSession(deviceId: String): AdbSession {val link = links[deviceId] ?: return session(deviceId)diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.ktindex 908e958..48970ee 100644--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt@@ -1278,15 +1278,22 @@ class TellyscopeViewModel(if (uris.isEmpty()) returnsetSideload(SideloadUi())sideloadJob = viewModelScope.launch {+ // The phone's file and the TV fail apart: nothing has been sent yet, so neither is "lost partway".+ val app = try {+ storage.readApp(uris)+ } catch (e: CancellationException) {+ throw e+ } catch (_: NotAnApp) {+ return@launch updateDevice(id) { it.copy(sideload = SideloadUi(SideloadUi.Step.Failed, error = Copy.NOT_AN_APP)) }+ } catch (_: Exception) {+ return@launch updateDevice(id) { it.copy(sideload = SideloadUi(SideloadUi.Step.Failed, error = Copy.CANT_READ)) }+ }val ui = try {- val app = storage.readApp(uris)SideloadUi(SideloadUi.Step.Ready, app, source.installed(id, app.info.packageName))} catch (e: CancellationException) {throw e- } catch (_: NotAnApp) {- SideloadUi(SideloadUi.Step.Failed, error = Copy.NOT_AN_APP)} catch (_: Exception) {- SideloadUi(SideloadUi.Step.Failed, error = Copy.SIDELOAD_LOST)+ SideloadUi(SideloadUi.Step.Failed, error = Copy.UNREACHABLE)}updateDevice(id) { it.copy(sideload = ui) }}diff --git a/app/src/test/java/app/tellyscope/PickerDropTest.kt b/app/src/test/java/app/tellyscope/PickerDropTest.ktnew file mode 100644index 0000000..0d8c677--- /dev/null+++ b/app/src/test/java/app/tellyscope/PickerDropTest.kt@@ -0,0 +1,75 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope++import app.tellyscope.adb.AdbPipe+import app.tellyscope.adb.AdbSession+import app.tellyscope.adb.InstalledVersion+import app.tellyscope.adb.RemoteEntry+import app.tellyscope.adb.ShellResult+import app.tellyscope.data.AdbDeviceSource+import app.tellyscope.data.ConnectResult+import app.tellyscope.data.ScanHit+import app.tellyscope.data.ScanKind+import java.io.File+import java.io.IOException+import kotlinx.coroutines.runBlocking+import kotlinx.coroutines.withTimeout+import okio.Sink+import okio.Source+import org.junit.Assert.assertEquals+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.RuntimeEnvironment+import org.robolectric.annotation.Config+import app.tellyscope.adb.ConnectResult as AdbConnectResult++/** One adb session to the TV; every call throws once [dead], like a socket Android cut in the background. */+private class Link(private val version: Int) : AdbSession {+ @Volatile var dead = false++ override suspend fun shell(command: String): ShellResult = when {+ dead -> throw IOException("link gone")+ command.startsWith("dumpsys package") ->+ ShellResult("Packages:\n Package [com.example.app] (1a2b3c):\n versionCode=$version minSdk=21 targetSdk=34\n versionName=$version.0\n", 0)+ else -> ShellResult("", 0)+ }++ override suspend fun push(bytes: ByteArray, remotePath: String) = Unit+ override suspend fun reboot() = Unit+ override suspend fun exec(command: String): AdbPipe = throw IOException("no exec")+ override fun install(source: Source, size: Long, vararg options: String) = Unit+ override fun installMultiple(apks: List<File>, vararg options: String) = Unit+ override fun push(source: Source, remotePath: String, mode: Int, lastModifiedMs: Long) = Unit+ override fun pull(sink: Sink, remotePath: String) = Unit+ override fun list(remoteDir: String) = emptyList<RemoteEntry>()+ override fun close() = Unit+}++/** The version check is the first call after the file picker, so it gets a fresh link when the old one died behind it (#290). */+@RunWith(RobolectricTestRunner::class)+@Config(sdk = [35])+class PickerDropTest {+ @Test fun theVersionCheckAfterThePickerRedialsADeadLink() = runBlocking {+ val before = Link(version = 1)+ val after = Link(version = 2)+ var dials = 0+ val source = AdbDeviceSource(RuntimeEnvironment.getApplication(), connector = { _, _ ->+ AdbConnectResult.Online(if (++dials == 1) before else after)+ })+ val hit = ScanHit("tv", 5555, ScanKind.Classic, "tv", null)+ assertTrue(source.connect(hit) is ConnectResult.Online)++ // The picker is up: the app is in the background, and Android cuts the socket.+ source.pause(true)+ before.dead = true+ source.pause(false)++ val installed = withTimeout(30_000) { source.installed("tv", "com.example.app") }+ assertEquals(InstalledVersion(2, "2.0"), installed)+ assertTrue(dials >= 2)+ source.forget("tv")+ }+}diff --git a/app/src/test/java/app/tellyscope/SideloadPickTest.kt b/app/src/test/java/app/tellyscope/SideloadPickTest.ktnew file mode 100644index 0000000..43056ca--- /dev/null+++ b/app/src/test/java/app/tellyscope/SideloadPickTest.kt@@ -0,0 +1,111 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope++import android.net.Uri+import androidx.lifecycle.viewModelScope+import app.tellyscope.adb.ApkInfo+import app.tellyscope.adb.InstalledVersion+import app.tellyscope.data.Device+import app.tellyscope.data.DeviceSource+import app.tellyscope.data.DeviceState+import app.tellyscope.data.FakeDeviceSource+import app.tellyscope.data.PhoneStorage+import app.tellyscope.data.PickedApp+import app.tellyscope.data.ScanHit+import app.tellyscope.data.ScanKind+import app.tellyscope.data.Snapshot+import app.tellyscope.ui.Copy+import app.tellyscope.ui.SideloadUi+import app.tellyscope.ui.TellyscopeViewModel+import java.io.File+import java.io.IOException+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.ExperimentalCoroutinesApi+import kotlinx.coroutines.cancel+import kotlinx.coroutines.flow.emptyFlow+import kotlinx.coroutines.test.StandardTestDispatcher+import kotlinx.coroutines.test.TestScope+import kotlinx.coroutines.test.resetMain+import kotlinx.coroutines.test.runCurrent+import kotlinx.coroutines.test.setMain+import okio.Buffer+import org.junit.After+import org.junit.Assert.assertEquals+import org.junit.Before+import org.junit.Test+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config++/** One online TV whose version check fails when [unreachable]; [asked] counts the checks. */+private class VersionCheckTv : DeviceSource by FakeDeviceSource(FakeDeviceSource.Scenario.Empty, clock = { 0L }) {+ var unreachable = false+ var asked = 0++ override suspend fun known() = listOf(Device("tv", ScanHit("tv", 5555, ScanKind.Classic, "tv", null), DeviceState.Online, null, null, null, 0L))++ override fun live(deviceId: String) = emptyFlow<Snapshot>()++ override suspend fun installed(deviceId: String, packageName: String): InstalledVersion? {+ asked+++ if (unreachable) throw IOException("link gone")+ return null+ }+}++/** A phone whose picked file reads when [readable], and fails like a revoked or vanished file otherwise. */+private class Picked(private val readable: Boolean) : PhoneStorage {+ override suspend fun readApp(uris: List<Uri>) =+ if (readable) PickedApp(listOf(File("app.apk")), ApkInfo("com.example.app", 1, "1.0"), "Example") else throw IOException("permission revoked")+ override fun open(uri: Uri) = error("unused")+ override fun create(uri: Uri) = Buffer()+ override fun delete(uri: Uri) = Unit+ override fun clearApp() = Unit+}++/** A failed pick names what failed: the phone's file or the TV, never "lost partway" before anything was sent. */+@OptIn(ExperimentalCoroutinesApi::class)+@RunWith(RobolectricTestRunner::class)+@Config(sdk = [35])+class SideloadPickTest {+ private val dispatcher = StandardTestDispatcher()+ private val test = TestScope(dispatcher)+ private val tv = VersionCheckTv()+ private lateinit var vm: TellyscopeViewModel++ @Before fun setUp() = Dispatchers.setMain(dispatcher)++ @After fun tearDown() {+ vm.viewModelScope.cancel()+ Dispatchers.resetMain()+ }++ private fun TestScope.pick(phone: PhoneStorage): SideloadUi? {+ vm = TellyscopeViewModel(tv, phone, clock = { 0L })+ runCurrent()+ vm.pickedApp(listOf(Uri.parse("content://x/app.apk")))+ runCurrent()+ return vm.state.value.device.sideload+ }++ @Test fun aFileThePhoneCantReadSaysSoAndNeverAsksTheTv() = with(test) {+ val ui = pick(Picked(readable = false))+ assertEquals(SideloadUi.Step.Failed, ui?.step)+ assertEquals(Copy.CANT_READ, ui?.error)+ assertEquals(0, tv.asked)+ }++ @Test fun aTvThatDoesntAnswerTheVersionCheckIsUnreachableNotLost() = with(test) {+ tv.unreachable = true+ val ui = pick(Picked(readable = true))+ assertEquals(SideloadUi.Step.Failed, ui?.step)+ assertEquals(Copy.UNREACHABLE, ui?.error)+ assertEquals(1, tv.asked)+ }++ @Test fun aReadableFileOnAnAnsweringTvIsReady() = with(test) {+ val ui = pick(Picked(readable = true))+ assertEquals(SideloadUi.Step.Ready, ui?.step)+ }+}