Skip to content

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: per-state copy, brand tile width, GB decimals, tests

jesse-agent-232fd274c8ba8ba
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index a5af40b..110d14f 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -84,6 +84,18 @@ object Copy {
DeviceState.Found -> "Not connected"
}
+ /** Under 10 GB a whole number hides too much: a 1.5 GB TV isn't a 2 GB one. */
+ fun gbOf(used: Double, total: Double) =
+ if (total < 10) "%.1f of %.1f GB".format(used, total) else "%.1f of %.0f GB".format(used, total)
+
+ /** An offline TV that has never sent stats; a refusing TV is on, it just hasn't allowed us. */
+ fun noStats(s: DeviceState) =
+ if (s == DeviceState.NotAllowed) "Stats show up once the TV allows this phone."
+ else "No stats yet. They show up once the TV is back on."
+
+ const val WRONG_CODE = "That code didn't work. Check the 6 digits on the TV and try again."
+ const val UNREACHABLE = "The TV didn't answer. Check it's on and on the same Wi-Fi as this phone, then try again."
+
data class Health(val ok: Boolean, val text: String)
/**
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
index 96e304f..e0ea420 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
@@ -22,6 +22,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.shape.CircleShape
@@ -187,7 +188,7 @@ fun DeviceScreen(
} else if (offline) {
item {
Text(
- "No stats yet. They show up once the TV is back on.",
+ Copy.noStats(device.state),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
@@ -345,8 +346,8 @@ fun RenameDialog(current: String, networkName: String, onSave: (String) -> Unit,
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),
+ Modifier.padding(end = 10.dp).widthIn(min = 52.dp).height(36.dp).clip(MaterialTheme.shapes.medium)
+ .background(MaterialTheme.colorScheme.secondaryContainer).padding(horizontal = 8.dp),
contentAlignment = Alignment.Center,
) {
Text(maker, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSecondaryContainer, maxLines = 1)
@@ -512,7 +513,7 @@ private fun Meter(label: String, usedGb: Double, totalGb: Double) {
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)
+ Text(Copy.gbOf(usedGb, totalGb), style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
LinearProgressIndicator(
progress = { frac },
diff --git a/app/src/main/java/app/tellyscope/ui/ScanScreen.kt b/app/src/main/java/app/tellyscope/ui/ScanScreen.kt
index 1a82052..c00c0a5 100644
--- a/app/src/main/java/app/tellyscope/ui/ScanScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/ScanScreen.kt
@@ -47,6 +47,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import app.tellyscope.data.ScanHit
@@ -241,6 +243,7 @@ private fun CodeBoxes(code: String, onChange: (String) -> Unit, enabled: Boolean
BasicTextField(
value = code,
onValueChange = onChange,
+ modifier = Modifier.semantics { contentDescription = "Pairing code" },
enabled = enabled,
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 852f0cb..77e4a01 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -66,9 +66,6 @@ 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"
@@ -166,8 +163,8 @@ class TellyscopeViewModel(
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 = WRONG_CODE, detail = r.message))
- is ConnectResult.Unreachable -> setRow(hit.ip, row.copy(busy = false, error = UNREACHABLE, detail = r.message))
+ is ConnectResult.WrongCode -> setRow(hit.ip, row.copy(busy = false, error = Copy.WRONG_CODE, detail = r.message))
+ is ConnectResult.Unreachable -> setRow(hit.ip, row.copy(busy = false, error = Copy.UNREACHABLE, detail = r.message))
ConnectResult.NotAllowed -> setRow(hit.ip, RowState.NotAllowed)
ConnectResult.NeedsPairing -> setRow(hit.ip, row.copy(busy = false, error = "The TV still wants a code. Check the number on screen and try again."))
}
diff --git a/app/src/test/java/app/tellyscope/HealthTest.kt b/app/src/test/java/app/tellyscope/HealthTest.kt
new file mode 100644
index 0000000..c50a86d
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/HealthTest.kt
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import app.tellyscope.data.Snapshot
+import app.tellyscope.ui.Copy
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class HealthTest {
+ private fun snap(ram: Double = 0.5, storage: Double? = 0.5, temp: Int? = 50) = Snapshot(
+ at = 0, cpuPercent = 10,
+ ramUsedMb = (ram * 1000).toInt(), ramTotalMb = 1000,
+ storageUsedGb = storage?.let { it * 10 }, storageTotalGb = storage?.let { 10.0 },
+ tempC = temp, uptimeSeconds = 60, screenOn = true, procs = emptyList(),
+ )
+
+ @Test fun fine() = assertEquals(Copy.Health(true, "Running fine"), Copy.health(snap(), listOf("YouTube")))
+
+ @Test fun storageBeforeMemoryBeforeHeat() {
+ assertEquals("Storage almost full", Copy.health(snap(ram = 0.95, storage = 0.95, temp = 90), emptyList()).text)
+ assertEquals("Memory almost full", Copy.health(snap(ram = 0.95, temp = 90), emptyList()).text)
+ assertEquals("Running hot", Copy.health(snap(temp = 90), emptyList()).text)
+ }
+
+ @Test fun thresholdIsNinetyPercent() {
+ assertEquals(true, Copy.health(snap(ram = 0.89, storage = 0.89), emptyList()).ok)
+ assertEquals(false, Copy.health(snap(storage = 0.9), emptyList()).ok)
+ assertEquals(false, Copy.health(snap(ram = 0.9), emptyList()).ok)
+ }
+
+ @Test fun namesTheHeaviestOnlyWhenKnown() {
+ assertEquals(
+ "Memory almost full: YouTube and Netflix use the most",
+ Copy.health(snap(ram = 0.95), listOf("YouTube", "Netflix", "Kodi")).text,
+ )
+ assertEquals("Memory almost full", Copy.health(snap(ram = 0.95), emptyList()).text)
+ }
+
+ @Test fun missingStatsAreNotProblems() {
+ assertEquals(true, Copy.health(snap(storage = null, temp = null), emptyList()).ok)
+ }
+}
diff --git a/app/src/test/java/app/tellyscope/NameBookTest.kt b/app/src/test/java/app/tellyscope/NameBookTest.kt
new file mode 100644
index 0000000..bd62add
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/NameBookTest.kt
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import app.tellyscope.data.NameBook
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TemporaryFolder
+
+class NameBookTest {
+ @get:Rule val tmp = TemporaryFolder()
+
+ @Test fun survivesARestart() {
+ val file = tmp.root.resolve("names.tsv")
+ NameBook(file).set("sn:ABC", "Living room")
+ assertEquals("Living room", NameBook(file)["sn:ABC"])
+ }
+
+ @Test fun blankClearsTheName() {
+ val file = tmp.root.resolve("names.tsv")
+ val book = NameBook(file)
+ book.set("sn:ABC", "Living room")
+ book.set("sn:ABC", " ")
+ assertNull(book["sn:ABC"])
+ assertNull(NameBook(file)["sn:ABC"])
+ }
+
+ @Test fun tabsAndNewlinesCannotBreakTheFile() {
+ val file = tmp.root.resolve("names.tsv")
+ NameBook(file).set("sn:ABC", "Living\troom\nTV")
+ assertEquals("Living room TV", NameBook(file)["sn:ABC"])
+ }
+
+ @Test fun longNamesAreCapped() {
+ val book = NameBook()
+ book.set("sn:ABC", "x".repeat(100))
+ assertEquals(NameBook.MAX_LENGTH, book["sn:ABC"]!!.length)
+ }
+
+ @Test fun rekeyMovesTheName() {
+ val file = tmp.root.resolve("names.tsv")
+ NameBook(file).rekey("192.168.1.23", "sn:ABC") // nothing to move
+ val book = NameBook(file)
+ book.set("192.168.1.23", "Projector")
+ book.rekey("192.168.1.23", "sn:ABC")
+ assertEquals("Projector", NameBook(file)["sn:ABC"])
+ assertNull(book["192.168.1.23"])
+ }
+
+ @Test fun rekeyKeepsTheExistingName() {
+ // The TV was named under its real key before; a name typed while it read as an address loses.
+ val book = NameBook()
+ book.set("sn:ABC", "Bedroom")
+ book.set("192.168.1.23", "Projector")
+ book.rekey("192.168.1.23", "sn:ABC")
+ assertEquals("Bedroom", book["sn:ABC"])
+ }
+}