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.
Lead the TV page with the TV, its vitals and the main jobs
jesse-agent-2327073410b008c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex cf65460..a58a05d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -23,4 +23,4 @@ until this file has a section for its version.- **Fixed:** Done and error messages stay on screen long enough to read. [#20](../../pull/20)- **Fixed:** Undo and results always go to the TV the action ran on. [#20](../../pull/20)- **New:** Debloat in two steps: pick your TV, then review every app it turns off. [#23](../../pull/23)-- **Improved:** The TV page uses plain words; every number moves to a new Advanced screen. [#23](../../pull/23)+- **Improved:** The TV page leads with the TV, its vitals and big action buttons. [#23](../../pull/23)diff --git a/NOTICE b/NOTICEindex 30147d1..188e801 100644--- a/NOTICE+++ b/NOTICE@@ -22,7 +22,8 @@ debugging pairing.Material Icons — https://github.com/google/material-design-iconsLicense: Apache License 2.0The TV and HDMI (streaming stick) device icons use the path data of the-"tv" and "settings_input_hdmi" icons.+"tv" and "settings_input_hdmi" icons, and the Debloat button that of+"cleaning_services".--------------------------------------------------------------------------------cleanyourtv — https://github.com/Gathin23/cleanyourtvdiff --git a/README.md b/README.mdindex 8ca1c16..0c5e968 100644--- a/README.md+++ b/README.md@@ -6,7 +6,7 @@ See inside your Android TV from your phone. Live stats, reversible debloat, app<p><img src="docs/screenshots/scan.png" width="200" alt="Finding TVs on the Wi-Fi">- <img src="docs/screenshots/tv-page.png" width="200" alt="A TV's page: how it's doing, free space and suggested clean-up">+ <img src="docs/screenshots/tv-page.png" width="200" alt="A TV's page: the TV at a glance, its vitals, and the Install, Debloat and Send buttons"><img src="docs/screenshots/debloat.png" width="200" alt="Debloat: reviewing the apps it will turn off"><img src="docs/screenshots/install.png" width="200" alt="Installing an app on the TV"></p>@@ -19,7 +19,8 @@ Tellyscope is a phone app that talks to your Android TV, Google TV or Fire TV ov- **Find and connect.** It looks for TVs on your Wi-Fi, or you add one by IP address. Classic network debugging (port 5555) and Android 11+ wireless debugging with a 6-digit pairing code both work. A step-by-step card shows how to turn debugging on for Google TV, Android TV, Fire TV, Xiaomi and XGIMI.- **Remembers your TVs.** They reconnect on their own after a restart of the app or the TV. You can rename a TV (the name stays on your phone) or forget it.-- **How it's doing.** A one-line summary such as "Running fine" or "Storage almost full", and how much space is free.+- **How it's doing.** The TV at a glance: maker and model, a one-line summary such as "Running fine" or "Storage almost full", its address, how long it's been on, its Android version and when its software was last updated. Below that, free space as a bar, then CPU, RAM, temperature and network speed.+- **The main jobs up front.** Big **Install app**, **Debloat** and **Send file** buttons right under the vitals.- **Advanced.** Every number in one place: memory, storage, CPU, temperature, uptime and screen state, CPU and RAM by app, processes, network and data used, and the TV's address.- **Apps.** Every app on the TV with its real name and icon. Stop, disable, turn back on or open any app that isn't protected; each button says what it will do and asks first.- **Debloat.** Tellyscope matches your TV to a tested clean-up list (adapted from [cleanyourtv](https://github.com/Gathin23/cleanyourtv)) and says how many of its apps are still on. **Debloat** first asks which TV it is, with the match already chosen, then shows every app it will turn off. Apps are pre-ticked only when the TV runs the Android version the list was tested on; untick anything you use, and you confirm before anything is disabled.diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt b/adb/src/main/kotlin/app/tellyscope/adb/Commands.ktindex 42f815d..c43a812 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt@@ -10,8 +10,8 @@ internal object Commands {const val THERMAL ="for z in /sys/class/thermal/thermal_zone*; do echo \"$(cat \$z/type 2>/dev/null)=$(cat \$z/temp 2>/dev/null)\"; done"- /** Every 2 s: CPU counters and memory. */- val FAST = listOf("cat /proc/stat", "cat /proc/meminfo").batch()+ /** Every 2 s: CPU counters, memory and the byte counters for network speed. */+ val FAST = listOf("cat /proc/stat", "cat /proc/meminfo", "cat /proc/net/dev").batch()/** Every 60 s and on open: identity, storage, uptime, temperature. */val SLOW = listOf(diff --git a/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.kt b/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.ktindex ba814de..1c3356c 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/DeviceMonitor.kt@@ -6,6 +6,8 @@ import kotlinx.coroutines.flow.Flowimport kotlinx.coroutines.flow.flowimport kotlinx.coroutines.withTimeoutOrNullimport java.io.IOException+import java.time.YearMonth+import kotlin.time.ComparableTimeMarkimport kotlin.time.Durationimport kotlin.time.Duration.Companion.secondsimport kotlin.time.TimeSource@@ -25,6 +27,9 @@ data class Stats(val packages: Map<Int, List<String>> = emptyMap(),val processes: List<AppProcess> = emptyList(),val screenOn: Boolean? = null,+ /** Bytes in and out per second over the whole TV, between the last two fast readings. */+ val netBytesPerSec: Long? = null,+ val softwareMonth: YearMonth? = null,)/** One process and the package it belongs to; null for native daemons. */@@ -36,7 +41,7 @@ fun interface MonitorSource {}/**- * Live stats on three tiers: CPU/RAM every [fast], processes and screen state every [medium],+ * Live stats on three tiers: CPU/RAM/network speed every [fast], processes and screen state every [medium],* identity/storage/uptime/temperature/packages every [slow].* The first emission comes after one fast interval, since CPU % needs two samples.* Shell failures and reads slower than [readTimeout] throw [IOException], so the caller can mark@@ -48,13 +53,15 @@ class DeviceMonitor(private val medium: Duration = 10.seconds,private val slow: Duration = 60.seconds,private val readTimeout: Duration = 10.seconds,+ /** Times network speed; tests pass the test scheduler's clock. */+ private val clock: TimeSource.WithComparableMarks = TimeSource.Monotonic,) : MonitorSource {override fun stats(): Flow<Stats> = flow {var slowStats = readSlow()var lastSlow = TimeSource.Monotonic.markNow()var mediumStats = readMedium(slowStats.packages)var lastMedium = TimeSource.Monotonic.markNow()- var prevCpu = readFast().first+ var prev = readFast()while (true) {delay(fast)@@ -66,10 +73,18 @@ class DeviceMonitor(mediumStats = readMedium(slowStats.packages)lastMedium = TimeSource.Monotonic.markNow()}- val (cpu, mem) = readFast()- val pct = if (prevCpu != null && cpu != null) Parsers.cpuPercent(prevCpu, cpu) else null- prevCpu = cpu- emit(slowStats.copy(cpuPercent = pct, memory = mem, processes = mediumStats.first, screenOn = mediumStats.second))+ val now = readFast()+ val pct = if (prev.cpu != null && now.cpu != null) Parsers.cpuPercent(prev.cpu, now.cpu) else null+ emit(+ slowStats.copy(+ cpuPercent = pct,+ memory = now.memory,+ processes = mediumStats.first,+ screenOn = mediumStats.second,+ netBytesPerSec = rate(prev, now),+ ),+ )+ prev = now}}@@ -77,9 +92,18 @@ class DeviceMonitor(withTimeoutOrNull(readTimeout) { shell.shell(command).output }?: throw IOException("no answer in $readTimeout")- private suspend fun readFast(): Pair<Parsers.CpuTimes?, Parsers.Memory?> {- val (stat, meminfo) = Commands.split(run(Commands.FAST), 2)- return Parsers.cpuTimes(stat) to Parsers.memory(meminfo)+ private class Fast(val cpu: Parsers.CpuTimes?, val memory: Parsers.Memory?, val netBytes: Long?, val at: ComparableTimeMark)++ private suspend fun readFast(): Fast {+ val (stat, meminfo, netDev) = Commands.split(run(Commands.FAST), 3)+ return Fast(Parsers.cpuTimes(stat), Parsers.memory(meminfo), Parsers.netBytes(netDev), clock.markNow())+ }++ /** Null across a counter reset (an interface going down and up), never a negative speed. */+ private fun rate(prev: Fast, now: Fast): Long? {+ val bytes = (now.netBytes ?: return null) - (prev.netBytes ?: return null)+ val ms = (now.at - prev.at).inWholeMilliseconds+ return if (bytes < 0 || ms <= 0) null else bytes * 1000 / ms}private suspend fun readMedium(packages: Map<Int, List<String>>): Pair<List<AppProcess>, Boolean?> {@@ -104,6 +128,7 @@ class DeviceMonitor(manufacturer = props["ro.product.manufacturer"],androidVersion = props["ro.build.version.release"],sdk = props["ro.build.version.sdk"]?.toIntOrNull(),+ softwareMonth = Parsers.softwareMonth(props),packages = Parsers.byUid(Parsers.packages(pm)),)}diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Parsers.kt b/adb/src/main/kotlin/app/tellyscope/adb/Parsers.ktindex c5b25c7..231c5d1 100644--- a/adb/src/main/kotlin/app/tellyscope/adb/Parsers.kt+++ b/adb/src/main/kotlin/app/tellyscope/adb/Parsers.kt@@ -1,6 +1,10 @@// SPDX-License-Identifier: GPL-3.0-onlypackage app.tellyscope.adb+import java.time.Instant+import java.time.YearMonth+import java.time.ZoneOffset+/** Parsers for raw shell output. Pure functions; every one returns null rather than guessing. */object Parsers {@@ -236,4 +240,26 @@ object Parsers {val m = Regex("""\[(.+?)]: \[(.*)]""").matchEntire(line.trim()) ?: return@mapNotNull nullm.groupValues[1] to m.groupValues[2]}.toMap()++ /**+ * Bytes in plus out since boot over every interface but loopback, from `/proc/net/dev`; null+ * when nothing readable. Loopback is the TV talking to itself, not network traffic.+ */+ fun netBytes(procNetDev: String): Long? {+ val totals = procNetDev.lineSequence().mapNotNull { line ->+ val iface = line.substringBefore(':', "").trim().takeIf { it.isNotEmpty() && it != "lo" } ?: return@mapNotNull null+ val f = line.substringAfter(':').trim().split(Regex("\\s+")).mapNotNull(String::toLongOrNull)+ if (f.size < 9) null else f[0] + f[8] // rx bytes, tx bytes+ }.toList()+ return totals.takeIf { it.isNotEmpty() }?.sum()+ }++ /**+ * When the TV's software was last updated: the security patch month, which an update moves,+ * else the month the build was made. Null when the TV reports neither.+ */+ fun softwareMonth(props: Map<String, String>): YearMonth? =+ props["ro.build.version.security_patch"]?.let { runCatching { YearMonth.parse(it.take(7)) }.getOrNull() }+ ?: props["ro.build.date.utc"]?.toLongOrNull()?.takeIf { it > 0 }+ ?.let { YearMonth.from(Instant.ofEpochSecond(it).atZone(ZoneOffset.UTC)) }}diff --git a/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.ktindex 5e0244f..2576a90 100644--- a/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.kt+++ b/adb/src/test/kotlin/app/tellyscope/adb/DeviceMonitorTest.kt@@ -39,6 +39,22 @@ class DeviceMonitorTest {assertEquals(30, s.sdk)}+ @Test fun networkSpeedIsBytesPerSecondBetweenFastReadings() = runTest {+ var tick = 0L+ val tv = AdbShell { cmd ->+ if (cmd.startsWith("cat /proc/stat")) {+ tick+++ // 4000 bytes in and 1000 out per reading on wlan0; loopback moves too but isn't counted.+ ok("cpu 0 0 0 0\n${sep}MemTotal: 2000 kB\n$sep" ++ "Inter-| Receive | Transmit\n face |bytes packets errs drop fifo frame compressed multicast|bytes packets\n" ++ " lo: ${tick * 999} 1 0 0 0 0 0 0 ${tick * 999} 1 0 0 0 0 0 0\n" ++ " wlan0: ${tick * 4000} 1 0 0 0 0 0 0 ${tick * 1000} 1 0 0 0 0 0 0\n")+ } else ok("")+ }+ val s = DeviceMonitor(tv, clock = testScheduler.timeSource).stats().first()+ assertEquals(2500L, s.netBytesPerSec) // 5000 bytes over the default 2 s+ }+@Test fun keepsEmitting() = runTest {assertEquals(3, DeviceMonitor(device()).stats().take(3).toList().size)}diff --git a/adb/src/test/kotlin/app/tellyscope/adb/ParsersTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ParsersTest.ktindex 5bb0bad..0150610 100644--- a/adb/src/test/kotlin/app/tellyscope/adb/ParsersTest.kt+++ b/adb/src/test/kotlin/app/tellyscope/adb/ParsersTest.kt@@ -165,4 +165,25 @@ class ParsersTest {""".trimIndent()assertEquals(mapOf(10087 to Parsers.Traffic(1500, 300), 0 to Parsers.Traffic(40, 60)), Parsers.qtaguidTraffic(stats))}+ @Test fun netBytesSumsEveryInterfaceButLoopback() {+ val dev = """+ Inter-| Receive | Transmit+ face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed+ lo: 5000 50 0 0 0 0 0 0 5000 50 0 0 0 0 0 0+ wlan0:1200000 900 0 0 0 0 0 0 300000 400 0 0 0 0 0 0+ eth0: 10 1 0 0 0 0 0 0 20 1 0 0 0 0 0 0+ """.trimIndent()+ assertEquals(1_500_030L, Parsers.netBytes(dev))+ assertEquals(null, Parsers.netBytes("cat: /proc/net/dev: Permission denied\n"))+ }++ @Test fun softwareMonthPrefersTheSecurityPatch() {+ assertEquals(+ java.time.YearMonth.of(2023, 5),+ Parsers.softwareMonth(mapOf("ro.build.version.security_patch" to "2023-05-05", "ro.build.date.utc" to "1600000000")),+ )+ // 1600000000 is 13 September 2020, UTC.+ assertEquals(java.time.YearMonth.of(2020, 9), Parsers.softwareMonth(mapOf("ro.build.date.utc" to "1600000000")))+ assertEquals(null, Parsers.softwareMonth(mapOf("ro.build.version.security_patch" to "", "ro.build.date.utc" to "0")))+ }}diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex 8fbf50f..a123e41 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -241,6 +241,8 @@ class AdbDeviceSource(context: Context) : DeviceSource {uptimeSeconds = s.uptimeSeconds ?: 0,screenOn = s.screenOn,procs = s.processes.map { Proc(it.pid, it.name, it.packageName, it.cpuPercent, (it.rssKb / 1024).toInt()) },+ netBytesPerSec = s.netBytesPerSec,+ softwareMonth = s.softwareMonth,)}}diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.ktindex 2a0ebaf..72c92d8 100644--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt@@ -10,6 +10,7 @@ import app.tellyscope.adb.RemoteKeyimport app.tellyscope.adb.TvFileimport app.tellyscope.adb.TvFolderimport java.io.File+import java.time.YearMonthimport kotlin.random.Randomimport kotlinx.coroutines.currentCoroutineContextimport kotlinx.coroutines.delay@@ -157,6 +158,8 @@ class FakeDeviceSource(uptimeSeconds = 3 * 86_400L + 4 * 3_600L,screenOn = true,procs = procs,+ netBytesPerSec = 2_400_000L + random.nextLong(-200_000, 200_000),+ softwareMonth = YearMonth.of(2023, 5),)}diff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.ktindex 47d51fd..e9cabe5 100644--- a/app/src/main/java/app/tellyscope/data/Model.kt+++ b/app/src/main/java/app/tellyscope/data/Model.kt@@ -2,6 +2,8 @@package app.tellyscope.data+import java.time.YearMonth+/** How a TV was found: legacy network ADB on 5555, or Android 11+ wireless debugging (TLS + pairing code). */enum class ScanKind { Classic, Wireless }@@ -77,6 +79,10 @@ data class Snapshot(val uptimeSeconds: Long,val screenOn: Boolean?,val procs: List<Proc>,+ /** Whole-TV network traffic, in and out. */+ val netBytesPerSec: Long? = null,+ /** When the TV's software was last updated. */+ val softwareMonth: YearMonth? = null,)data class AppInfo(diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.ktindex 264ef33..c8f9fcc 100644--- a/app/src/main/java/app/tellyscope/ui/Copy.kt+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt@@ -9,6 +9,8 @@ import app.tellyscope.data.Actionimport app.tellyscope.data.AppNamesimport app.tellyscope.data.DeviceStateimport app.tellyscope.data.Snapshot+import java.time.YearMonth+import java.time.format.DateTimeFormatter/*** Every user-facing sentence about actions and time lives here so wording is@@ -74,6 +76,26 @@ object Copy {}}+ /** Uptime for people: the largest unit or two, spelled out. */+ fun upFor(s: Long): String {+ fun n(v: Long, unit: String) = "$v $unit${if (v == 1L) "" else "s"}"+ val d = s / 86_400+ val h = (s % 86_400) / 3600+ val m = (s % 3600) / 60+ return when {+ d > 0 && h > 0 -> "${n(d, "day")}, ${n(h, "hour")}"+ d > 0 -> n(d, "day")+ h > 0 -> n(h, "hour")+ else -> n(m, "minute")+ }+ }++ /** "May 2023", in the phone's language. */+ fun month(m: YearMonth): String = m.format(DateTimeFormatter.ofPattern("MMMM yyyy"))++ /** Network speed in the same units as [bytes], so a download's size and speed line up. */+ fun speed(bytesPerSec: Long) = bytes(bytesPerSec) + "/s"+fun mb(v: Int) = if (v >= 1024) "%.1f GB".format(v / 1024.0) else "$v MB"fun disabledSuggested(done: Int, of: Int) = when {diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.ktindex 7afca92..8ed8937 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt@@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.Spacerimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.width@@ -48,6 +49,7 @@ import androidx.compose.material3.FilledTonalButtonimport androidx.compose.material3.HorizontalDividerimport androidx.compose.material3.Iconimport androidx.compose.material3.IconButton+import androidx.compose.material3.LinearProgressIndicatorimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.OutlinedButtonimport androidx.compose.material3.OutlinedTextField@@ -163,7 +165,7 @@ fun DeviceScreen()} else {TopAppBar(- title = { DevicePicker(state, actions) },+ title = { Text("Your TV", style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.onSurfaceVariant) },actions = {if (REMOTE_ENABLED) TextButton(onClick = actions.remote, enabled = !offline) { Text("Remote") }TextButton(onClick = actions.advanced) { Text("Advanced") }@@ -180,23 +182,10 @@ fun DeviceScreen(contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = 32.dp),verticalArrangement = Arrangement.spacedBy(12.dp),) {- item {- // What the TV is on the left, where to find it on the right; the rest is on Advanced.- Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {- Text(- listOfNotNull(device.model, device.android?.let { "Android $it" }).joinToString(" · "),- Modifier.weight(1f),- style = MaterialTheme.typography.bodyMedium,- color = MaterialTheme.colorScheme.onSurfaceVariant,- )- Text(- listOfNotNull(device.hit.ip, device.manufacturer ?: device.hit.maker).joinToString(" · "),- style = MaterialTheme.typography.bodyMedium,- color = MaterialTheme.colorScheme.onSurfaceVariant,- textAlign = androidx.compose.ui.text.style.TextAlign.End,- )- }- }+ val snap = ui.snapshot+ // A reading from before the TV went away is stale: it doesn't speak for the TV now.+ val live = snap?.takeIf { !offline }+ item { TvCard(state, live, actions) }val restart = state.restarting[device.id]if (restart != null) {item { RestartingCard(restart, state.now) }@@ -205,15 +194,9 @@ fun DeviceScreen(} else if (offline) {item { OfflineCard(device, state.now, actions.reconnect) }}- val snap = ui.snapshot- if (snap != null) {- // Plain words only: the health line already reads memory, CPU and heat; free space- // decides whether an install fits. Every number is on Advanced.- if (!offline) item {- HealthLine(Copy.health(snap, heaviest(snap, ui.apps)))- Copy.free(snap)?.let { FreeLine(it) }- }- } else if (offline) {+ if (live != null) {+ item { SystemWidget(live) }+ } else if (offline && snap == null) {item {Text(Copy.noStats(device.state),@@ -222,11 +205,17 @@ fun DeviceScreen()}}- if (!offline && q.isEmpty()) item { SendRow(actions) }if (!offline && q.isEmpty()) {+ item {+ ActionTiles(+ actions,+ canDebloat = ui.lists is Suggestions.Pick || ui.lists is Suggestions.Ready,+ disabling = ui.busy == DISABLING,+ )+ }val count = (ui.lists as? Suggestions.Ready)?.groups?.sumOf { it.packages.size } ?: 0section("lists", "Suggested for this TV", count, expandedByDefault = true) {- SuggestionsSummary(ui.lists, ui.busy == DISABLING, actions.debloat)+ SuggestionsSummary(ui.lists)}}// An offline TV can't list anything: sections with nothing in them stay out of the way.@@ -257,6 +246,101 @@ fun DeviceScreen(}}+/**+ * The TV at a glance, with room to breathe: which TV (tap to switch), how it's doing, and the+ * few facts people look up. Everything else is on Advanced.+ */+@Composable+private fun TvCard(state: UiState, live: Snapshot?, actions: DeviceActions) {+ val device = state.selected ?: return+ val facts = listOfNotNull(+ "IP address" to device.hit.ip,+ live?.uptimeSeconds?.takeIf { it > 0 }?.let { "Up for" to Copy.upFor(it) },+ device.android?.let { "Android" to it },+ // Not live: the software doesn't change while the TV is away.+ state.device.snapshot?.softwareMonth?.let { "Last software update" to Copy.month(it) },+ )+ Card(+ Modifier.fillMaxWidth().padding(top = 4.dp),+ shape = MaterialTheme.shapes.extraLarge,+ colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow),+ ) {+ Column(Modifier.padding(18.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {+ DevicePicker(state, actions)+ if (live != null) {+ HealthLine(Copy.health(live, heaviest(live, state.device.apps)))+ } else {+ Row(verticalAlignment = Alignment.CenterVertically) {+ StateDot(device.state)+ Spacer(Modifier.width(8.dp))+ Text(Copy.state(device.state), style = MaterialTheme.typography.titleMedium)+ }+ }+ Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {+ facts.chunked(2).forEach { pair ->+ Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {+ pair.forEach { (k, v) -> Fact(k, v, Modifier.weight(1f)) }+ if (pair.size == 1) Spacer(Modifier.weight(1f))+ }+ }+ }+ }+ }+}++@Composable+private fun Fact(label: String, value: String, modifier: Modifier = Modifier) {+ Column(modifier) {+ Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Text(value, style = MaterialTheme.typography.bodyLarge, maxLines = 1, overflow = TextOverflow.Ellipsis)+ }+}++/**+ * The TV's vitals in one small card: internal storage as a full bar, since it decides whether an+ * install fits, then CPU, RAM, temperature and network speed as plain numbers.+ */+@Composable+private fun SystemWidget(s: Snapshot) {+ val dash = "\u2014"+ Card(+ Modifier.fillMaxWidth(),+ colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer),+ ) {+ Column(Modifier.padding(16.dp)) {+ val used = s.storageUsedGb+ val total = s.storageTotalGb?.takeIf { it > 0 }+ if (used != null && total != null) {+ Row {+ Text("Internal storage", Modifier.weight(1f), style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Text("${Copy.gbOf(used, total)} used", style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ }+ Copy.free(s)?.let { Text(it, style = MaterialTheme.typography.titleLarge) }+ val full = used / total+ LinearProgressIndicator(+ progress = { full.toFloat().coerceIn(0f, 1f) },+ modifier = Modifier.fillMaxWidth().padding(top = 8.dp, bottom = 16.dp).height(8.dp),+ color = if (full >= Copy.FULL) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primary,+ )+ }+ Row {+ Vital("CPU", "${s.cpuPercent}%", Modifier.weight(1f))+ Vital("RAM", if (s.ramTotalMb > 0) "${s.ramUsedMb * 100 / s.ramTotalMb}%" else dash, Modifier.weight(1f))+ Vital("Temp", s.tempC?.let { "$it\u00b0C" } ?: dash, Modifier.weight(1f))+ Vital("Network", s.netBytesPerSec?.let(Copy::speed) ?: dash, Modifier.weight(1.3f))+ }+ }+ }+}++@Composable+private fun Vital(label: String, value: String, modifier: Modifier = Modifier) {+ Column(modifier) {+ Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Text(value, style = MaterialTheme.typography.titleMedium.copy(fontFeatureSettings = "tnum"), maxLines = 1)+ }+}+@Composableprivate fun DevicePicker(state: UiState, actions: DeviceActions) {var open by remember { mutableStateOf(false) }@@ -277,16 +361,15 @@ private fun DevicePicker(state: UiState, actions: DeviceActions) {val offlineCount = state.devices.count { it.state != DeviceState.Online }Box {Row(- Modifier.clip(MaterialTheme.shapes.large).clickable { open = true }.padding(horizontal = 8.dp, vertical = 4.dp),+ Modifier.clip(MaterialTheme.shapes.large).clickable { open = true }.padding(vertical = 4.dp),verticalAlignment = Alignment.CenterVertically,) {KindBadge(device)Column(Modifier.weight(1f, fill = false)) {- Text(name(device), maxLines = 1, overflow = TextOverflow.Ellipsis)- Row(verticalAlignment = Alignment.CenterVertically) {- StateDot(device.state)- Spacer(Modifier.width(6.dp))- Text(Copy.state(device.state), style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Text(name(device), style = MaterialTheme.typography.titleLarge, maxLines = 1, overflow = TextOverflow.Ellipsis)+ val made = made(device.manufacturer ?: device.hit.maker, device.model)+ if (made.isNotEmpty()) {+ Text(made, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)}}Icon(Icons.Default.ArrowDropDown, contentDescription = "Switch TV")@@ -363,6 +446,12 @@ fun RestoreDialog(count: Int, onRestore: () -> Unit, onDismiss: () -> Unit) {)}+/** "XGIMI · Horizon Pro": many models already start with the maker's name, so it isn't said twice. */+private fun made(maker: String?, model: String?): String {+ val m = if (maker != null && model != null && model.startsWith(maker, ignoreCase = true)) model.drop(maker.length).trim() else model+ return listOfNotNull(maker, m?.takeIf { it.isNotEmpty() }).joinToString(" · ")+}+private fun name(d: Device) = d.nickname ?: networkName(d)private fun networkName(d: Device) = d.hit.hostname ?: d.model ?: d.hit.ip@@ -395,11 +484,11 @@ fun RenameDialog(current: String, networkName: String, onSave: (String) -> Unit,private fun KindBadge(d: Device) {val kind = deviceKind(d)Box(- Modifier.padding(end = 10.dp).size(40.dp).clip(MaterialTheme.shapes.medium)+ Modifier.padding(end = 14.dp).size(56.dp).clip(MaterialTheme.shapes.large).background(MaterialTheme.colorScheme.secondaryContainer),contentAlignment = Alignment.Center,) {- Icon(DeviceIcons.of(kind), contentDescription = kind.word(), tint = MaterialTheme.colorScheme.onSecondaryContainer)+ Icon(DeviceIcons.of(kind), contentDescription = kind.word(), Modifier.size(30.dp), tint = MaterialTheme.colorScheme.onSecondaryContainer)}}@@ -505,11 +594,6 @@ private fun HealthLine(h: Copy.Health) {}}-@Composable-private fun FreeLine(text: String) {- Text(text, Modifier.padding(start = 32.dp), style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)-}-/** A collapsible card section. */private fun LazyListScope.section(key: String,diff --git a/app/src/main/java/app/tellyscope/ui/ListsCard.kt b/app/src/main/java/app/tellyscope/ui/ListsCard.ktindex 4f41549..8a89772 100644--- a/app/src/main/java/app/tellyscope/ui/ListsCard.kt+++ b/app/src/main/java/app/tellyscope/ui/ListsCard.kt@@ -50,17 +50,16 @@ import androidx.compose.ui.unit.dpimport app.tellyscope.data.Suggestedimport app.tellyscope.data.Suggestions-/** Body of the "Suggested for this TV" section: one line on what the list offers, and the way in. */+/** Body of the "Suggested for this TV" section: one line on what the list offers; the Debloat tile is the way in. */@Composable-fun SuggestionsSummary(lists: Suggestions?, disabling: Boolean, onDebloat: () -> Unit) {+fun SuggestionsSummary(lists: Suggestions?) {when (lists) {null -> Muted("Looking up this TV's list…")Suggestions.Unavailable -> Muted("Couldn't load the device lists. They download the first time you open a TV; check the phone's internet and open this TV again.",)is Suggestions.Pick -> {- Text("Tellyscope doesn't know this model yet. Pick your TV to see what's usually safe to turn off.", style = MaterialTheme.typography.bodyMedium)- DebloatButton(disabling, onDebloat)+ Text("Tellyscope doesn't know this model yet. Tap Debloat to pick your TV and see what's usually safe to turn off.", style = MaterialTheme.typography.bodyMedium)}is Suggestions.Ready -> {val n = lists.groups.sumOf { it.packages.size }@@ -69,19 +68,11 @@ fun SuggestionsSummary(lists: Suggestions?, disabling: Boolean, onDebloat: () ->} else {Text("$n ${if (n == 1) "app" else "apps"} usually safe to turn off on this TV.", style = MaterialTheme.typography.bodyMedium)}- DebloatButton(disabling, onDebloat)}}if (lists is Suggestions.Pick || lists is Suggestions.Ready) Muted("Lists adapted from cleanyourtv (MIT).")}-@Composable-private fun DebloatButton(disabling: Boolean, onDebloat: () -> Unit) {- Button(onClick = onDebloat, enabled = !disabling, modifier = Modifier.padding(vertical = 4.dp)) {- Text(if (disabling) "Disabling…" else "Debloat")- }-}-@Composableprivate fun Muted(text: String) {Text(text, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)diff --git a/app/src/main/java/app/tellyscope/ui/Transfers.kt b/app/src/main/java/app/tellyscope/ui/Transfers.ktindex bf6b71e..12c8f89 100644--- a/app/src/main/java/app/tellyscope/ui/Transfers.kt+++ b/app/src/main/java/app/tellyscope/ui/Transfers.kt@@ -19,12 +19,10 @@ import androidx.compose.material.icons.filled.Sendimport androidx.compose.material.icons.filled.Warningimport androidx.compose.material3.AlertDialogimport androidx.compose.material3.Button-import androidx.compose.material3.ButtonDefaultsimport androidx.compose.material3.Checkboximport androidx.compose.material3.DropdownMenuimport androidx.compose.material3.DropdownMenuItemimport androidx.compose.material3.ExperimentalMaterial3ExpressiveApi-import androidx.compose.material3.FilledTonalButtonimport androidx.compose.material3.Iconimport androidx.compose.material3.LinearWavyProgressIndicatorimport androidx.compose.material3.LoadingIndicator@@ -32,6 +30,7 @@ import androidx.compose.material3.MaterialThemeimport androidx.compose.material3.SegmentedButtonimport androidx.compose.material3.SegmentedButtonDefaultsimport androidx.compose.material3.SingleChoiceSegmentedButtonRow+import androidx.compose.material3.Surfaceimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composable@@ -41,6 +40,10 @@ import androidx.compose.runtime.rememberimport androidx.compose.runtime.setValueimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.SolidColor+import androidx.compose.ui.graphics.vector.ImageVector+import androidx.compose.ui.graphics.vector.PathParserimport androidx.compose.ui.text.style.TextOverflowimport androidx.compose.ui.unit.dpimport androidx.compose.ui.window.DialogProperties@@ -55,24 +58,20 @@ import app.tellyscope.ui.theme.SmallNumber*/private val Sticky = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)-/** The two ways onto the TV, under the stats. */+/**+ * The three things people come to a TV's page for, as big tiles under the system widget.+ * Debloat is the filled one: it's what most people open the app to do.+ */@Composable-fun SendRow(actions: DeviceActions) {- Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- FilledTonalButton(onClick = actions.pickApp, Modifier.weight(1f)) {- Icon(Icons.Default.Add, null, Modifier.size(ButtonDefaults.IconSize))- Spacer(Modifier.width(ButtonDefaults.IconSpacing))- Text("Install an app")- }+fun ActionTiles(actions: DeviceActions, canDebloat: Boolean, disabling: Boolean) {+ Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {+ Tile(Icons.Default.Add, "Install app", actions.pickApp, Modifier.weight(1f))+ Tile(Broom, if (disabling) "Disabling…" else "Debloat", actions.debloat, Modifier.weight(1f), enabled = canDebloat && !disabling, primary = true)// Where the file lands is the user's choice, every time, not whatever folder was last shown.var choosing by remember { mutableStateOf(false) }Box(Modifier.weight(1f)) {- FilledTonalButton(onClick = { choosing = true }, Modifier.fillMaxWidth()) {- @Suppress("DEPRECATION") // the AutoMirrored set isn't in icons-core- Icon(Icons.Default.Send, null, Modifier.size(ButtonDefaults.IconSize))- Spacer(Modifier.width(ButtonDefaults.IconSpacing))- Text("Send a file")- }+ @Suppress("DEPRECATION") // the AutoMirrored set isn't in icons-core+ Tile(Icons.Default.Send, "Send file", { choosing = true }, Modifier.fillMaxWidth())DropdownMenu(choosing, onDismissRequest = { choosing = false }) {TvFolder.entries.forEach { f ->DropdownMenuItem(@@ -85,6 +84,56 @@ fun SendRow(actions: DeviceActions) {}}+@Composable+private fun Tile(+ icon: ImageVector,+ label: String,+ onClick: () -> Unit,+ modifier: Modifier = Modifier,+ enabled: Boolean = true,+ primary: Boolean = false,+) {+ val c = MaterialTheme.colorScheme+ Surface(+ onClick = onClick,+ modifier = modifier,+ enabled = enabled,+ shape = MaterialTheme.shapes.large,+ // Material's disabled colours, so a greyed-out Debloat doesn't still read as the main button.+ color = when {+ !enabled -> c.onSurface.copy(alpha = 0.12f)+ primary -> c.primary+ else -> c.secondaryContainer+ },+ contentColor = when {+ !enabled -> c.onSurface.copy(alpha = 0.38f)+ primary -> c.onPrimary+ else -> c.onSecondaryContainer+ },+ ) {+ Column(+ Modifier.padding(vertical = 20.dp, horizontal = 4.dp),+ horizontalAlignment = Alignment.CenterHorizontally,+ verticalArrangement = Arrangement.spacedBy(6.dp),+ ) {+ Icon(icon, contentDescription = null, Modifier.size(28.dp))+ Text(label, style = MaterialTheme.typography.labelLarge, maxLines = 1)+ }+ }+}++/** Material Icons "cleaning_services" (Apache-2.0, see NOTICE); icons-core has no broom. */+private val Broom = ImageVector.Builder("Broom", 24.dp, 24.dp, 24f, 24f)+ .addPath(+ PathParser().parsePathString(+ "M16 11h-1V3c0-1.1-.9-2-2-2h-2c-1.1 0-2 .9-2 2v8H8c-2.76 0-5 2.24-5 5v7h18v-7c0-2.76-2.24-5-5-5z" ++ "m3 10h-2v-3c0-.55-.45-1-1-1s-1 .45-1 1v3h-2v-3c0-.55-.45-1-1-1s-1 .45-1 1v3H9v-3c0-.55-.45-1-1-1s-1 .45-1 1v3H5v-5" ++ "c0-1.65 1.35-3 3-3h8c1.65 0 3 1.35 3 3v5z",+ ).toNodes(),+ fill = SolidColor(Color.Black),+ )+ .build()+/** Body of the Files section: the folder switch, then the folder's files, each one tap from the phone. */@Composablefun FilesBlock(files: FilesUi, now: Long, actions: DeviceActions) {diff --git a/app/src/test/java/app/tellyscope/CopyTest.kt b/app/src/test/java/app/tellyscope/CopyTest.ktnew file mode 100644index 0000000..475c058--- /dev/null+++ b/app/src/test/java/app/tellyscope/CopyTest.kt@@ -0,0 +1,22 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope++import app.tellyscope.ui.Copy+import org.junit.Assert.assertEquals+import org.junit.Test++class CopyTest {+ @Test fun upForSpellsOutTheLargestUnits() {+ assertEquals("3 days, 4 hours", Copy.upFor(3 * 86_400L + 4 * 3_600 + 59))+ assertEquals("1 day", Copy.upFor(86_400L + 120))+ assertEquals("1 hour", Copy.upFor(3_600L + 300))+ assertEquals("12 minutes", Copy.upFor(12 * 60L))+ }++ @Test fun speedUsesTheSameUnitsAsSizes() {+ assertEquals("2.3 MB/s", Copy.speed(2_400_000))+ assertEquals("12 KB/s", Copy.speed(12_500))+ assertEquals("300 bytes/s", Copy.speed(300))+ }+}diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.ktindex 035d216..e96da39 100644--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt@@ -179,7 +179,9 @@ class ScreenshotTest {compose.onNodeWithText("Details").assertDoesNotExist()compose.onNodeWithText("Advanced").assertExists()compose.onNodeWithText("Running · ", substring = true).assertDoesNotExist()- compose.onNodeWithText("Debloat").assertExists()+ // The three main actions sit under the system widget, Debloat among them.+ for (t in listOf("Install app", "Debloat", "Send file")) compose.onNodeWithText(t).assertIsEnabled()+ for (t in listOf("Up for", "Last software update", "Internal storage", "Network")) compose.onNodeWithText(t).assertExists()}@Test fun device_overview_dark() = shot("04_device", dark = true) { DeviceScreen(deviceState(), DeviceActions()) }@@ -205,6 +207,10 @@ class ScreenshotTest {shot("06_device_offline") {DeviceScreen(base.copy(selectedId = off.id, device = DeviceUi(snapshot = last), showOffline = true), DeviceActions())}+ // Old numbers don't speak for a TV that's away; what it is still does.+ compose.onNodeWithText("Up for").assertDoesNotExist()+ compose.onNodeWithText("Internal storage").assertDoesNotExist()+ compose.onNodeWithText("Last software update").assertExists()}@Test fun device_storageFull() {diff --git a/docs/screenshots/tv-page.png b/docs/screenshots/tv-page.pngindex 757a283..21bbe2a 100644Binary files a/docs/screenshots/tv-page.png and b/docs/screenshots/tv-page.png differ