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.
Match the model by whole words, and the maker by brand too
jesse-agent-232f051c98756a3
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex 79a7566..ebe0dbb 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -41,7 +41,9 @@ import kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.Jobimport kotlinx.coroutines.SupervisorJobimport kotlinx.coroutines.async+import kotlinx.coroutines.awaitAllimport kotlinx.coroutines.channels.awaitClose+import kotlinx.coroutines.coroutineScopeimport kotlinx.coroutines.flow.Flowimport kotlinx.coroutines.flow.callbackFlowimport kotlinx.coroutines.flow.combine@@ -489,8 +491,9 @@ class AdbDeviceSource(context: Context) : DeviceSource {val match = lists.find(index, key, props)val list = when (match) {is ListMatch.Model -> lists.list(match.entry)- // A list that fails its checksum is left out; the rest still count.- is ListMatch.Maker -> match.entries.mapNotNull { lists.list(it) }.ifEmpty { null }?.let { merge(match.maker, it) }+ // Fetched together, as a maker can have dozens. A list that fails its checksum is left out; the rest still count.+ is ListMatch.Maker -> coroutineScope { match.entries.map { async { lists.list(it) } }.awaitAll() }+ .filterNotNull().ifEmpty { null }?.let { merge(match.maker, it) }ListMatch.None -> null}keep[key] = list?.keep.orEmpty()diff --git a/app/src/main/java/app/tellyscope/data/DeviceLists.kt b/app/src/main/java/app/tellyscope/data/DeviceLists.ktindex b86c482..5c129c4 100644--- a/app/src/main/java/app/tellyscope/data/DeviceLists.kt+++ b/app/src/main/java/app/tellyscope/data/DeviceLists.kt@@ -53,22 +53,30 @@ sealed interface ListMatch {data object None : ListMatch}+/** True when [model], squashed, is a run of whole consecutive [words]: "MoGo 2" fits "XGIMI MoGo 2", "X10" doesn't fit "TCL X100". */+private fun wordsFit(model: String, words: List<String>): Boolean = words.indices.any { i ->+ var run = ""+ words.drop(i).any { w -> run += squash(w); run == model }+}++/** The TV's maker names: `ro.product.manufacturer`, then `ro.product.brand`, which can differ. */+private fun tvMakers(props: Map<String, String?>) = listOf("manufacturer", "brand").mapNotNull { squash(props[it].orEmpty()).ifEmpty { null } }.distinct()+/**- * The one list whose name or id contains the TV's model, letters and digits only. Null when none- * or several do, or when that list's maker isn't the TV's manufacturer: a wrong list is worse+ * The one list whose name (by words) or id (by `-` parts) holds the TV's model as whole words.+ * Null when none or several do, or when that list's maker isn't the TV's: a wrong list is worse* than the maker's lists, which start unticked.*/fun byModel(devices: List<ListEntry>, props: Map<String, String?>): ListEntry? {val model = squash(props["model"].orEmpty()).takeIf { it.length >= 3 } ?: return null- val fit = devices.filter { model in squash(it.name) || model in squash(it.id) }.singleOrNull() ?: return null- return fit.takeIf { squash(listMakers(devices).getValue(it.id)) == squash(props["manufacturer"].orEmpty()) }+ val fit = devices.filter { wordsFit(model, it.name.split(' ')) || wordsFit(model, it.id.split('-')) }.singleOrNull() ?: return null+ return fit.takeIf { squash(listMakers(devices).getValue(it.id)) in tvMakers(props) }}-/** Every list from the TV's manufacturer, by [listMakers]. */+/** Every list from the TV's maker, by [listMakers]: its manufacturer's, else its brand's. */fun byMaker(devices: List<ListEntry>, props: Map<String, String?>): List<ListEntry> {- val maker = squash(props["manufacturer"].orEmpty()).ifEmpty { return emptyList() }val makers = listMakers(devices)- return devices.filter { squash(makers.getValue(it.id)) == maker }+ return tvMakers(props).firstNotNullOfOrNull { m -> devices.filter { squash(makers.getValue(it.id)) == m }.ifEmpty { null } }.orEmpty()}/**@@ -136,8 +144,8 @@ private val FILE = Regex("devices/[A-Za-z0-9][A-Za-z0-9._-]*\\.json")private val SHA256 = Regex("[0-9a-f]{64}")private const val SCHEMA = 1-/** The props a match rule may name, read from `ro.product.*`. */-val MATCH_KEYS = listOf("manufacturer", "model", "device")+/** The props a match rule may name, read from `ro.product.*`; brand also finds the maker's lists. */+val MATCH_KEYS = listOf("manufacturer", "model", "device", "brand")/** A rule matches when every key in it equals one of its values, ignoring case. An empty rule never does. */fun matches(rule: Map<String, List<String>>?, props: Map<String, String?>): Boolean =diff --git a/app/src/test/java/app/tellyscope/DeviceListsTest.kt b/app/src/test/java/app/tellyscope/DeviceListsTest.ktindex a85f821..b29c61d 100644--- a/app/src/test/java/app/tellyscope/DeviceListsTest.kt+++ b/app/src/test/java/app/tellyscope/DeviceListsTest.kt@@ -128,11 +128,12 @@ class DeviceListsTest {entry("xgimi-horizon", "XGIMI Horizon"),entry("tcl-p7-2021", "TCL P7 2021"),entry("tcl-p7-2023", "TCL P7 2023"),+ entry("tcl-x100", "TCL X100"),),)- private fun find(manufacturer: String, model: String) =- DeviceLists(tmp.root).find(fakes, "sn:x", mapOf("manufacturer" to manufacturer, "model" to model))+ private fun find(manufacturer: String, model: String, brand: String? = null) =+ DeviceLists(tmp.root).find(fakes, "sn:x", mapOf("manufacturer" to manufacturer, "model" to model, "brand" to brand))@Test fun oneListNamedAfterTheModelIsTheTvsList() {// Case, spaces and dashes don't count.@@ -142,7 +143,19 @@ class DeviceListsTest {@Test fun twoListsForTheModelFallBackToTheMaker() {val m = find("TCL", "P7") as ListMatch.MakerassertEquals("TCL", m.maker)- assertEquals(listOf("tcl-p7-2021", "tcl-p7-2023"), m.entries.map { it.id })+ assertEquals(listOf("tcl-p7-2021", "tcl-p7-2023", "tcl-x100"), m.entries.map { it.id })+ }++ @Test fun theModelMustBeWholeWordsNotPartOfOne() {+ // "X10" is not "X100": the maker's lists, unticked, instead of the wrong model's.+ assertTrue(find("TCL", "X10") is ListMatch.Maker)+ assertEquals(ListMatch.Model(fakes.devices[4]), find("TCL", "X100"))+ }++ @Test fun theBrandFindsTheMakerWhenTheManufacturerDoesnt() {+ // Like a Philips TV, which reports its factory, TPV, as manufacturer.+ assertEquals(ListMatch.Model(fakes.devices[0]), find("Zeta", "MoGo 2", brand = "XGIMI"))+ assertEquals(2, (find("Zeta", "Halo+", brand = "XGIMI") as ListMatch.Maker).entries.size)}@Test fun aModelWithNoListGetsEveryListFromItsMaker() {