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.
Make the TV page readable without the technical bits
jesse-agent-232c72d4a960177
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.ktindex 2c869d2..4e7f11a 100644--- a/app/src/main/java/app/tellyscope/MainActivity.kt+++ b/app/src/main/java/app/tellyscope/MainActivity.kt@@ -163,6 +163,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {undo = vm::undo,reconnect = { state.selectedId?.let(vm::reconnect) },forget = vm::forget,+ rename = vm::rename,restoreAll = vm::restoreAll,),)diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex 815c109..b2955ce 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -57,6 +57,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {/** Wireless debugging advertises pairing and connect on different ports. */private val pairingPorts = ConcurrentHashMap<String, Int>()private val book = HistoryBook(File(appContext.filesDir, "history.tsv"))+ private val names = NameBook(File(appContext.filesDir, "names.tsv"))/** Last label seen per package, so history entries read like the app list. */private val labels = ConcurrentHashMap<String, String>()private val helperDex by lazy { appContext.assets.open("label-helper.jar").use { it.readBytes() } }@@ -123,6 +124,11 @@ class AdbDeviceSource(context: Context) : DeviceSource {links[deviceId]?.connect()}+ override suspend fun rename(deviceId: String, name: String?) {+ restored.await()+ names.set(key(deviceId), name)+ }+override suspend fun forget(deviceId: String) {restored.await()watchers.remove(deviceId)?.cancel()@@ -321,6 +327,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {}if (keys.put(deviceId, key) != key) {book.rekey(deviceId, key)+ names.rekey(deviceId, key)remember(deviceId)}return key@@ -354,6 +361,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {manufacturer = stats?.manufacturer,android = stats?.androidVersion,lastSeen = link?.lastSeenMillis ?: saved[id]?.lastSeen,+ nickname = names[keys[id] ?: id],)}diff --git a/app/src/main/java/app/tellyscope/data/AppNames.kt b/app/src/main/java/app/tellyscope/data/AppNames.ktindex 20a1ddb..76aeb59 100644--- a/app/src/main/java/app/tellyscope/data/AppNames.kt+++ b/app/src/main/java/app/tellyscope/data/AppNames.kt@@ -57,12 +57,23 @@ class AppNames(private val dir: File) {}companion object {- /** Bundled table first, then `com.google.android.youtube.tv` → "Youtube". */+ /**+ * Bundled table first, then a humanised id that keeps the maker: `com.xgimi.assistant` →+ * "XGIMI Assistant", `com.google.android.youtube.tv` → "Youtube".+ */fun fallback(pkg: String): String = KnownLabels[pkg] ?: humanise(pkg)+ private val GENERIC = setOf("com", "net", "org", "io", "co", "android", "google", "tv", "app", "apps")++ /** Makers whose name isn't simply capitalised. */+ private val BRAND_CASE = mapOf("xgimi" to "XGIMI", "tcl" to "TCL", "lg" to "LG", "nvidia" to "NVIDIA", "hbo" to "HBO", "bbc" to "BBC")+private fun humanise(pkg: String): String {- val parts = pkg.split('.').filter { it !in setOf("com", "android", "google", "tv", "app", "apps", "org") }- return (parts.lastOrNull() ?: pkg).replaceFirstChar(Char::uppercase)+ val parts = pkg.split('.').filter { it.isNotEmpty() && it.lowercase() !in GENERIC }+ val name = parts.lastOrNull() ?: return pkg+ // The maker is the first part left; skip it when the name already says it.+ val maker = parts.first().takeIf { parts.size > 1 && !name.lowercase().contains(it.lowercase()) }+ return listOfNotNull(maker, name).joinToString(" ") { BRAND_CASE[it.lowercase()] ?: it.replaceFirstChar(Char::uppercase) }}private fun fileName(tv: String) = tv.replace(Regex("[^A-Za-z0-9._-]"), "_") + ".tsv"diff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.ktindex dab7099..03ee0ba 100644--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt@@ -26,6 +26,9 @@ interface DeviceSource {/** Try a known TV again after it stopped at "not allowed": the TV shows its Allow prompt. */suspend fun reconnect(deviceId: String)+ /** The user's own name for a TV; blank goes back to the network name. Kept per [historyKey]. */+ suspend fun rename(deviceId: String, name: 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 71352d0..5c37208 100644--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt@@ -96,6 +96,10 @@ class FakeDeviceSource(override suspend fun reconnect(deviceId: String) = Unit+ override suspend fun rename(deviceId: String, name: String?) {+ remembered[deviceId]?.let { remembered[deviceId] = it.copy(nickname = name?.trim()?.ifEmpty { null }) }+ }+override suspend fun forget(deviceId: String) {remembered.remove(deviceId)}diff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.ktindex 668bc89..47d51fd 100644--- a/app/src/main/java/app/tellyscope/data/Model.kt+++ b/app/src/main/java/app/tellyscope/data/Model.kt@@ -43,6 +43,8 @@ data class Device(val android: String?,/** Epoch millis of the last successful poll. */val lastSeen: Long?,+ /** The name the user gave it; wins over the network name. */+ val nickname: String? = null,)sealed interface ConnectResult {diff --git a/app/src/main/java/app/tellyscope/data/NameBook.kt b/app/src/main/java/app/tellyscope/data/NameBook.ktnew file mode 100644index 0000000..c65a481--- /dev/null+++ b/app/src/main/java/app/tellyscope/data/NameBook.kt@@ -0,0 +1,58 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope.data++import java.io.File++/**+ * Names the user gave their TVs, keyed like history ([historyKey]) so a name follows the TV+ * across DHCP changes and survives Forget + add again. `key \t name` per line; null file keeps+ * it in memory (tests, the fake source).+ */+class NameBook(private val file: File? = null) {+ private val names = linkedMapOf<String, String>()++ init {+ file?.takeIf { it.exists() }?.let { f ->+ runCatching { f.readLines() }.getOrDefault(emptyList()).forEach { line ->+ val (k, v) = line.split('\t').takeIf { it.size == 2 && it[0].isNotEmpty() && it[1].isNotBlank() } ?: return@forEach+ names[k] = v+ }+ }+ }++ @Synchronized+ operator fun get(key: String): String? = names[key]++ /** Blank clears the name, so the TV goes back to what the network calls it. */+ @Synchronized+ fun set(key: String, name: String?) {+ val clean = name.orEmpty().replace(Regex("[\\t\\r\\n]"), " ").trim().take(MAX_LENGTH)+ if (clean.isEmpty()) names.remove(key) else names[key] = clean+ save()+ }++ /** The address stood in until the TV said who it is; the name moves to the real key. */+ @Synchronized+ fun rekey(from: String, to: String) {+ if (from == to) return+ val name = names.remove(from) ?: return+ names.putIfAbsent(to, name)+ save()+ }++ private fun save() {+ val f = file ?: return+ f.parentFile?.mkdirs()+ val tmp = File(f.path + ".tmp")+ tmp.writeText(names.entries.joinToString("") { (k, v) -> "$k\t$v\n" })+ if (!tmp.renameTo(f)) {+ f.delete()+ tmp.renameTo(f)+ }+ }++ companion object {+ const val MAX_LENGTH = 40+ }+}diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.ktindex bcad8be..a5af40b 100644--- a/app/src/main/java/app/tellyscope/ui/Copy.kt+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt@@ -3,6 +3,8 @@package app.tellyscope.uiimport app.tellyscope.data.Action+import app.tellyscope.data.DeviceState+import app.tellyscope.data.Snapshot/*** Every user-facing sentence about actions and time lives here so wording is@@ -71,4 +73,35 @@ object Copy {fun mb(v: Int) = if (v >= 1024) "%.1f GB".format(v / 1024.0) else "$v MB"const val ANDROID_SYSTEM = "Android system"++ /** The word next to the status dot, so the state never rests on colour alone. */+ fun state(s: DeviceState) = when (s) {+ DeviceState.Online -> "Connected"+ DeviceState.Offline -> "Offline"+ DeviceState.NotAllowed -> "Not allowed"+ DeviceState.Waiting -> "Connecting"+ DeviceState.NeedsPairing -> "Needs the pairing code"+ DeviceState.Found -> "Not connected"+ }++ data class Health(val ok: Boolean, val text: String)++ /**+ * The one line at the top of a TV's page: the most pressing problem, or that all is well.+ * [heaviest] are app names by memory use, largest first; there is no per-app storage size yet.+ */+ fun health(s: Snapshot, heaviest: List<String>): Health {+ val storage = s.storageUsedGb?.let { u -> s.storageTotalGb?.takeIf { it > 0 }?.let { u / it } }+ val ram = if (s.ramTotalMb > 0) s.ramUsedMb.toDouble() / s.ramTotalMb else null+ val most = heaviest.take(2).takeIf { it.isNotEmpty() }?.let { ": ${it.joinToString(" and ")} use the most" }.orEmpty()+ return when {+ storage != null && storage >= FULL -> Health(false, "Storage almost full")+ ram != null && ram >= FULL -> Health(false, "Memory almost full$most")+ (s.tempC ?: 0) >= HOT_C -> Health(false, "Running hot")+ else -> Health(true, "Running fine")+ }+ }++ const val FULL = 0.9+ private const val HOT_C = 80}diff --git a/app/src/main/java/app/tellyscope/ui/Details.kt b/app/src/main/java/app/tellyscope/ui/Details.ktnew file mode 100644index 0000000..5bbb8d7--- /dev/null+++ b/app/src/main/java/app/tellyscope/ui/Details.kt@@ -0,0 +1,60 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope.ui++import androidx.compose.animation.animateContentSize+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.filled.KeyboardArrowDown+import androidx.compose.material3.Icon+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.saveable.rememberSaveable+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.draw.rotate+import androidx.compose.ui.unit.dp+import app.tellyscope.ui.theme.SmallNumber++/**+ * Technical facts (addresses, ids, what the TV actually said) one tap away, under the plain+ * sentence that explains them. Closed by default: most people never need them.+ */+@Composable+fun Details(rows: List<Pair<String, String>>, modifier: Modifier = Modifier) {+ if (rows.isEmpty()) return+ var open by rememberSaveable { mutableStateOf(false) }+ Column(modifier.animateContentSize(MaterialTheme.motionScheme.defaultSpatialSpec())) {+ Row(+ Modifier.clip(MaterialTheme.shapes.small).clickable { open = !open }.padding(vertical = 4.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ Text("Details", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.primary)+ Icon(+ Icons.Default.KeyboardArrowDown,+ contentDescription = if (open) "Hide details" else "Show details",+ Modifier.size(18.dp).rotate(if (open) 180f else 0f),+ tint = MaterialTheme.colorScheme.primary,+ )+ }+ if (open) rows.forEach { (k, v) -> KeyValue(k, v) }+ }+}++@Composable+fun KeyValue(k: String, v: String) {+ Row(Modifier.padding(vertical = 2.dp)) {+ Text(k, Modifier.width(96.dp), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Text(v, style = SmallNumber)+ }+}diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.ktindex 3d66192..96e304f 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt@@ -28,10 +28,15 @@ import androidx.compose.foundation.shape.CircleShapeimport androidx.compose.material.icons.Iconsimport androidx.compose.material.icons.filled.Addimport androidx.compose.material.icons.filled.ArrowDropDown+import androidx.compose.material.icons.filled.CheckCircleimport androidx.compose.material.icons.filled.Closeimport androidx.compose.material.icons.filled.Delete+import androidx.compose.material.icons.filled.Edit+import androidx.compose.material.icons.filled.Infoimport androidx.compose.material.icons.filled.KeyboardArrowDown+import androidx.compose.material.icons.filled.Lockimport androidx.compose.material.icons.filled.Search+import androidx.compose.material.icons.filled.Warningimport androidx.compose.material3.AlertDialogimport androidx.compose.material3.Buttonimport androidx.compose.material3.Card@@ -45,8 +50,10 @@ 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.OutlinedButton+import androidx.compose.material3.OutlinedTextFieldimport androidx.compose.material3.Scaffoldimport androidx.compose.material3.SnackbarHostimport androidx.compose.material3.SnackbarHostState@@ -72,6 +79,7 @@ import androidx.compose.ui.text.style.TextOverflowimport androidx.compose.ui.unit.dpimport app.tellyscope.data.Actionimport app.tellyscope.data.AppInfo+import app.tellyscope.data.AppNamesimport app.tellyscope.data.Deviceimport app.tellyscope.data.DeviceStateimport app.tellyscope.data.HistoryBook@@ -93,6 +101,7 @@ data class DeviceActions(val undo: (HistoryEntry) -> Unit = {},val reconnect: () -> Unit = {},val forget: (String) -> Unit = {},+ val rename: (String, String?) -> Unit = { _, _ -> },val restoreAll: () -> Unit = {},)@@ -152,22 +161,44 @@ fun DeviceScreen() {item {Text(- listOfNotNull(device.model, device.android?.let { "Android $it" }, device.hit.ip).joinToString(" · "),- style = SmallNumber,+ listOfNotNull(device.model, device.android?.let { "Android $it" }).joinToString(" · "),+ style = MaterialTheme.typography.bodyMedium,color = MaterialTheme.colorScheme.onSurfaceVariant,)+ Details(+ listOfNotNull(+ "IP address" to device.hit.ip,+ "Port" to device.hit.port.toString(),+ (device.manufacturer ?: device.hit.maker)?.let { "Maker" to it },+ device.hit.hostname?.let { "Network name" to it },+ ),+ )}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 ->+ val snap = ui.snapshot+ if (snap != null) {+ if (!offline) item { HealthLine(Copy.health(snap, heaviest(snap, ui.apps))) }+ // Offline: the last stats this phone saw, greyed and dated, rather than a grid of blanks.+ item { Stats(snap, if (offline) state.now else null) }+ } else if (offline) {+ item {+ Text(+ "No stats yet. They show up once the TV is back on.",+ style = MaterialTheme.typography.bodyMedium,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ }+ }+ snap?.let {// The :adb source has no per-process list yet; no bars beats an empty card.- if (q.isEmpty() && snap.procs.isNotEmpty()) item { UsageCard(snap, ui.apps) }+ if (q.isEmpty() && it.procs.isNotEmpty() && !offline) item { UsageCard(it, ui.apps) }}- section(+ // An offline TV can't list anything: sections with nothing in them stay out of the way.+ if (!offline || ui.apps.isNotEmpty()) section(key = "apps",title = "Apps",count = ui.apps.size,@@ -179,13 +210,13 @@ fun DeviceScreen(.sortedWith(compareBy({ it.protectedReason != null }, { !it.enabled }, { it.system }, { it.label }))if (apps.isEmpty()) EmptyLine(q)apps.forEach { app ->- AppRow(app, ui.snapshot?.procs.orEmpty(), ui.pending, ui.busy == app.packageName, actions)+ AppRow(app, snap?.procs.orEmpty(), ui.pending, ui.busy == app.packageName, actions)}}- section("procs", "Processes", ui.snapshot?.procs?.size ?: 0, forceOpen = q.isNotEmpty()) {- ProcessTable(ui.snapshot?.procs.orEmpty(), ui.apps, q)+ if (!offline || !snap?.procs.isNullOrEmpty()) section("procs", "Processes", snap?.procs?.size ?: 0, forceOpen = q.isNotEmpty()) {+ ProcessTable(snap?.procs.orEmpty(), ui.apps, q)}- section("net", "Network", ui.network?.sockets?.size ?: 0, forceOpen = q.isNotEmpty()) {+ if (!offline || ui.network != null) section("net", "Network", ui.network?.sockets?.size ?: 0, forceOpen = q.isNotEmpty()) {ui.network?.let { NetworkBlock(it, q) }}section("history", "History", ui.history.size) {@@ -199,17 +230,25 @@ fun DeviceScreen(private fun DevicePicker(state: UiState, actions: DeviceActions) {var open by remember { mutableStateOf(false) }var forgetting by remember { mutableStateOf(false) }+ var renaming by remember { mutableStateOf(false) }val device = state.selected ?: returnif (forgetting) ForgetDialog(name(device), onForget = { forgetting = false; actions.forget(device.id) }, onDismiss = { forgetting = false })+ if (renaming) RenameDialog(device.nickname.orEmpty(), networkName(device), onSave = { renaming = false; actions.rename(device.id, it) }, onDismiss = { renaming = false })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),verticalAlignment = Alignment.CenterVertically,) {- StateDot(device.state)- Spacer(Modifier.width(8.dp))- Text(name(device), maxLines = 1, overflow = TextOverflow.Ellipsis)+ BrandBadge(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)+ }+ }Icon(Icons.Default.ArrowDropDown, contentDescription = "Switch TV")}DropdownMenu(open, onDismissRequest = { open = false }) {@@ -220,8 +259,9 @@ private fun DevicePicker(state: UiState, actions: DeviceActions) {text = { Text(name(d)) },leadingIcon = { StateDot(d.state) },trailingIcon = {- if (d.state != DeviceState.Online) Text(- d.lastSeen?.let { "seen ${Copy.ago(it, state.now)}" } ?: "offline",+ Text(+ if (d.state == DeviceState.Online) Copy.state(d.state)+ else d.lastSeen?.let { "${Copy.state(d.state)}, seen ${Copy.ago(it, state.now)}" } ?: Copy.state(d.state),style = MaterialTheme.typography.labelSmall,)},@@ -239,6 +279,11 @@ private fun DevicePicker(state: UiState, actions: DeviceActions) {leadingIcon = { Icon(Icons.Default.Add, null) },onClick = { open = false; actions.addDevice() },)+ DropdownMenuItem(+ text = { Text("Rename this TV") },+ leadingIcon = { Icon(Icons.Default.Edit, null) },+ onClick = { open = false; renaming = true },+ )DropdownMenuItem(text = { Text("Forget this TV") },leadingIcon = { Icon(Icons.Default.Delete, null) },@@ -265,7 +310,59 @@ fun RestoreDialog(count: Int, onRestore: () -> Unit, onDismiss: () -> Unit) {)}-private fun name(d: Device) = d.hit.hostname ?: d.model ?: d.hit.ip+private fun name(d: Device) = d.nickname ?: networkName(d)++private fun networkName(d: Device) = d.hit.hostname ?: d.model ?: d.hit.ip++/** Stored on this phone only, per TV; an empty name goes back to what the network calls it. */+@Composable+fun RenameDialog(current: String, networkName: String, onSave: (String) -> Unit, onDismiss: () -> Unit) {+ var text by rememberSaveable { mutableStateOf(current) }+ AlertDialog(+ onDismissRequest = onDismiss,+ title = { Text("Rename this TV") },+ text = {+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {+ Text("Only this phone sees the name. Nothing on the TV changes.")+ OutlinedTextField(+ value = text,+ onValueChange = { text = it.take(app.tellyscope.data.NameBook.MAX_LENGTH) },+ singleLine = true,+ placeholder = { Text(networkName) },+ )+ }+ },+ confirmButton = { Button(onClick = { onSave(text) }) { Text("Save") } },+ dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },+ )+}++/**+ * The maker's name on a tile, when the TV said who made it. A wordmark in the app's own colours,+ * not the maker's logo: no third-party artwork ships in the app.+ */+@Composable+private fun BrandBadge(d: Device) {+ val maker = (d.manufacturer ?: d.hit.maker)?.let(::brand) ?: return+ Box(+ Modifier.padding(end = 10.dp).size(width = 52.dp, height = 36.dp).clip(MaterialTheme.shapes.medium)+ .background(MaterialTheme.colorScheme.secondaryContainer),+ contentAlignment = Alignment.Center,+ ) {+ Text(maker, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSecondaryContainer, maxLines = 1)+ }+}++/** Makers of Android TVs and boxes, as they write their own name. Chip makers (Amlogic) don't count. */+private fun brand(maker: String): String? {+ val words = maker.split(Regex("[^A-Za-z]+"))+ return BRANDS.firstOrNull { b -> words.any { it.equals(b, ignoreCase = true) } }+}++private val BRANDS = listOf(+ "XGIMI", "Google", "Sony", "TCL", "Xiaomi", "Philips", "Hisense", "NVIDIA", "Amazon", "Nokia",+ "Toshiba", "Sharp", "Skyworth", "Haier", "Panasonic", "Nebula", "Dangbei", "Formovie", "onn",+)/** Forgetting only touches this phone; the TV keeps its own list of allowed computers. */@Composable@@ -284,7 +381,8 @@ private fun StateDot(state: DeviceState) {val c = when (state) {DeviceState.Online -> MaterialTheme.colorScheme.primaryDeviceState.Waiting, DeviceState.Found, DeviceState.NeedsPairing -> MaterialTheme.colorScheme.tertiary- DeviceState.Offline, DeviceState.NotAllowed -> MaterialTheme.colorScheme.outline+ DeviceState.Offline -> MaterialTheme.colorScheme.outline+ DeviceState.NotAllowed -> MaterialTheme.colorScheme.error}Box(Modifier.size(10.dp).clip(CircleShape).background(c))}@@ -292,29 +390,48 @@ private fun StateDot(state: DeviceState) {/** The TV refused (revoked access, a reset, or Deny); retrying stopped so the prompt doesn't nag. */@Composableprivate fun NotAllowedCard(onConnect: () -> Unit) {- Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerHigh)) {+ Card(+ colors = CardDefaults.cardColors(+ containerColor = MaterialTheme.colorScheme.errorContainer,+ contentColor = MaterialTheme.colorScheme.onErrorContainer,+ ),+ ) {Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {- Text("The TV didn't allow this phone", style = MaterialTheme.typography.titleSmall)+ CardTitle(Icons.Default.Warning, "The TV didn't allow this phone")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") }+ Button(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,)}}}+@Composable+private fun CardTitle(icon: androidx.compose.ui.graphics.vector.ImageVector, text: String) {+ Row(verticalAlignment = Alignment.CenterVertically) {+ Icon(icon, contentDescription = null, Modifier.size(20.dp))+ Spacer(Modifier.width(8.dp))+ Text(text, style = MaterialTheme.typography.titleSmall)+ }+}+@Composableprivate fun OfflineCard(device: Device, now: Long, onReconnect: () -> Unit) {- Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerHigh)) {+ // Material 3 has no warning role; tertiary is the standard stand-in, kept apart from error.+ Card(+ colors = CardDefaults.cardColors(+ containerColor = MaterialTheme.colorScheme.tertiaryContainer,+ contentColor = MaterialTheme.colorScheme.onTertiaryContainer,+ ),+ ) {Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {Column(Modifier.weight(1f)) {- Text("Offline", style = MaterialTheme.typography.titleSmall)+ CardTitle(Icons.Default.Info, "Offline")Text("Last seen ${device.lastSeen?.let { Copy.ago(it, now) } ?: "a while ago"}. It reconnects on its own when the TV is back on.",style = MaterialTheme.typography.bodyMedium,@@ -326,26 +443,58 @@ private fun OfflineCard(device: Device, now: Long, onReconnect: () -> Unit) {}}-/** Stat strip, phone-shaped: a 3×2 grid. Missing stats show "—", never 0. */+/** App names by memory use, largest first, for the health line. */+private fun heaviest(snap: Snapshot, apps: List<AppInfo>): List<String> {+ val labels = apps.associate { it.packageName to it.label }+ return snap.procs.filter { it.packageName != null }+ .groupBy { labels[it.packageName] ?: AppNames.fallback(it.packageName!!) }+ .mapValues { (_, ps) -> ps.sumOf { it.ramMb } }+ .entries.sortedByDescending { it.value }.map { it.key }+}++@Composable+private fun HealthLine(h: Copy.Health) {+ Row(verticalAlignment = Alignment.CenterVertically) {+ Icon(+ if (h.ok) Icons.Default.CheckCircle else Icons.Default.Warning,+ contentDescription = null,+ Modifier.size(24.dp),+ tint = if (h.ok) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.error,+ )+ Spacer(Modifier.width(8.dp))+ Text(h.text, style = MaterialTheme.typography.titleMedium)+ }+}++/**+ * Memory and storage as "75% used" with a bar, then the small stats. Missing stats show "—",+ * never 0. [staleSince] set means the TV is offline: these are its last numbers, greyed and dated.+ */@Composable-private fun StatGrid(s: Snapshot?, modifier: Modifier = Modifier) {+private fun Stats(s: Snapshot, staleSince: Long?) {val cells = listOf(- "CPU" to s?.let { "${it.cpuPercent}%" },- // Units live in the label so the value fits a third of a phone width.- "RAM GB" to s?.let { "%.1f/%.0f".format(it.ramUsedMb / 1024.0, it.ramTotalMb / 1024.0) },- "Storage GB" to s?.storageUsedGb?.let { u -> s.storageTotalGb?.let { t -> "%.1f/%.0f".format(u, t) } },- "Temp" to s?.tempC?.let { "$it°C" },- "Up" to s?.let { Copy.uptime(it.uptimeSeconds) },- "Screen" to s?.screenOn?.let { if (it) "on" else "off" },+ "CPU" to "${s.cpuPercent}%",+ "Temperature" to s.tempC?.let { "$it°C" },+ "On for" to Copy.uptime(s.uptimeSeconds),+ "Screen" to s.screenOn?.let { if (it) "On" else "Off" },)- Card(modifier, colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)) {- Column(Modifier.padding(vertical = 8.dp)) {- cells.chunked(3).forEach { row ->+ Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)) {+ Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {+ if (staleSince != null) {+ Text(+ "As of ${Copy.ago(s.at, staleSince)}",+ style = MaterialTheme.typography.labelLarge,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ }+ Column(Modifier.alpha(if (staleSince != null) 0.5f else 1f), verticalArrangement = Arrangement.spacedBy(16.dp)) {+ Meter("Memory", s.ramUsedMb / 1024.0, s.ramTotalMb / 1024.0)+ s.storageUsedGb?.let { u -> s.storageTotalGb?.let { t -> Meter("Storage", u, t) } }Row(Modifier.fillMaxWidth()) {- row.forEach { (label, value) ->- Column(Modifier.weight(1f).padding(horizontal = 16.dp, vertical = 8.dp)) {- Text(label.uppercase(), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)- Text(value ?: "—", style = StatNumber, maxLines = 1)+ cells.forEach { (label, value) ->+ Column(Modifier.weight(1f)) {+ Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Text(value ?: "—", style = MaterialTheme.typography.titleLarge.copy(fontFeatureSettings = "tnum"), maxLines = 1)}}}@@ -354,11 +503,30 @@ private fun StatGrid(s: Snapshot?, modifier: Modifier = Modifier) {}}+@Composable+private fun Meter(label: String, usedGb: Double, totalGb: Double) {+ val frac = if (totalGb > 0) (usedGb / totalGb).toFloat().coerceIn(0f, 1f) else 0f+ Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {+ Row(verticalAlignment = Alignment.Bottom) {+ Column(Modifier.weight(1f)) {+ Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)+ Text("${(frac * 100).toInt()}% used", style = StatNumber)+ }+ Text("%.1f of %.0f GB".format(usedGb, totalGb), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)+ }+ LinearProgressIndicator(+ progress = { frac },+ Modifier.fillMaxWidth(),+ color = if (frac >= Copy.FULL) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primary,+ )+ }+}+/** Grey bars, no chart library: top 6 by value, the rest summed as "other". */@Composableprivate fun UsageCard(snap: Snapshot, apps: List<AppInfo>) {val labels = apps.associate { it.packageName to it.label }- fun label(p: Proc) = p.packageName?.let { labels[it] ?: it } ?: Copy.ANDROID_SYSTEM+ fun label(p: Proc) = p.packageName?.let { labels[it] ?: AppNames.fallback(it) } ?: Copy.ANDROID_SYSTEMval byApp = snap.procs.groupBy(::label)var cpu by rememberSaveable { mutableStateOf(false) }val rows = byApp.map { (name, ps) ->@@ -417,7 +585,7 @@ private fun LazyListScope.section(verticalAlignment = Alignment.CenterVertically,) {Text(title, style = MaterialTheme.typography.titleMedium, modifier = Modifier.weight(1f))- Text("$count", style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)+ if (count > 0) Text("$count", style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)Spacer(Modifier.width(8.dp))Icon(Icons.Default.KeyboardArrowDown, contentDescription = if (shown) "Collapse" else "Expand", Modifier.rotate(turn))}@@ -484,6 +652,9 @@ private fun AppRow(color = MaterialTheme.colorScheme.onSurfaceVariant,)}+ if (app.protectedReason != null) {+ Icon(Icons.Default.Lock, contentDescription = "Protected", Modifier.size(20.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant)+ }if (busy) androidx.compose.material3.LoadingIndicator(Modifier.size(32.dp))}val proposed = pending?.takeIf { it.first == app.packageName }?.second@@ -513,7 +684,7 @@ private fun AppRow(private fun ProcessTable(procs: List<Proc>, apps: List<AppInfo>, q: String) {val labels = apps.associate { it.packageName to it.label }val groups = procs- .groupBy { p -> p.packageName?.let { labels[it] ?: it } ?: Copy.ANDROID_SYSTEM }+ .groupBy { p -> p.packageName?.let { labels[it] ?: AppNames.fallback(it) } ?: Copy.ANDROID_SYSTEM }.filter { (name, ps) -> q.isEmpty() || name.lowercase().contains(q) || ps.any { it.name.lowercase().contains(q) } }.toList().sortedByDescending { (_, ps) -> ps.sumOf { it.cpuPercent } }@@ -549,9 +720,15 @@ private fun ProcessTable(procs: List<Proc>, apps: List<AppInfo>, q: String) {private fun NetworkBlock(n: NetworkInfo, q: String) {if (q.isEmpty()) {KeyValue("Connection", listOfNotNull(if (n.iface == "wifi") "Wi-Fi" else "Ethernet", n.ssid).joinToString(" · "))- KeyValue("IP", n.ip)- n.mac?.let { KeyValue("MAC", it) }- n.rssi?.let { r -> KeyValue("Signal", "$r dBm · ${signalWord(r)}" + (n.linkMbps?.let { " · $it Mbps" } ?: "")) }+ n.rssi?.let { r -> KeyValue("Signal", signalWord(r).replaceFirstChar(Char::uppercase)) }+ Details(+ listOfNotNull(+ "IP address" to n.ip,+ n.mac?.let { "MAC" to it },+ n.rssi?.let { "Signal" to "$it dBm" },+ n.linkMbps?.let { "Link speed" to "$it Mbps" },+ ),+ )Spacer(Modifier.height(8.dp))Text("Data used", style = MaterialTheme.typography.titleSmall)Bars(n.traffic.map { it.app to (it.rxMb + it.txMb).toDouble() }, fmt = { Copy.mb(it.toInt()) })@@ -575,14 +752,6 @@ private fun signalWord(rssi: Int) = when {else -> "very weak"}-@Composable-private fun KeyValue(k: String, v: String) {- Row(Modifier.padding(vertical = 2.dp)) {- Text(k, Modifier.width(96.dp), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)- Text(v, style = SmallNumber)- }-}-@Composableprivate fun HistoryList(history: List<HistoryEntry>,diff --git a/app/src/main/java/app/tellyscope/ui/ScanScreen.kt b/app/src/main/java/app/tellyscope/ui/ScanScreen.ktindex ee22c8f..1a82052 100644--- a/app/src/main/java/app/tellyscope/ui/ScanScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/ScanScreen.kt@@ -3,7 +3,9 @@package app.tellyscope.uiimport androidx.compose.animation.animateContentSize+import androidx.compose.foundation.borderimport androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.PaddingValuesimport androidx.compose.foundation.layout.Row@@ -15,6 +17,7 @@ import androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.lazy.LazyColumnimport androidx.compose.foundation.lazy.items+import androidx.compose.foundation.text.BasicTextFieldimport androidx.compose.foundation.text.KeyboardOptionsimport androidx.compose.material.icons.Iconsimport androidx.compose.material.icons.filled.Add@@ -159,10 +162,11 @@ private fun HitCard(Column(Modifier.weight(1f)) {Text(hit.hostname ?: hit.maker ?: "Android device", style = MaterialTheme.typography.titleMedium)Text(- listOfNotNull(hit.maker ?: "Unknown maker", hit.ip).joinToString(" · "),- style = SmallNumber,+ hit.maker ?: "Unknown maker",+ style = MaterialTheme.typography.bodyMedium,color = MaterialTheme.colorScheme.onSurfaceVariant,)+ Details(listOf("IP address" to hit.ip, "Port" to hit.port.toString()))}when (row) {RowState.Found -> FilledTonalButton(onClick = { onConnect(hit) }) { Text("Connect") }@@ -208,30 +212,60 @@ private fun HitCard("On the TV: Settings → Developer options → Wireless debugging → Pair device with pairing code. Type the 6 digits it shows:",style = MaterialTheme.typography.bodyMedium,)- Row(verticalAlignment = Alignment.CenterVertically) {- OutlinedTextField(- value = row.input,- onValueChange = { onCode(hit, it) },- modifier = Modifier.weight(1f),- singleLine = true,- enabled = !row.busy,- textStyle = StatNumber,- placeholder = { Text("000000", style = StatNumber) },- keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),- isError = row.error != null,+ CodeBoxes(row.input, onChange = { onCode(hit, it) }, enabled = !row.busy, isError = row.error != null)+ val missing = CODE_LENGTH - row.input.length+ // The button says what's missing instead of sitting there disabled with no reason.+ Button(onClick = { onPair(hit) }, enabled = !row.busy && missing == 0) {+ Text(+ when {+ row.busy -> "Pairing…"+ missing == 0 -> "Pair"+ missing == 1 -> "1 more digit"+ else -> "$missing more digits"+ },)- Spacer(Modifier.width(12.dp))- Button(onClick = { onPair(hit) }, enabled = !row.busy && row.input.length == 6) {- Text(if (row.busy) "Pairing…" else "Pair")- }}- row.error?.let { Text(it, color = MaterialTheme.colorScheme.error, style = MaterialTheme.typography.bodySmall) }+ row.error?.let { Text(it, color = MaterialTheme.colorScheme.error, style = MaterialTheme.typography.bodyMedium) }+ row.detail?.let { Details(listOf("From the TV" to it)) }}}}}}+private const val CODE_LENGTH = 6++/** One box per digit, on the number keypad. A single hidden field underneath, so paste and delete just work. */+@Composable+private fun CodeBoxes(code: String, onChange: (String) -> Unit, enabled: Boolean, isError: Boolean) {+ BasicTextField(+ value = code,+ onValueChange = onChange,+ enabled = enabled,+ singleLine = true,+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),+ decorationBox = { _ ->+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {+ repeat(CODE_LENGTH) { i ->+ val current = enabled && i == code.length+ val color = when {+ isError -> MaterialTheme.colorScheme.error+ current -> MaterialTheme.colorScheme.primary+ else -> MaterialTheme.colorScheme.outline+ }+ Box(+ Modifier.size(width = 44.dp, height = 56.dp)+ .border(if (current) 2.dp else 1.dp, color, MaterialTheme.shapes.medium),+ contentAlignment = Alignment.Center,+ ) {+ Text(code.getOrNull(i)?.toString().orEmpty(), style = StatNumber)+ }+ }+ }+ },+ )+}+@Composableprivate fun AddByIpDialog(subnet: String?, onDismiss: () -> Unit, onSubmit: (String) -> String?) {var text by remember { mutableStateOf("") }@@ -248,7 +282,7 @@ private fun AddByIpDialog(subnet: String?, onDismiss: () -> Unit, onSubmit: (Strvalue = text,onValueChange = { text = it; error = null },singleLine = true,- textStyle = StatNumber,+ textStyle = MaterialTheme.typography.titleLarge.copy(fontFeatureSettings = "tnum"),isError = error != null,supportingText = error?.let { { Text(it) } },keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri),diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.ktindex 847a0a9..852f0cb 100644--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt@@ -30,7 +30,8 @@ import kotlinx.coroutines.withTimeoutOrNullsealed interface RowState {data object Found : RowStatedata class Waiting(val since: Long) : RowState- data class Code(val input: String = "", val busy: Boolean = false, val error: String? = null) : RowState+ /** [error] is the plain sentence; [detail] is what the TV said, shown under Details. */+ data class Code(val input: String = "", val busy: Boolean = false, val error: String? = null, val detail: String? = null) : RowStatedata object NotAllowed : RowState}@@ -65,6 +66,9 @@ data class UiState(val selected: Device? get() = devices.firstOrNull { it.id == selectedId }}+private const val WRONG_CODE = "That code didn't work. Check the 6 digits on the TV and try again."+private const val UNREACHABLE = "The TV didn't answer. Check it's on and on the same Wi-Fi as this phone, then try again."+/** [DeviceUi.busy] value while "Restore everything" runs. */const val RESTORING = "restore"@@ -85,6 +89,9 @@ class TellyscopeViewModel(private val _notice = MutableStateFlow<String?>(null)val notice: StateFlow<String?> = _notice.asStateFlow()+ /** Last stats per TV, so an offline page shows where it stood instead of blanks. Lives as long as the app. */+ private val lastSnapshot = mutableMapOf<String, Snapshot>()+private var scanJob: Job? = nullprivate var liveJob: Job? = nullprivate var mediumJob: Job? = null@@ -155,12 +162,12 @@ class TellyscopeViewModel(fun pair(hit: ScanHit) {val row = _state.value.scan.rows[hit.ip] as? RowState.Code ?: return- setRow(hit.ip, row.copy(busy = true, error = null))+ setRow(hit.ip, row.copy(busy = true, error = null, detail = null))viewModelScope.launch {when (val r = source.pair(hit, row.input)) {is ConnectResult.Online -> online(r.device)- is ConnectResult.WrongCode -> setRow(hit.ip, row.copy(busy = false, error = r.message))- is ConnectResult.Unreachable -> setRow(hit.ip, row.copy(busy = false, error = r.message))+ is ConnectResult.WrongCode -> setRow(hit.ip, row.copy(busy = false, error = WRONG_CODE, detail = r.message))+ is ConnectResult.Unreachable -> setRow(hit.ip, row.copy(busy = false, error = UNREACHABLE, detail = r.message))ConnectResult.NotAllowed -> setRow(hit.ip, RowState.NotAllowed)ConnectResult.NeedsPairing -> setRow(hit.ip, row.copy(busy = false, error = "The TV still wants a code. Check the number on screen and try again."))}@@ -195,7 +202,7 @@ class TellyscopeViewModel(fun select(id: String?) {liveJob?.cancel()mediumJob?.cancel()- _state.update { it.copy(selectedId = id, device = DeviceUi(), query = "") }+ _state.update { it.copy(selectedId = id, device = DeviceUi(snapshot = id?.let(lastSnapshot::get)), query = "") }val device = _state.value.selected ?: return// History lives on the phone, so it shows (and undo is offered) even while the TV is off.viewModelScope.launch {@@ -204,7 +211,10 @@ class TellyscopeViewModel(}if (device.state != DeviceState.Online) returnliveJob = viewModelScope.launch {- source.live(id!!).collect { snap -> _state.update { it.copy(device = it.device.copy(snapshot = snap)) } }+ source.live(id!!).collect { snap ->+ lastSnapshot[id] = snap+ _state.update { it.copy(device = it.device.copy(snapshot = snap)) }+ }}mediumJob = viewModelScope.launch {// A TV that drops mid-read throws; the live flow ends and the offline card takes over.@@ -241,6 +251,13 @@ class TellyscopeViewModel(}}+ fun rename(id: String, name: String?) {+ viewModelScope.launch {+ source.rename(id, name)+ _state.update { it.copy(devices = source.known()) }+ }+ }+fun forget(id: String) {viewModelScope.launch {source.forget(id)diff --git a/app/src/main/java/app/tellyscope/ui/theme/Theme.kt b/app/src/main/java/app/tellyscope/ui/theme/Theme.ktindex 754b51c..f583810 100644--- a/app/src/main/java/app/tellyscope/ui/theme/Theme.kt+++ b/app/src/main/java/app/tellyscope/ui/theme/Theme.kt@@ -16,7 +16,6 @@ import androidx.compose.runtime.Composableimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.text.TextStyle-import androidx.compose.ui.text.font.FontFamilyimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.unit.sp@@ -58,9 +57,9 @@ private val DarkBrand = darkColorScheme(surfaceContainerHigh = Color(0xFF252B2B),)-/** Numbers come first: stats use a tabular monospace so values don't jitter as they update. */-val StatNumber = TextStyle(fontFamily = FontFamily.Monospace, fontWeight = FontWeight.Medium, fontSize = 20.sp, lineHeight = 26.sp)-val SmallNumber = TextStyle(fontFamily = FontFamily.Monospace, fontSize = 13.sp, lineHeight = 18.sp)+/** Numbers come first: the app font with tabular figures, so values line up and don't jitter as they update. */+val StatNumber = TextStyle(fontWeight = FontWeight.Medium, fontSize = 28.sp, lineHeight = 34.sp, fontFeatureSettings = "tnum")+val SmallNumber = TextStyle(fontSize = 13.sp, lineHeight = 18.sp, fontFeatureSettings = "tnum")@OptIn(ExperimentalMaterial3ExpressiveApi::class)@Composablediff --git a/app/src/test/java/app/tellyscope/AppNamesTest.kt b/app/src/test/java/app/tellyscope/AppNamesTest.ktindex 8f4d709..2939042 100644--- a/app/src/test/java/app/tellyscope/AppNamesTest.kt+++ b/app/src/test/java/app/tellyscope/AppNamesTest.kt@@ -39,12 +39,18 @@ class AppNamesTest {assertArrayEquals(icon, names.getValue("com.netflix.ninja").icon)}+ @Test fun fallbackKeepsTheMaker() {+ assertEquals("XGIMI Assistant", AppNames.fallback("com.xgimi.assistant"))+ assertEquals("Youtube", AppNames.fallback("com.google.android.youtube"))+ assertEquals("Spotifytv", AppNames.fallback("com.spotify.spotifytv")) // maker already in the name+ }+@Test fun fallbackWhenTheHelperFails() = runBlocking {val helper = Helper(fail = true)val appNames = AppNames(tmp.root)val names = appNames.names("SN1", listOf(netflix, odd), helper::describe)assertEquals("Netflix", names.getValue("com.netflix.ninja").label) // bundled table- assertEquals("Weatherbox", names.getValue("com.example.weatherbox").label) // humanised id+ assertEquals("Example Weatherbox", names.getValue("com.example.weatherbox").label) // humanised id, maker keptassertNull(names.getValue("com.netflix.ninja").icon) // letter avatar// A refusal isn't retried on every open; the next app start tries again.appNames.names("SN1", listOf(netflix, odd), helper::describe)diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.ktindex 59a2cb8..6efd382 100644--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt@@ -10,7 +10,6 @@ import androidx.compose.ui.test.junit4.v2.createComposeRuleimport androidx.compose.ui.test.onNodeWithTextimport androidx.compose.ui.test.onRootimport androidx.compose.ui.test.performClick-import androidx.compose.ui.test.performScrollToimport app.tellyscope.data.Actionimport app.tellyscope.data.AppInfoimport app.tellyscope.data.AppNames@@ -32,7 +31,9 @@ import app.tellyscope.ui.ScanScreenimport app.tellyscope.ui.ScanUiimport app.tellyscope.ui.UiStateimport app.tellyscope.ui.theme.TellyscopeTheme+import com.github.takahirom.roborazzi.ExperimentalRoborazziApiimport com.github.takahirom.roborazzi.captureRoboImage+import com.github.takahirom.roborazzi.captureScreenRoboImageimport java.io.ByteArrayOutputStreamimport kotlin.random.Randomimport kotlinx.coroutines.runBlocking@@ -63,7 +64,13 @@ class ScreenshotTest {private val chromecast = ScanHit("192.168.1.57", 37211, ScanKind.Wireless, "chromecast", "Google")private val unknown = ScanHit("192.168.1.88", 5555, ScanKind.Classic, null, null)- private fun shot(name: String, dark: Boolean = false, before: () -> Unit = {}, content: @Composable () -> Unit) {+ /**+ * [screen] captures every window, so a dialog shows over its scrim. Robolectric doesn't apply+ * the platform dialog width, so dialogs still render edge to edge here; on a phone the+ * default `DialogProperties` give them the usual margins.+ */+ @OptIn(ExperimentalRoborazziApi::class)+ private fun shot(name: String, dark: Boolean = false, screen: Boolean = false, before: () -> Unit = {}, content: @Composable () -> Unit) {// Expressive indicators animate forever, so the clock never idles on its own:// drive it by hand and capture a fixed frame.compose.mainClock.autoAdvance = false@@ -71,7 +78,8 @@ class ScreenshotTest {compose.mainClock.advanceTimeBy(1_000)before()compose.mainClock.advanceTimeBy(1_000)- compose.onRoot().captureRoboImage("build/outputs/roborazzi/${name}${if (dark) "_dark" else ""}.png")+ val path = "build/outputs/roborazzi/${name}${if (dark) "_dark" else ""}.png"+ if (screen) captureScreenRoboImage(path) else compose.onRoot().captureRoboImage(path)}private fun scan(ui: ScanUi, dark: Boolean = false, name: String) = shot(name, dark) {@@ -135,12 +143,20 @@ class ScreenshotTest {@Test fun device_offline() {val base = deviceState()val off = base.devices.last()+ // The last stats this phone saw, 14 minutes before it went away.+ val last = fake.snapshot(off.id).copy(at = now - 14 * 60_000)shot("06_device_offline") {- DeviceScreen(base.copy(selectedId = off.id, device = DeviceUi(), showOffline = true), DeviceActions())+ DeviceScreen(base.copy(selectedId = off.id, device = DeviceUi(snapshot = last), showOffline = true), DeviceActions())}}- @Config(qualifiers = "w411dp-h1500dp-xxhdpi")+ @Test fun device_storageFull() {+ val state = deviceState { copy(snapshot = snapshot?.copy(storageUsedGb = 29.1, storageTotalGb = 32.0)) }+ shot("13_device_storage_full") { DeviceScreen(state, DeviceActions()) }+ }++ // Tall enough that History is composed without scrolling: the lazy list never lays it out otherwise.+ @Config(qualifiers = "w411dp-h2600dp-xxhdpi")@Test fun device_history() {val history = listOf(HistoryEntry(2, xgimi.ip, now - 40_000, Action.Disable, "com.xgimi.ota", "XGIMI Updates", Action.Enable, null),@@ -148,7 +164,7 @@ class ScreenshotTest {)val openHistory = {compose.onNodeWithText("Apps").performClick() // fold the long list away- compose.onNodeWithText("History").performScrollTo().performClick()+ compose.onNodeWithText("History").performClick()Unit}shot("07_device_history", before = openHistory) { DeviceScreen(deviceState { copy(history = history) }, DeviceActions()) }@@ -197,7 +213,7 @@ class ScreenshotTest {@Test fun permission_denied() = shot("08_permission_denied") { PermissionScreen(denied = true, canAsk = true, {}, {}) }- @Test fun forget() = shot("09_forget") { ForgetDialog("xgimi-projector", {}, {}) }+ @Test fun forget() = shot("09_forget", screen = true) { ForgetDialog("xgimi-projector", {}, {}) }@Test fun scan_offWifi() = scan(ScanUi(scanning = false, noLan = true, hits = listOf(chromecast), rows = mapOf(chromecast.ip to RowState.Found)),@@ -212,5 +228,5 @@ class ScreenshotTest {}}- @Test fun restore() = shot("11_restore") { RestoreDialog(2, {}, {}) }+ @Test fun restore() = shot("11_restore", screen = true) { RestoreDialog(2, {}, {}) }}