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.

Launcher APKs save as <name>.apk, cleaned from the list

jesse-agent-23254ac8b0c3e84
diff --git a/app/src/main/java/app/tellyscope/data/LauncherDownload.kt b/app/src/main/java/app/tellyscope/data/LauncherDownload.kt
index b88fe05..d2c629e 100644
--- a/app/src/main/java/app/tellyscope/data/LauncherDownload.kt
+++ b/app/src/main/java/app/tellyscope/data/LauncherDownload.kt
@@ -52,6 +52,14 @@ private fun LauncherRelease.valid(launcher: KnownLauncher): Boolean {
fun latestTag(location: String?, releases: String): String? =
location?.removePrefix("$releases/tag/")?.takeIf { it != location && it.isNotEmpty() && '/' !in it && '?' !in it }
+/**
+ * The file [launcher] is saved as: its list name with spaces as `-` and only `[A-Za-z0-9._-]` kept,
+ * so no `/` or `..` path, at most 64 characters; its package name when nothing is left.
+ */
+fun apkName(launcher: KnownLauncher): String =
+ launcher.name.replace(' ', '-').filter { it.isLetterOrDigit() && it.code < 128 || it in "._-" }.take(64)
+ .ifEmpty { launcher.pkg } + ".apk"
+
/** The release page's one APK, from its asset list's links: the full URL, or null unless there is exactly one. */
fun pageApk(html: String, tag: String, releases: String): String? {
val path = releases.removePrefix("https://github.com") + "/download/$tag/"
@@ -144,7 +152,7 @@ class AndroidLauncherDownload(context: Context) : LauncherDownload {
override suspend fun fetch(launcher: KnownLauncher, release: LauncherRelease, onProgress: (Progress) -> Unit): PickedApp = withContext(Dispatchers.IO) {
dir.deleteRecursively()
dir.mkdirs()
- val file = File(dir, "launcher.apk")
+ val file = File(dir, apkName(launcher))
val c = URL(release.apk).openConnection() as HttpURLConnection
c.connectTimeout = 10_000
c.readTimeout = 30_000
@@ -174,7 +182,7 @@ class AndroidLauncherDownload(context: Context) : LauncherDownload {
override suspend fun open(uri: Uri, launcher: KnownLauncher): PickedApp = withContext(Dispatchers.IO) {
dir.deleteRecursively()
dir.mkdirs()
- val file = File(dir, "launcher.apk")
+ val file = File(dir, apkName(launcher))
val input = ctx.contentResolver.openInputStream(uri) ?: throw IOException("can't read $uri")
input.use { s ->
file.outputStream().use { out ->
diff --git a/app/src/test/java/app/tellyscope/FireOsTest.kt b/app/src/test/java/app/tellyscope/FireOsTest.kt
index 7ed9292..3b757d6 100644
--- a/app/src/test/java/app/tellyscope/FireOsTest.kt
+++ b/app/src/test/java/app/tellyscope/FireOsTest.kt
@@ -26,6 +26,7 @@ import app.tellyscope.data.Suggestions
import app.tellyscope.data.UiText
import app.tellyscope.data.WrongApk
import app.tellyscope.data.isFireOs
+import app.tellyscope.data.apkName
import app.tellyscope.data.latestTag
import app.tellyscope.data.pageApk
import app.tellyscope.data.parseLaunchers
@@ -312,6 +313,13 @@ class FireOsTest {
assertEquals(0, download.fetched)
}
+ @Test fun theApkIsSavedUnderItsCleanedName() {
+ assertEquals("Projectivy-Launcher.apk", apkName(projectivy.copy(name = "Projectivy Launcher")))
+ assertEquals("....Evil-Home.apk", apkName(projectivy.copy(name = "../../Evil Home")))
+ assertEquals("$PROJECTIVY.apk", apkName(projectivy.copy(name = "//?")))
+ assertEquals("a".repeat(64) + ".apk", apkName(projectivy.copy(name = "a".repeat(80))))
+ }
+
@Test fun whenTheApiIsLimitedTheReleasePageGivesTheTagAndItsOneApk() {
assertEquals(TAG, latestTag(PAGE, RELEASES))
assertNull(latestTag("https://github.com/someone/miproja1/releases/tag/$TAG", RELEASES))