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.

Remote: clear the TV's text box

jesse-agent-232e13a2946cce3
diff --git a/README.md b/README.md
index 8056db4..0f3e8f2 100644
--- a/README.md
+++ b/README.md
@@ -94,7 +94,7 @@ Tellyscope is a phone app that talks to your Android TV, Google TV or Fire TV ov
- **Connected devices.** The Overview lists what's paired with or plugged into the TV: Bluetooth remotes and headphones, USB keyboards and drives with their free space, HDMI-CEC devices such as a soundbar, and where the sound goes now.
- **Connection requests.** When another device asks to debug the TV, Tellyscope shows the TV's "Allow debugging?" prompt on your phone, with the device's key fingerprint, so you can **Allow** or **Deny** it without the remote. **Always allow this device** appears when the TV's own prompt offers it.
- **Files.** Send a file from your phone into the TV's Download or Movies folder, or save one from there to your phone. Two buttons under the TV pick the folder, and stay pinned under the bar as you scroll. An empty folder says so in the middle of the page. A file with the same name gets a " (1)" instead of being overwritten, and a cancelled copy leaves nothing half-written behind.
-- **Remote.** A D-pad and icon keys for Back, Home, Menu, mute and volume, laid out like Google TV's phone remote, plus typing on the TV. Each key gives a short tick; **Vibrate on key press** in Settings turns it off. The D-pad's centre pauses a playing video. **Add to dock** puts up to four of the TV's apps under the volume keys, each one tap from opening on the TV. Long-press one to change or remove it, or keep holding and move it to reorder. An app uninstalled from the TV leaves the dock by itself, and a snackbar says so. The restart button in the top bar asks first, then waits for the TV to come back: **Hide** keeps the wait in the top bar, and after a minute **Retry** waits another one. **Screen off** in the top bar turns off the TV's picture while Tellyscope stays connected, say to listen to music; any key or closing the Remote turns it back on. It needs Android 13 or older.
+- **Remote.** A D-pad and icon keys for Back, Home, Menu, mute and volume, laid out like Google TV's phone remote, plus typing on the TV. The backspace button next to Send empties the TV's text box, whatever is in your phone's. Each key gives a short tick; **Vibrate on key press** in Settings turns it off. The D-pad's centre pauses a playing video. **Add to dock** puts up to four of the TV's apps under the volume keys, each one tap from opening on the TV. Long-press one to change or remove it, or keep holding and move it to reorder. An app uninstalled from the TV leaves the dock by itself, and a snackbar says so. The restart button in the top bar asks first, then waits for the TV to come back: **Hide** keeps the wait in the top bar, and after a minute **Retry** waits another one. **Screen off** in the top bar turns off the TV's picture while Tellyscope stays connected, say to listen to music; any key or closing the Remote turns it back on. It needs Android 13 or older.
## Setting up your TV
@@ -113,7 +113,7 @@ Debloating a TV can break it if done carelessly. Tellyscope is built around thes
2. **Record before changing.** Before the first change on a TV, Tellyscope notes which apps were already off, so **Restore everything** turns back on only what Tellyscope turned off. Every change goes into the TV's history with an Undo. The history lives on the phone and is deleted if you uninstall Tellyscope; a disabled app still shows in the Apps list with **Turn on**.
3. **Protected list.** Packages the TV needs to boot, install its updates, stay on Wi-Fi, show web pages, show the home screen or accept input are on a protected list. Tellyscope refuses to stop or disable them, and there is no override in the app. A TV's list can add keeps: those only warn in the confirm, and can be overridden. If the TV doesn't say which app is its home screen, Tellyscope refuses to stop or disable anything. The one exception is switching home screens: the old launcher is disabled only after another launcher has become Home and Home has been checked to open it; a stock launcher that outranks the rest, such as Android TV Home, is turned off first and turned back on if Home still doesn't open the new one. The current home screen itself never can be. A TV's suggested list never protects fewer apps; its keeps add a warning, not a lock.
4. **No root, no exploits.** Only what ADB allows on a stock TV.
-5. **Nothing left on the TV.** Tellyscope copies two small helpers to `/data/local/tmp`. To show real app names and icons, the label helper runs once and is deleted; it only reads through PackageManager: no writes, no permissions, no network. While the Remote is open, the key helper keeps running to send keys and text and to turn the screen off and on; it is deleted when the Remote closes.
+5. **Nothing left on the TV.** Tellyscope copies two small helpers to `/data/local/tmp`. To show real app names and icons, the label helper runs once and is deleted; it only reads through PackageManager: no writes, no permissions, no network. While the Remote is open, the key helper keeps running to send keys and text, empty the TV's text box, and turn the screen off and on; it is deleted when the Remote closes.
## Project layout
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/KeyHelper.kt b/adb/src/main/kotlin/app/tellyscope/adb/KeyHelper.kt
index 4a0e757..7031209 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/KeyHelper.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/KeyHelper.kt
@@ -33,6 +33,9 @@ class KeyHelper(val session: AdbSession, private val dex: ByteArray) : AutoClose
/** Types [text], already checked with [Remote.typeable]; answers like [press]. */
suspend fun type(text: String): Boolean? = send("t$text")
+ /** Empties the focused text box on the TV (Ctrl+A, then Delete). Answers like [press]. */
+ suspend fun clear(): Boolean? = send("c")
+
/** Turns the TV's picture off or on; the TV stays awake and connected. Answers like [press]. */
suspend fun screen(on: Boolean): Boolean? = send(if (on) "p2" else "p0")
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt b/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt
index 8df3902..17caeca 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Remote.kt
@@ -43,6 +43,12 @@ class Remote(private val session: AdbSession, private val keys: KeyHelper? = nul
/** Types [text] into whatever box has focus on the TV, through [keys] like [press]. Check [typeable] first. */
suspend fun type(text: String): Boolean = keys?.type(text) ?: (session.shell(typeCommand(text)).exitCode == 0)
+ /**
+ * Empties the focused text box on the TV. Only the key helper can (`input` has no Ctrl+A on
+ * older Android): false when it isn't running or the TV refused. Throws if the link is gone.
+ */
+ suspend fun clearText(): Boolean = keys?.clear() ?: false
+
/**
* Turns the TV's picture off or back on, leaving the TV awake so the link stays up. Only the
* key helper can: false when it isn't running or the TV refused. Throws if the link is gone.
diff --git a/app/src/helper/java/app/tellyscope/helper/Keys.java b/app/src/helper/java/app/tellyscope/helper/Keys.java
index 2ff63a8..e11259c 100644
--- a/app/src/helper/java/app/tellyscope/helper/Keys.java
+++ b/app/src/helper/java/app/tellyscope/helper/Keys.java
@@ -58,6 +58,11 @@ public final class Keys {
out.flush();
continue;
}
+ if (line.equals("c")) {
+ out.print(clear(manager, inject) ? "1\n" : "0\n");
+ out.flush();
+ continue;
+ }
if (line.startsWith("t")) {
out.print(type(manager, inject, keymap, line.substring(1)) ? "1\n" : "0\n");
out.flush();
@@ -65,8 +70,8 @@ public final class Keys {
}
int code = Integer.parseInt(line.trim());
long now = SystemClock.uptimeMillis();
- ok = send(manager, inject, now, KeyEvent.ACTION_DOWN, code)
- && send(manager, inject, now, KeyEvent.ACTION_UP, code);
+ ok = send(manager, inject, now, KeyEvent.ACTION_DOWN, code, 0)
+ && send(manager, inject, now, KeyEvent.ACTION_UP, code, 0);
} catch (Throwable t) {
ok = false;
}
@@ -113,8 +118,27 @@ public final class Keys {
}
}
- private static boolean send(Object manager, Method inject, long downTime, int action, int code) throws Exception {
- KeyEvent e = new KeyEvent(downTime, SystemClock.uptimeMillis(), action, code, 0, 0,
+ /** Ctrl+A, then Delete: everything in the focused text box is selected and deleted. */
+ private static boolean clear(Object manager, Method inject) {
+ try {
+ int ctrl = KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON;
+ long now = SystemClock.uptimeMillis();
+ boolean ok = send(manager, inject, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_CTRL_LEFT, ctrl)
+ && send(manager, inject, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_A, ctrl)
+ && send(manager, inject, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_A, ctrl);
+ // Ctrl comes back up even when A wasn't taken, so the TV isn't left holding it.
+ ok = send(manager, inject, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_CTRL_LEFT, 0) && ok;
+ long del = SystemClock.uptimeMillis();
+ return ok
+ && send(manager, inject, del, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL, 0)
+ && send(manager, inject, del, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL, 0);
+ } catch (Throwable t) {
+ return false;
+ }
+ }
+
+ private static boolean send(Object manager, Method inject, long downTime, int action, int code, int meta) throws Exception {
+ KeyEvent e = new KeyEvent(downTime, SystemClock.uptimeMillis(), action, code, 0, meta,
KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD);
return (Boolean) inject.invoke(manager, e, WAIT_FOR_FINISH);
}
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index 5540ee6..9d3bf44 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -220,6 +220,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
actions = RemoteActions(
press = vm::press,
type = vm::type,
+ clearText = vm::clearText,
reboot = vm::reboot,
back = { remote = false },
retryRestart = vm::retryRestart,
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
index c8d0a38..d9369bc 100644
--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
@@ -604,6 +604,8 @@ class AdbDeviceSource(context: Context) : DeviceSource {
override suspend fun type(deviceId: String, text: String) = busy(deviceId) { remote(deviceId).type(text) }
+ override suspend fun clearText(deviceId: String) = busy(deviceId) { remote(deviceId).clearText() }
+
override suspend fun screen(deviceId: String, on: Boolean) = busy(deviceId) { remote(deviceId).screen(on) }
override suspend fun reboot(deviceId: String) = Remote(session(deviceId)).reboot()
diff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
index e3b9050..b412614 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
@@ -121,6 +121,9 @@ interface DeviceSource {
/** Types into the focused box on the TV. The caller checks [app.tellyscope.adb.Remote.typeable] first. */
suspend fun type(deviceId: String, text: String): Boolean
+ /** Empties the focused text box on the TV. False when this TV can't, or refused. Throws when it's gone. */
+ suspend fun clearText(deviceId: String): Boolean = false
+
/**
* Turns the TV's picture off or back on; the TV stays awake and connected. False when this TV
* can't (no key helper, or the TV refused). Throws when it's gone.
diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
index 56077f0..4148083 100644
--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
@@ -313,6 +313,11 @@ class FakeDeviceSource(
return true
}
+ override suspend fun clearText(deviceId: String): Boolean {
+ delay(100)
+ return true
+ }
+
override suspend fun screen(deviceId: String, on: Boolean): Boolean {
delay(100)
return true
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index ca20dde..a6487c8 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -321,6 +321,8 @@ object Copy {
const val REBOOT_IGNORED = "The TV didn't restart. Use its own remote or power button instead."
const val REMOTE_OFFLINE = "The TV is offline. The remote works again once it reconnects."
const val TYPE_HINT = "Select a text box on the TV, like a search box, then type here."
+ const val CLEAR_TV_TEXT = "Clear the TV's text box"
+ const val CLEAR_REFUSED = "The TV's text box didn't clear. Select it on the TV first, then try again."
const val SCREEN_OFF = "Screen off"
const val SCREEN_ON = "Turn the screen back on"
const val SCREEN_OFF_WAKE = "tap any key to wake"
diff --git a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
index 8295b78..1cb1a37 100644
--- a/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/RemoteScreen.kt
@@ -142,6 +142,8 @@ data class RemoteActions(
val press: suspend (RemoteKey) -> Boolean = { true },
/** Returns why the text can't be typed, or null once it's sent. */
val type: (String) -> String? = { null },
+ /** Empties the text box on the TV, whatever is in the phone's field. */
+ val clearText: () -> Unit = {},
val reboot: () -> Unit = {},
val back: () -> Unit = {},
/** A restart running late: try the TV again and wait another minute. */
@@ -272,7 +274,7 @@ fun RemoteScreen(
}
// Clear space above and below, so a thumb aiming at a volume key doesn't open an app.
DockSection(state.device.dock, state.device.apps, name(device), live, actions, Modifier.padding(vertical = 4.dp))
- Keyboard(live, actions.type)
+ Keyboard(live, actions.type, actions.clearText)
} }
}
}
@@ -370,7 +372,8 @@ private fun KeySurface(
}
@Composable
-private fun Keyboard(enabled: Boolean, type: (String) -> String?) {
+@OptIn(ExperimentalMaterial3Api::class)
+private fun Keyboard(enabled: Boolean, type: (String) -> String?, clearText: () -> Unit) {
var text by rememberSaveable { mutableStateOf("") }
var error by rememberSaveable { mutableStateOf<String?>(null) }
fun send() {
@@ -388,8 +391,19 @@ private fun Keyboard(enabled: Boolean, type: (String) -> String?) {
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Send),
keyboardActions = KeyboardActions(onSend = { send() }),
trailingIcon = {
- IconButton(onClick = ::send, enabled = enabled && text.isNotEmpty()) {
- Icon(Icons.AutoMirrored.Filled.Send, contentDescription = "Send to the TV")
+ Row {
+ TooltipBox(
+ positionProvider = TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Above),
+ tooltip = { PlainTooltip { Text(Copy.CLEAR_TV_TEXT) } },
+ state = rememberTooltipState(),
+ ) {
+ IconButton(onClick = clearText, enabled = enabled) {
+ Icon(RemoteIcons.Backspace, contentDescription = Copy.CLEAR_TV_TEXT)
+ }
+ }
+ IconButton(onClick = ::send, enabled = enabled && text.isNotEmpty()) {
+ Icon(Icons.AutoMirrored.Filled.Send, contentDescription = "Send to the TV")
+ }
}
},
modifier = Modifier.fillMaxWidth(),
@@ -771,6 +785,11 @@ private object RemoteIcons {
"M3 19L3 7L4.46 7L16.46 19L3 19Z" +
"M21 5L13.42 5L16.71 1.7L16 1L12 5L8 1L7.3 1.7L10.58 5L7.52 5L9.52 7L21 7L21 18.48L22.65 20.13C22.87 19.81 23 19.42 23 19L23 7C23 5.89 22.11 5 21 5Z",
)
+ val Backspace = icon(
+ "Backspace",
+ "M22 3L7 3C6.31 3 5.77 3.35 5.41 3.88L0 12L5.41 20.11C5.77 20.64 6.31 21 7 21L22 21C23.1 21 24 20.1 24 19L24 5C24 3.9 23.1 3 22 3Z" +
+ "M19 15.59L17.59 17L14 13.41L10.41 17L9 15.59L12.59 12L9 8.41L10.41 7L14 10.59L17.59 7L19 8.41L15.41 12L19 15.59Z",
+ )
val RestartAlt = icon(
"RestartAlt",
"M12 5L12 2L8 6L12 10L12 7C15.31 7 18 9.69 18 13C18 15.97 15.83 18.43 13 18.91L13 20.93C16.95 20.44 20 17.08 20 13C20 8.58 16.42 5 12 5Z" +
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index c5a57e9..3346359 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -1249,6 +1249,22 @@ class TellyscopeViewModel(
return null
}
+ /** Empties the focused text box on the TV. */
+ fun clearText() {
+ val id = _state.value.selectedId ?: return
+ viewModelScope.launch {
+ keys.withLock {
+ _notice.value = try {
+ if (source.clearText(id)) null else Copy.CLEAR_REFUSED
+ } catch (e: CancellationException) {
+ throw e
+ } catch (_: Exception) {
+ Copy.REMOTE_LOST
+ }
+ }
+ }
+ }
+
/** The TV shows its own update screen; Tellyscope can't see what it finds, so it only says where to look. */
fun checkUpdates() {
val id = _state.value.selectedId ?: return
diff --git a/app/src/test/java/app/tellyscope/ClearTextTest.kt b/app/src/test/java/app/tellyscope/ClearTextTest.kt
new file mode 100644
index 0000000..47e0521
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/ClearTextTest.kt
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import androidx.lifecycle.viewModelScope
+import app.tellyscope.data.Device
+import app.tellyscope.data.DeviceSource
+import app.tellyscope.data.DeviceState
+import app.tellyscope.data.FakeDeviceSource
+import app.tellyscope.data.ScanHit
+import app.tellyscope.data.ScanKind
+import app.tellyscope.data.Snapshot
+import app.tellyscope.ui.Copy
+import app.tellyscope.ui.TellyscopeViewModel
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.cancel
+import kotlinx.coroutines.flow.emptyFlow
+import kotlinx.coroutines.test.StandardTestDispatcher
+import kotlinx.coroutines.test.TestScope
+import kotlinx.coroutines.test.resetMain
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.setMain
+import org.junit.After
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Before
+import org.junit.Test
+import java.io.IOException
+
+/** One TV; [answer] is what clearing its text box does: true, false, or throw for a lost link. */
+private class TextBox : DeviceSource by FakeDeviceSource(FakeDeviceSource.Scenario.Empty, clock = { 0L }) {
+ var clears = 0
+ var answer: () -> Boolean = { true }
+
+ override suspend fun known() = listOf(
+ Device("tv", ScanHit("tv", 5555, ScanKind.Classic, "tv", null), DeviceState.Online, null, null, null, 0L, nickname = "Projector"),
+ )
+
+ override fun live(deviceId: String) = emptyFlow<Snapshot>()
+
+ override suspend fun clearText(deviceId: String): Boolean {
+ clears++
+ return answer()
+ }
+}
+
+@OptIn(ExperimentalCoroutinesApi::class)
+class ClearTextTest {
+ private val dispatcher = StandardTestDispatcher()
+ private val test = TestScope(dispatcher)
+ private val tv = TextBox()
+ private lateinit var vm: TellyscopeViewModel
+
+ @Before fun setUp() = Dispatchers.setMain(dispatcher)
+
+ @After fun tearDown() {
+ if (::vm.isInitialized) vm.viewModelScope.cancel()
+ Dispatchers.resetMain()
+ }
+
+ private fun clear() = with(test) {
+ vm = TellyscopeViewModel(tv, clock = { 0L })
+ runCurrent()
+ vm.clearText()
+ runCurrent()
+ }
+
+ @Test fun aClearedBoxSaysNothing() {
+ clear()
+ assertEquals(1, tv.clears)
+ assertNull(vm.notice.value)
+ }
+
+ @Test fun aBoxThatDidntClearSaysSo() {
+ tv.answer = { false }
+ clear()
+ assertEquals(Copy.CLEAR_REFUSED, vm.notice.value)
+ }
+
+ @Test fun aLostLinkSaysTheRemoteLostTheTv() {
+ tv.answer = { throw IOException("gone") }
+ clear()
+ assertEquals(Copy.REMOTE_LOST, vm.notice.value)
+ }
+}