fix(lab): reuse installed add-on packs so the Agent can restart (#2512)

This commit is contained in:
KeegantheVeganat0r authored and GitHub committed 2026-11-12 00:02:26 -05:00
1 parent 1882520cac
commit b303423001
3 files changed
+24 -1

No files matched your search

@@ -3,6 +3,7 @@ package com.droiddeck.launcher.core
import android.content.Context
import android.util.Log
import com.droiddeck.launcher.BuildConfig
import com.droiddeck.launcher.lab.LabOverlay
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
@@ -16,6 +17,7 @@ import java.io.FileInputStream
internal class AddonPack(
val name: String, private val sha256: String, val size: Long, private val required: List<String>,
private val reuseDeviceCopy: Boolean = sha256.isEmpty() && !BuildConfig.CI_BUILD,
private val labBuild: Boolean = LabOverlay.active != null,
private val bundle: (Context) -> java.io.InputStream = { it.assets.open("packs/$name.tar.zst") },
) {
sealed interface State {
@@ -42,7 +44,8 @@ internal class AddonPack(
fun installed(context: Context): Boolean = version(context).isNotEmpty() && File(dir(context), COMPLETE).isFile
private fun version(context: Context): String = if (!reuseDeviceCopy) sha256 else deviceCopy(context).orEmpty()
private fun version(context: Context): String =
if (reuseDeviceCopy || labBuild) deviceCopy(context) ?: sha256 else sha256
private fun deviceCopy(context: Context): String? = root(context).listFiles().orEmpty()
.filter { dir ->
@@ -58,6 +58,22 @@ class AddonPackTest {
assertFalse(AddonPack("sample", "", 0L, listOf("tool"), reuseDeviceCopy = false).installed(context))
}
@Test fun labBuildReusesInstalledPackDespiteDifferentSourcePin() {
installed("b".repeat(64))
val pack = AddonPack("sample", "a".repeat(64), 1L, listOf("tool"), labBuild = true)
assertTrue(pack.installed(context))
assertEquals("b".repeat(64), pack.dir(context).name)
}
@Test fun labBuildWithoutCompleteInstalledPackKeepsSourcePin() {
installed("b".repeat(64), complete = false)
val pack = AddonPack("sample", "a".repeat(64), 1L, listOf("tool"), labBuild = true)
assertFalse(pack.installed(context))
assertEquals("a".repeat(64), pack.dir(context).name)
}
@Test fun localBuildInstallsTheBundledPackWithoutDownloading() {
val archive = tarZst("tool" to "x")
val pack = AddonPack("sample", Hashes.sha256(archive), archive.length(), listOf("tool"), bundle = { archive.inputStream() })