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.

List each package once, even when pm prints it twice

jesse-agent-36264630c8ac214
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Parsers.kt b/adb/src/main/kotlin/app/tellyscope/adb/Parsers.kt
index c2c3f67..74a4539 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Parsers.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Parsers.kt
@@ -73,7 +73,8 @@ object Parsers {
/**
* `pm list packages [--show-versioncode] [-U]`: `package:com.foo versionCode:42 uid:10023`
- * (uid list may be comma-separated).
+ * (uid list may be comma-separated). Each package once: some TVs print one twice, and the
+ * app list is keyed on the name.
*/
fun packages(pmList: String): List<Package> = pmList.lineSequence().mapNotNull { line ->
val l = line.trim()
@@ -82,7 +83,7 @@ object Parsers {
val uid = l.substringAfter(" uid:", "").substringBefore(',').toIntOrNull()
val version = l.substringAfter(" versionCode:", "").substringBefore(' ').toLongOrNull()
Package(name, uid, version).takeIf { name.isNotEmpty() }
- }.toList()
+ }.distinctBy { it.name }.toList()
/** [cpuPercent] is null from [psProcesses], which reads memory only. */
data class Process(val pid: Int, val user: String, val rssKb: Long, val cpuPercent: Double?, val name: String)
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/ParsersTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ParsersTest.kt
index 70d7ba0..eff3170 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/ParsersTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/ParsersTest.kt
@@ -49,6 +49,20 @@ class ParsersTest {
)
}
+ @Test fun packageListedTwiceComesOnce() {
+ // A TCL Android TV 11 prints play.games twice; the Apps list crashed on the repeated key (#107).
+ val out = "package:com.google.android.play.games versionCode:7 uid:10090\n" +
+ "package:com.android.vending versionCode:9 uid:10040\n" +
+ "package:com.google.android.play.games versionCode:7 uid:10090\n"
+ assertEquals(
+ listOf(
+ Parsers.Package("com.google.android.play.games", 10090, 7),
+ Parsers.Package("com.android.vending", 10040, 9),
+ ),
+ Parsers.packages(out),
+ )
+ }
+
@Test fun processesSkipHeaders() {
val top = """
Tasks: 210 total, 1 running, 209 sleeping