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.
Review fixes: Waiting never hides a live session, New only skips in-app allows
jesse-agent-2327c4c062a4f72
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex a397125..7a66fd2 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -103,8 +103,6 @@ class AdbDeviceSource(context: Context) : DeviceSource {private val mine = MineBook(File(appContext.filesDir, "mine.tsv"))/** The keys each TV was seen to allow, so one allowed behind Tellyscope's back shows as new. */private val knownKeys = MineBook(File(appContext.filesDir, "known-keys.tsv"))- /** Per TV, fingerprints seen on its prompt in this launch: allowed while the user watched, so not new. */- private val watchedKeys = ConcurrentHashMap<String, Set<String>>()private val networkNames = NetworkNames()/** Last label seen per package, so history entries read like the app list. */private val labels = ConcurrentHashMap<String, String>()@@ -970,10 +968,18 @@ class AdbDeviceSource(context: Context) : DeviceSource {override suspend fun screenshot(deviceId: String, sink: Sink) = Tweaks(session(deviceId)).screenshot(sink)- override suspend fun connectionRequest(deviceId: String) = ConnectionPrompt(session(deviceId)).pending()?.also { watch(deviceId, it.fingerprint) }+ override suspend fun connectionRequest(deviceId: String) = ConnectionPrompt(session(deviceId)).pending()- override suspend fun answerRequest(deviceId: String, request: ConnectionRequest, allow: Boolean, always: Boolean) =- ConnectionPrompt(session(deviceId)).answer(request, allow, always)+ /**+ * Allow pressed from the app makes that key known, so it isn't flagged new. Only on a TV with a+ * known list: before the first read every key counts as known anyway.+ */+ override suspend fun answerRequest(deviceId: String, request: ConnectionRequest, allow: Boolean, always: Boolean): Boolean {+ val answered = ConnectionPrompt(session(deviceId)).answer(request, allow, always)+ val tv = key(deviceId)+ if (answered && allow && request.fingerprint.isNotEmpty() && knownKeys.has(tv)) knownKeys.add(tv, request.fingerprint)+ return answered+ }override suspend fun closeAlert(deviceId: String) = ConnectionPrompt(session(deviceId)).closeAlert()@@ -986,9 +992,12 @@ class AdbDeviceSource(context: Context) : DeviceSource {val tv = key(deviceId)val access = TvAccess.of(a.clients(port), a.keys(), phoneAddresses(), deviceId, mine[tv], phoneFingerprint(),- pending = pending, known = knownKeys[tv].takeIf { knownKeys.has(tv) }, watched = watchedKeys[deviceId].orEmpty(),+ pending = pending, known = knownKeys[tv].takeIf { knownKeys.has(tv) },)- access.allowed?.let { keys -> knownKeys.set(tv, knownKeys[tv] + keys.filterNot { it.new }.map { it.fingerprint }) }+ access.allowed?.let { keys ->+ val known = knownKeys[tv] + keys.filterNot { it.new }.map { it.fingerprint }+ if (!knownKeys.has(tv) || known != knownKeys[tv]) knownKeys.set(tv, known)+ }// Other computers only: this phone and apps on the TV itself need no name.val lookup = access.connected.orEmpty().filter { it.who == AccessClient.Who.Other || it.who == AccessClient.Who.Mine }return access.named(networkNames.of(lookup.map { it.address }))@@ -999,11 +1008,6 @@ class AdbDeviceSource(context: Context) : DeviceSource {mine.add(key(deviceId), address)}- /** A prompt the app showed: the key on it, once allowed, isn't new. */- private fun watch(deviceId: String, fingerprint: String) {- if (fingerprint.isNotEmpty()) watchedKeys.merge(deviceId, setOf(fingerprint), Set<String>::plus)- }-override suspend fun markKeyMine(deviceId: String, fingerprint: String) {restored.await()knownKeys.add(key(deviceId), fingerprint)diff --git a/app/src/main/java/app/tellyscope/data/TvAccess.kt b/app/src/main/java/app/tellyscope/data/TvAccess.ktindex 10ef508..81016da 100644--- a/app/src/main/java/app/tellyscope/data/TvAccess.kt+++ b/app/src/main/java/app/tellyscope/data/TvAccess.kt@@ -38,11 +38,11 @@ data class TvAccess(** [pending]: the fingerprint on the TV's "Allow debugging?" prompt now, empty when the prompt* can't be read, null when there is none. A prompt for a key that isn't allowed means a- * connection is waiting on it; with exactly one other connection, that one is+ * connection is waiting on it; with exactly one other connection, from an address with no other, that one is* [AccessClient.Who.Waiting]. With more, nothing says which, so none is.** [known]: the keys this TV was seen to allow before, null on the first read, when every key- * counts as known. A key that isn't, and wasn't seen on a prompt ([watched]), is [AccessKey.new].+ * counts as known. A key that isn't is [AccessKey.new].*/fun of(clients: List<AdbClient>?,@@ -53,7 +53,6 @@ data class TvAccess(phoneFingerprint: String?,pending: String? = null,known: Set<String>? = null,- watched: Set<String> = emptySet(),): TvAccess {val tvLoopback = tvHost == "localhost" || AdbClient(tvHost, 0).loopbackval connected = clients?.groupBy { it.address }?.map { (address, rows) ->@@ -67,12 +66,14 @@ data class TvAccess(}AccessClient(address, rows.size, who)}?.let { list ->- val waiting = pending != null && keys?.none { it.fingerprint == pending } != false && list.count { it.who == AccessClient.Who.Other } == 1+ // A client waiting on the prompt holds one connection; a second from that address is a live session.+ val waiting = pending != null && keys?.none { it.fingerprint == pending } != false &&+ list.singleOrNull { it.who == AccessClient.Who.Other }?.connections == 1if (waiting) list.map { if (it.who == AccessClient.Who.Other) it.copy(who = AccessClient.Who.Waiting) else it } else list}?.sortedBy { it.who.ordinal }val allowed = keys?.map { k ->val phone = k.fingerprint == phoneFingerprint- AccessKey(k.fingerprint, k.name, k.lastSeen, phone, new = !phone && known != null && k.fingerprint !in known && k.fingerprint !in watched)+ AccessKey(k.fingerprint, k.name, k.lastSeen, phone, new = !phone && known != null && k.fingerprint !in known)}?.sortedWith(compareByDescending<AccessKey> { it.phone }.thenByDescending { it.new })return TvAccess(connected, allowed)}diff --git a/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt b/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.ktindex 9bf9ae3..c3eed9b 100644--- a/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt+++ b/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt@@ -513,7 +513,7 @@ private fun Numbered(n: Int, content: @Composable () -> Unit) {}}-private enum class Mark { Todo, Active, Done, Failed }+private enum class StepMark { Todo, Active, Done, Failed }/** Download (or the picked file), the check, the install: each to do, under way, done, or failed. */@OptIn(ExperimentalMaterial3ExpressiveApi::class)@@ -526,34 +526,34 @@ private fun FireSteps(f: FireInstall, device: Device) {Surface(shape = MaterialTheme.shapes.large, color = c.surfaceContainer, modifier = Modifier.fillMaxWidth()) {Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {when {- f.picked -> StepLine(1, Mark.Done, Copy.STEP_PICKED, f.size?.let(Copy::bytes))+ f.picked -> StepLine(1, StepMark.Done, Copy.STEP_PICKED, f.size?.let(Copy::bytes))f.step == FireInstall.Step.Downloading -> {val p = f.progressval total = p?.total?.takeIf { it > 0 } ?: release?.size ?: 0Lval fraction = p?.fraction- StepLine(1, Mark.Active, Copy.STEP_DOWNLOAD, Copy.downloading(((fraction ?: 0f) * 100).toInt(), p?.done ?: 0L, total)) {+ StepLine(1, StepMark.Active, Copy.STEP_DOWNLOAD, Copy.downloading(((fraction ?: 0f) * 100).toInt(), p?.done ?: 0L, total)) {if (fraction != null) LinearWavyProgressIndicator(progress = { fraction }, Modifier.fillMaxWidth())else LinearWavyProgressIndicator(Modifier.fillMaxWidth())}}- else -> StepLine(1, Mark.Done, Copy.STEP_DOWNLOADED, release?.let { Copy.release(it.version, it.size) })+ else -> StepLine(1, StepMark.Done, Copy.STEP_DOWNLOADED, release?.let { Copy.release(it.version, it.size) })}when {- failed -> StepLine(2, Mark.Failed, Copy.STEP_FAILED, Copy.STEP_FAILED_TEXT)- checked -> StepLine(2, Mark.Done, Copy.STEP_CHECKED, Copy.STEP_CHECKED_TEXT)- f.step == FireInstall.Step.Reading -> StepLine(2, Mark.Active, Copy.STEP_CHECKING)- else -> StepLine(2, Mark.Todo, Copy.STEP_CHECK)+ failed -> StepLine(2, StepMark.Failed, Copy.STEP_FAILED, Copy.STEP_FAILED_TEXT)+ checked -> StepLine(2, StepMark.Done, Copy.STEP_CHECKED, Copy.STEP_CHECKED_TEXT)+ f.step == FireInstall.Step.Reading -> StepLine(2, StepMark.Active, Copy.STEP_CHECKING)+ else -> StepLine(2, StepMark.Todo, Copy.STEP_CHECK)}if (!failed) {if (checked) {- StepLine(3, Mark.Active, Copy.installingOn(name(device))) {+ StepLine(3, StepMark.Active, Copy.installingOn(name(device))) {// Past the last byte the TV is still unpacking: no bar stuck at 100%.val p = f.progress?.fractionif (p != null && p < 1f) LinearWavyProgressIndicator(progress = { p }, Modifier.fillMaxWidth())else LinearWavyProgressIndicator(Modifier.fillMaxWidth())}} else {- StepLine(3, Mark.Todo, Copy.installOn(name(device)))+ StepLine(3, StepMark.Todo, Copy.installOn(name(device)))}}}@@ -562,25 +562,25 @@ private fun FireSteps(f: FireInstall, device: Device) {@OptIn(ExperimentalMaterial3ExpressiveApi::class)@Composable-private fun StepLine(n: Int, mark: Mark, title: String, text: String? = null, below: @Composable () -> Unit = {}) {+private fun StepLine(n: Int, mark: StepMark, title: String, text: String? = null, below: @Composable () -> Unit = {}) {val c = MaterialTheme.colorSchemeRow(horizontalArrangement = Arrangement.spacedBy(12.dp)) {Box(Modifier.size(24.dp), contentAlignment = Alignment.Center) {when (mark) {- Mark.Todo -> Box(Modifier.size(22.dp).border(1.5.dp, c.outline, CircleShape), contentAlignment = Alignment.Center) {+ StepMark.Todo -> Box(Modifier.size(22.dp).border(1.5.dp, c.outline, CircleShape), contentAlignment = Alignment.Center) {Text("$n", style = MaterialTheme.typography.labelMedium, color = c.onSurfaceVariant)}- Mark.Active -> LoadingIndicator(Modifier.size(24.dp))- Mark.Done -> Box(Modifier.size(24.dp).background(c.primary, CircleShape), contentAlignment = Alignment.Center) {+ StepMark.Active -> LoadingIndicator(Modifier.size(24.dp))+ StepMark.Done -> Box(Modifier.size(24.dp).background(c.primary, CircleShape), contentAlignment = Alignment.Center) {Icon(Icons.Default.Check, null, Modifier.size(16.dp), tint = c.onPrimary)}- Mark.Failed -> Box(Modifier.size(24.dp).background(c.errorContainer, CircleShape), contentAlignment = Alignment.Center) {+ StepMark.Failed -> Box(Modifier.size(24.dp).background(c.errorContainer, CircleShape), contentAlignment = Alignment.Center) {Icon(Icons.Default.Close, null, Modifier.size(16.dp), tint = c.onErrorContainer)}}}Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {- Text(title, style = MaterialTheme.typography.bodyLarge, color = if (mark == Mark.Todo) c.onSurfaceVariant else c.onSurface)+ Text(title, style = MaterialTheme.typography.bodyLarge, color = if (mark == StepMark.Todo) c.onSurfaceVariant else c.onSurface)text?.let { Text(it, style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant) }below()}diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.ktindex 580f2c2..2cedd3f 100644--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt@@ -944,7 +944,9 @@ class TellyscopeViewModel(fun pickedProjectivy(uri: Uri) {val id = _state.value.selectedId ?: returnval download = launcherDownload ?: return- if (_state.value.device.launcher?.fire == null) return+ // The picker answers on its own timing: only from a step that offers it, never over a running install.+ val step = _state.value.device.launcher?.fire?.step+ if (step != FireInstall.Step.NoDownload && step != FireInstall.Step.NotProjectivy && step != FireInstall.Step.Refused) returnlauncherJob?.cancel()setFire(id) { it.copy(step = FireInstall.Step.Reading, picked = true, progress = null, size = null) }launcherJob = viewModelScope.launch {diff --git a/app/src/test/java/app/tellyscope/FireOsTest.kt b/app/src/test/java/app/tellyscope/FireOsTest.ktindex 2d3471c..6cef90f 100644--- a/app/src/test/java/app/tellyscope/FireOsTest.kt+++ b/app/src/test/java/app/tellyscope/FireOsTest.kt@@ -58,6 +58,7 @@ import org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Configimport java.io.File+import java.io.IOException// Fixtures from Amazon's developer docs, not from a TV: Fire TV devices report Build.MANUFACTURER "Amazon" and an// AFT model (AFTKRT is the Fire TV Stick 4K Max, 2nd gen); Fire OS's home screen is com.amazon.tv.launcher, also on@@ -109,7 +110,8 @@ private class FireTv(val tv: Device = amazon, val own: List<AppInfo> = listOf(fiprivate class FakeDownload(var signedByDeveloper: Boolean = true) : LauncherDownload {var fetched = 0- override suspend fun latest() = parseRelease(release())!!+ var offline = false+ override suspend fun latest() = if (offline) throw IOException("offline") else parseRelease(release())!!override suspend fun fetch(release: LauncherRelease, onProgress: (Progress) -> Unit): PickedApp {fetched++if (!signedByDeveloper) throw NotProjectivy()@@ -275,7 +277,7 @@ class FireOsTest {}@Test fun aPickedFileIsCheckedThenInstalled() = with(test) {- val v = opened()+ val v = couldntDownload()v.pickedProjectivy(Uri.parse("content://downloads/1"))runCurrent()assertEquals(listOf(PROJECTIVY), source.installs.map { it.packageName })@@ -284,7 +286,7 @@ class FireOsTest {@Test fun aPickedFileThatIsntProjectivyInstallsNothing() = with(test) {download.signedByDeveloper = false- val v = opened()+ val v = couldntDownload()v.pickedProjectivy(Uri.parse("content://downloads/1"))runCurrent()assertTrue(source.installs.isEmpty())@@ -292,4 +294,21 @@ class FireOsTest {assertEquals(FireInstall.Step.NotProjectivy, fire?.step)assertEquals(true, fire?.picked)}++ @Test fun aPickOutsideAFailedStepIsIgnored() = with(test) {+ val v = opened()+ v.pickedProjectivy(Uri.parse("content://downloads/1"))+ runCurrent()+ assertTrue(source.installs.isEmpty())+ assertNull(v.state.value.device.launcher?.fire?.step)+ }++ private fun TestScope.couldntDownload(): TellyscopeViewModel {+ download.offline = true+ val v = opened()+ v.checkProjectivy()+ runCurrent()+ assertEquals(FireInstall.Step.NoDownload, v.state.value.device.launcher?.fire?.step)+ return v+ }}diff --git a/app/src/test/java/app/tellyscope/TvAccessTest.kt b/app/src/test/java/app/tellyscope/TvAccessTest.ktindex 5884d13..3d7de8b 100644--- a/app/src/test/java/app/tellyscope/TvAccessTest.kt+++ b/app/src/test/java/app/tellyscope/TvAccessTest.kt@@ -106,13 +106,20 @@ class TvAccessTest {assertEquals(2, two.others.size)}+ @Test fun aSecondConnectionFromTheWaitingAddressKeepsTheWarning() {+ // An allowed computer opens one more connection with a throwaway key to raise a prompt: its live session stays Other.+ val a = TvAccess.of(listOf(AdbClient(phone, 1), AdbClient(other, 2), AdbClient(other, 3)), listOf(phoneKey), setOf(phone), "192.0.2.20", emptySet(), "AA", pending = "CC")+ assertEquals(Who.Other, a.connected!!.first { it.address == other }.who)+ assertTrue(a.warning)+ }+@Test fun aKeyAllowedWhileTellyscopeWasntWatchingIsNew() {- fun keys(known: Set<String>?, watched: Set<String> = emptySet()) =- TvAccess.of(emptyList(), listOf(phoneKey, laptop), setOf(phone), "192.0.2.20", emptySet(), "AA", known = known, watched = watched).allowed!!+ fun keys(known: Set<String>?) =+ TvAccess.of(emptyList(), listOf(phoneKey, laptop), setOf(phone), "192.0.2.20", emptySet(), "AA", known = known).allowed!!assertTrue(keys(known = setOf("AA")).single { it.fingerprint == "BB" }.new)// First look at this TV: what's there is known. Allowed from Tellyscope's own prompt: known too.assertTrue(keys(known = null).none { it.new })- assertTrue(keys(known = setOf("AA"), watched = setOf("BB")).none { it.new })+ assertTrue(keys(known = setOf("AA", "BB")).none { it.new })assertTrue(keys(known = emptySet()).none { it.phone && it.new })}}