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.

Show a USB camera as a camera, its name said once

jesse-agent-232d2f1bc228382
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b10adfe..e954adb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ until this file has a section for its version.
## Unreleased
+- **Improved:** A USB camera shows a camera icon and its name once, under Input.
- **Improved:** On Fire TV, the Remote's Home opens your default launcher. [#153](../../pull/153)
- **New:** Install a recommended home screen from the TV's Play Store, then switch to it. [#152](../../pull/152)
- **Improved:** Setting a launcher as default asks separately before turning on its accessibility service, and the TV's page offers to turn it on later.
diff --git a/NOTICE b/NOTICE
index 9cb238e..31a65f2 100644
--- a/NOTICE
+++ b/NOTICE
@@ -35,7 +35,7 @@ The access warning, Who has access and Remove all other access use those
of "shield", "gpp_good", "gpp_maybe", "lock_reset", "smartphone", "lan",
"laptop", "desktop_windows" and "help_outline"; the Connected devices card
those of "bluetooth", "headphones", "keyboard", "mouse", "sports_esports",
-"usb", "speaker" and "settings_input_hdmi". The logged-out page and the
+"usb", "speaker", "settings_input_hdmi" and "videocam". The logged-out page and the
logged-out badge on a TV's chip use that of "logout"; the dialog that asks
about a launcher's accessibility service that of "accessibility_new".
The install-a-launcher flow uses those of "download", "error_outline",
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Peripherals.kt b/adb/src/main/kotlin/app/tellyscope/adb/Peripherals.kt
index bdea2d4..caf95ac 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Peripherals.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Peripherals.kt
@@ -14,7 +14,7 @@ data class Peripheral(
val free: Long? = null,
) {
enum class Group { Bluetooth, Input, Storage, Hdmi, Audio }
- enum class Kind { Remote, Headphones, Speaker, Keyboard, Mouse, Controller, Bluetooth, Usb, Hdmi, Sound }
+ enum class Kind { Remote, Headphones, Speaker, Keyboard, Mouse, Controller, Bluetooth, Usb, Hdmi, Sound, Camera }
}
/**
@@ -99,7 +99,26 @@ class Peripherals(private val shell: AdbShell) {
}.groupBy { it.first }.map { (n, rows) ->
// One remote shows up as several devices; the strongest kind wins.
val best = rows.maxBy { it.second.ordinal }
- Peripheral(n, Peripheral.Group.Input, best.second.kind, true, best.third)
+ val shown = once(n)
+ Peripheral(shown, Peripheral.Group.Input, if (CAMERA.containsMatchIn(shown)) Peripheral.Kind.Camera else best.second.kind, true, best.third)
+ }.distinctBy { it.name }
+ }
+
+ /** A USB camera's button: an input device named after the camera, not a remote. */
+ private val CAMERA = Regex("\\b(camera|webcam)\\b", RegexOption.IGNORE_CASE)
+
+ /**
+ * Linux names a UVC camera's input device "<product>: <name>", cut short: "icspring
+ * camera: icspring camer". When one half starts the other, the name is said once.
+ */
+ fun once(name: String): String {
+ val a = name.substringBefore(": ", "").trim()
+ val b = name.substringAfter(": ", "").trim()
+ return when {
+ a.isEmpty() || b.isEmpty() -> name
+ a.startsWith(b) -> a
+ b.startsWith(a) -> b
+ else -> name
}
}
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/PeripheralsTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/PeripheralsTest.kt
index 47f8db2..d8f4d8e 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/PeripheralsTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/PeripheralsTest.kt
@@ -53,6 +53,25 @@ class PeripheralsTest {
assertEquals(Kind.Mouse, Peripherals.inputs(out).single().kind)
}
+ @Test fun aUsbCameraIsACameraNamedOnce() {
+ // The projector's camera, as dumpsys input lists its button.
+ val out = """
+ Event Hub State:
+ Devices:
+ 4: icspring camera: icspring camer
+ Classes: KEYBOARD | EXTERNAL
+ Identifier: bus=0x0003, vendor=0x1d6b, product=0x0102, version=0x0100
+ """.trimIndent()
+ assertEquals(listOf(Peripheral("icspring camera", Group.Input, Kind.Camera, true, "USB")), Peripherals.inputs(out))
+ }
+
+ @Test fun aNameIsCutToOnceOnlyWhenOneHalfStartsTheOther() {
+ assertEquals("icspring camera", Peripherals.once("icspring camera: icspring camer"))
+ assertEquals("HD Webcam C270", Peripherals.once("HD Webcam: HD Webcam C270"))
+ assertEquals("Mi Remote: Consumer Control", Peripherals.once("Mi Remote: Consumer Control"))
+ assertEquals("Logitech K400", Peripherals.once("Logitech K400"))
+ }
+
private val bluetooth = """
Bonded devices:
AA:BB:CC:DD:EE:01 [ DUAL ] Xbox Wireless Controller
diff --git a/app/src/main/java/app/tellyscope/ui/AccessUi.kt b/app/src/main/java/app/tellyscope/ui/AccessUi.kt
index e998639..d89cebb 100644
--- a/app/src/main/java/app/tellyscope/ui/AccessUi.kt
+++ b/app/src/main/java/app/tellyscope/ui/AccessUi.kt
@@ -140,6 +140,7 @@ internal object AccessIcons {
"M17 2H7c-1.1 0-2 .9-2 2v16c0 1.1.9 1.99 2 1.99L17 22c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z" +
"M12 4a2 2 0 1 0 0 4 2 2 0 1 0 0-4zM12 10a5 5 0 1 0 0 10 5 5 0 1 0 0-10zM12 12a3 3 0 1 0 0 6 3 3 0 1 0 0-6z",
)
+ val Camera = icon("Camera", "M15 8v8H5V8h10m1-2H4c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-3.5l4 4v-11l-4 4V7c0-.55-.45-1-1-1z")
val Hdmi = icon("Hdmi", "M18 7V4c0-1.1-.9-2-2-2H8c-1.1 0-2 .9-2 2v3H5v6l3 6v3h8v-3l3-6V7h-1zM8 4h8v3h-2V5h-1v2h-2V5h-1v2H8V4z")
private fun icon(name: String, path: String) = ImageVector.Builder(name, 24.dp, 24.dp, 24f, 24f)
@@ -156,6 +157,7 @@ internal object AccessIcons {
Peripheral.Kind.Bluetooth -> Bluetooth
Peripheral.Kind.Usb -> Usb
Peripheral.Kind.Hdmi -> Hdmi
+ Peripheral.Kind.Camera -> Camera
}
}