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.

Shell: fix the GenericShape import; ask before more TV-changing forms

jesse-agent-232d22aed178ba8
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/ShellInput.kt b/adb/src/main/kotlin/app/tellyscope/adb/ShellInput.kt
index 1a38e3b..cd0856c 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/ShellInput.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/ShellInput.kt
@@ -28,9 +28,12 @@ object ShellInput {
* because Shell runs aren't in History and have no one-tap undo.
*/
private val CHANGES = listOf(
- "pm uninstall", "pm disable", "pm disable-user", "pm clear",
+ "pm uninstall", "pm disable", "pm disable-user", "pm clear", "pm hide", "pm suspend", "pm set-home-activity",
"cmd package uninstall", "cmd package disable", "cmd package disable-user", "cmd package clear",
+ "cmd package hide", "cmd package suspend", "cmd package set-home-activity",
"settings put", "settings delete",
+ // These cut the Wi-Fi that Tellyscope reaches the TV over.
+ "svc wifi disable", "cmd wifi set-wifi-enabled disabled",
"wm size", "wm density",
"reboot", "svc power reboot", "rm",
).map { it.split(' ') }
@@ -65,10 +68,17 @@ object ShellInput {
?.joinToString(" ")
}
- /** Each simple command's words, with `su -c`, `exec`-like wrappers and `VAR=x` prefixes skipped. */
+ /**
+ * Each simple command's words: `su -c`, `sh -c`, `exec`-like wrappers and `VAR=x` prefixes
+ * skipped, and a full path cut to the program's name (`/system/bin/pm` is `pm`).
+ */
private fun segments(command: String): List<List<String>> = command.split(SEGMENTS).map { seg ->
- seg.trim().split(Regex("""\s+""")).filter { it.isNotEmpty() }
- .dropWhile { it == "su" || it == "-c" || it == "0" || it == "exec" || it == "command" || it == "nohup" || it.matches(Regex("""\w+=\S*""")) }
+ val words = seg.trim().split(Regex("""\s+""")).filter { it.isNotEmpty() }
.map { it.trim('\'', '"', '(', ')', '{', '}') }
+ .filter { it.isNotEmpty() }
+ .dropWhile { it in WRAPPERS || it.matches(Regex("""\w+=\S*""")) }
+ if (words.isEmpty()) words else listOf(words[0].substringAfterLast('/')) + words.drop(1)
}
+
+ private val WRAPPERS = setOf("su", "sh", "-c", "0", "exec", "command", "nohup", "toybox", "busybox")
}
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/TvShellTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/TvShellTest.kt
index 6eefabf..f3ca93d 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/TvShellTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/TvShellTest.kt
@@ -142,4 +142,26 @@ class TvShellTest {
assertNull(ShellInput.changesTv("rmdir empty"))
assertNull(ShellInput.changesTv("wm size"))
}
+
+ @Test fun fullPathsAndShDashCAreSeenThrough() {
+ assertEquals("pm uninstall", ShellInput.changesTv("/system/bin/pm uninstall com.example"))
+ assertEquals("pm uninstall", ShellInput.changesTv("sh -c 'pm uninstall com.example'"))
+ assertEquals("rm", ShellInput.changesTv("sh -c \"/system/bin/rm -rf /sdcard/Download\""))
+ assertEquals("cmd package clear", ShellInput.changesTv("/system/bin/cmd package clear com.example"))
+ assertNull(ShellInput.changesTv("sh -c 'pm list packages'"))
+ }
+
+ @Test fun wifiOffAndHidingAppsAreFound() {
+ assertEquals("svc wifi disable", ShellInput.changesTv("svc wifi disable"))
+ assertEquals("cmd wifi set-wifi-enabled disabled", ShellInput.changesTv("cmd wifi set-wifi-enabled disabled"))
+ assertEquals("pm hide", ShellInput.changesTv("pm hide com.example"))
+ assertEquals("pm suspend", ShellInput.changesTv("pm suspend com.example"))
+ assertEquals("pm set-home-activity", ShellInput.changesTv("pm set-home-activity com.example/.Home"))
+ assertEquals("cmd package hide", ShellInput.changesTv("cmd package hide com.example"))
+ assertEquals("cmd package suspend", ShellInput.changesTv("cmd package suspend com.example"))
+ assertEquals("cmd package set-home-activity", ShellInput.changesTv("cmd package set-home-activity com.example/.Home"))
+ assertNull(ShellInput.changesTv("svc wifi enable"))
+ assertNull(ShellInput.changesTv("cmd wifi set-wifi-enabled enabled"))
+ assertNull(ShellInput.changesTv("cmd wifi status"))
+ }
}
diff --git a/app/src/main/java/app/tellyscope/ui/ShellScreen.kt b/app/src/main/java/app/tellyscope/ui/ShellScreen.kt
index 8ec7b37..ef8a84a 100644
--- a/app/src/main/java/app/tellyscope/ui/ShellScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/ShellScreen.kt
@@ -22,6 +22,7 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.shape.GenericShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
@@ -51,7 +52,6 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
-import androidx.compose.ui.graphics.GenericShape
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.Color