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.

Advanced: graphs by time; Wi-Fi read only on Advanced

jesse-agent-232b5f7ca803f44
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt b/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt
index d835cf9..6349688 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Commands.kt
@@ -29,7 +29,7 @@ internal object Commands {
).batch()
/**
- * Every 10 s on Advanced: the TV's address and hardware address, then its Wi-Fi. `cmd wifi`
+ * Every 10 s while Advanced is open (once per TV elsewhere): the TV's address and hardware address, then its Wi-Fi. `cmd wifi`
* came in Android 11; older TVs print the same facts on `dumpsys wifi`'s `mWifiInfo` line.
*/
val ADDRESS = listOf(
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
index c1f2b6b..58a237f 100644
--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
@@ -484,9 +484,13 @@ class AdbDeviceSource(
}.sortedBy { it.label.lowercase() }
}
+ /** The last address and Wi-Fi read per TV: re-read only while Advanced shows it, since old TVs answer with all of `dumpsys wifi`. */
+ private val addresses = ConcurrentHashMap<String, Pair<Parsers.Address?, Parsers.Wifi?>>()
+
override suspend fun network(deviceId: String): NetworkInfo {
val shell = session(deviceId)
- val (address, wifi) = NetworkStats(shell).address()
+ val cached = addresses[deviceId]?.takeIf { statsFor != (deviceId to StatsProfile.ADVANCED) }
+ val (address, wifi) = cached ?: NetworkStats(shell).address().also { addresses[deviceId] = it }
val packages = links[deviceId]?.stats?.value?.packages.orEmpty()
return NetworkInfo(
iface = address?.iface.orEmpty(),
diff --git a/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt b/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt
index d6d942c..f4a7f20 100644
--- a/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/AdvancedScreen.kt
@@ -277,7 +277,7 @@ private fun Stats(s: Snapshot, recent: List<Snapshot>, staleSince: Long?, rows:
)
}
Speeds(s, MaterialTheme.typography.titleSmall)
- Graph(recent.map { it.rxBytesPerSec?.toFloat() ?: 0f }, recent.map { it.txBytesPerSec?.toFloat() ?: 0f })
+ Graph(recent.map { it.at }, recent.map { it.rxBytesPerSec?.toFloat() ?: 0f }, recent.map { it.txBytesPerSec?.toFloat() ?: 0f })
// The busiest apps only when the CPU is busy enough for them to matter.
val busiest = rows.filter { it.cpu >= 1 }.sortedByDescending { it.cpu }.take(3).takeIf { s.cpuPercent > 33 }.orEmpty()
if (busiest.isNotEmpty()) {
@@ -495,7 +495,7 @@ private fun CpuCard(s: Snapshot, recent: List<Snapshot>, staleSince: Long?) {
}
}
}
- Graph(recent.map { it.cpuPercent.toFloat() }, max = 100f)
+ Graph(recent.map { it.at }, recent.map { it.cpuPercent.toFloat() }, max = 100f)
s.cores.chunked(2).forEachIndexed { row, pair ->
Row(horizontalArrangement = Arrangement.spacedBy(24.dp)) {
pair.forEachIndexed { i, pct ->
@@ -524,7 +524,7 @@ private fun RamCard(s: Snapshot, recent: List<Snapshot>, staleSince: Long?) {
Text(stringResource(R.string.advanced_percent, s.ramUsedMb * 100 / total), style = MaterialTheme.typography.headlineMedium.copy(fontFeatureSettings = "tnum"))
Text(Copy.gbOf(s.ramUsedMb / 1024.0, s.ramTotalMb / 1024.0).resolve(), style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant)
}
- Graph(recent.map { it.ramUsedMb * 100f / it.ramTotalMb.coerceAtLeast(1) }, max = 100f)
+ Graph(recent.map { it.at }, recent.map { it.ramUsedMb * 100f / it.ramTotalMb.coerceAtLeast(1) }, max = 100f)
// In use, then cache the TV gives back when asked, then memory holding nothing.
val parts = listOf(
Triple(R.string.advanced_in_use, s.ramUsedMb, c.primary),
@@ -574,7 +574,7 @@ private fun NetworkCard(s: Snapshot, recent: List<Snapshot>, staleSince: Long?,
else -> null
}?.let { Text(it, style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant) }
}
- Graph(recent.map { it.rxBytesPerSec?.toFloat() ?: 0f }, recent.map { it.txBytesPerSec?.toFloat() ?: 0f })
+ Graph(recent.map { it.at }, recent.map { it.rxBytesPerSec?.toFloat() ?: 0f }, recent.map { it.txBytesPerSec?.toFloat() ?: 0f })
val rx = s.rxTotalBytes
val tx = s.txTotalBytes
if (rx != null && tx != null) {
@@ -591,10 +591,11 @@ private fun NetworkCard(s: Snapshot, recent: List<Snapshot>, staleSince: Long?,
/**
* The last minute: [area] filled, [line] drawn over it, against [max] or the highest reading.
- * Readings fill from the right, so a graph that just started grows out of "now".
+ * Each reading sits at its time in [at], the newest at "now", so a graph that just started grows
+ * out of the right edge and readings taken further apart sit further apart.
*/
@Composable
-private fun Graph(area: List<Float>, line: List<Float>? = null, max: Float? = null) {
+private fun Graph(at: List<Long>, area: List<Float>, line: List<Float>? = null, max: Float? = null) {
val c = MaterialTheme.colorScheme
val fill = c.primary.copy(alpha = 0.25f)
val edge = c.primary
@@ -602,8 +603,9 @@ private fun Graph(area: List<Float>, line: List<Float>? = null, max: Float? = nu
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
Canvas(Modifier.fillMaxWidth().height(56.dp)) {
val top = max ?: ((area + line.orEmpty()).maxOrNull()?.takeIf { it > 0f } ?: 1f)
+ val now = at.lastOrNull() ?: 0L
fun points(v: List<Float>) = v.mapIndexed { i, y ->
- Offset(size.width * (RECENT_READINGS - v.size + i) / (RECENT_READINGS - 1), size.height * (1f - (y / top).coerceIn(0f, 1f)))
+ Offset(size.width * (1f - (now - at[i]).toFloat() / RECENT_MS), size.height * (1f - (y / top).coerceIn(0f, 1f)))
}
val a = points(area)
if (a.size >= 2) {
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 47e705f..4856ca5 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -112,8 +112,8 @@ data class ScanUi(
val offWifi get() = noLan && hits.isEmpty()
}
-/** Readings in [DeviceUi.recent] and across Advanced's graphs: a minute at one every 2 s. */
-const val RECENT_READINGS = 30
+/** How far back [DeviceUi.recent] and Advanced's graphs reach, by [Snapshot.at]. */
+const val RECENT_MS = 60_000L
data class DeviceUi(
val snapshot: Snapshot? = null,
@@ -773,7 +773,7 @@ class TellyscopeViewModel(
liveJob = viewModelScope.launch {
source.live(id).collect { snap ->
lastSnapshot[id] = snap
- _state.update { it.copy(device = it.device.copy(snapshot = snap, recent = (it.device.recent + snap).takeLast(RECENT_READINGS))) }
+ _state.update { it.copy(device = it.device.copy(snapshot = snap, recent = (it.device.recent + snap).filter { r -> snap.at - r.at <= RECENT_MS })) }
}
}
// One read of the app list per open: Apps and the TV's list both use it. The list