appstore: persist split-set siblings in the catalogue cache
- Commit
05c6b85b2cc7eebd2ed9e493917b2b3467a4f3b9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-10-31 22:31 UTC (1 month ago)
- Parents
ed2d060
Cached rows dropped splitFiles, so installing a split-set app from the cache committed only the base APK and failed with MISSING_SPLIT. Store them in a new splitFiles column (DB v9) and clear the cache on migration so the next sync repopulates rows with their splits.
Diff
appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.ktindex 94f1d1c56d..a36f11fa19 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.kt@@ -70,6 +70,8 @@ data class CachedAppEntity( val requiredFeatures: String? = null, /** TV-compat verdict from the catalogue; null when the source said nothing either way. */ val tvCompatible: Boolean? = null,+ /** Split-set siblings, one per line as `fileName\turl\tsha256\tsize`. Null for monolithic APKs. */+ val splitFiles: String? = null, ) /** URLs never contain a newline, so this survives values a comma would split apart. */@@ -81,6 +83,24 @@ private fun List<String>.packList(): String? = private fun String?.unpackList(): List<String> = this?.split(LIST_SEP)?.filter { it.isNotBlank() } ?: emptyList() +private const val FIELD_SEP = "\t"+private const val SPLIT_FIELDS = 4++internal fun List<SplitFile>.packSplits(): String? =+ map { listOf(it.fileName, it.url, it.sha256.orEmpty(), it.size.toString()).joinToString(FIELD_SEP) }+ .packList()++internal fun String?.unpackSplits(): List<SplitFile> = unpackList().mapNotNull { line ->+ val fields = line.split(FIELD_SEP)+ if (fields.size != SPLIT_FIELDS) return@mapNotNull null+ SplitFile(+ fileName = fields[0],+ url = fields[1],+ sha256 = fields[2].ifBlank { null },+ size = fields[3].toLongOrNull() ?: 0L,+ )+}+ fun UnifiedApp.toEntity(): CachedAppEntity = CachedAppEntity( packageName = packageName, source = source.name,@@ -117,6 +137,7 @@ fun UnifiedApp.toEntity(): CachedAppEntity = CachedAppEntity( tvScreenshots = tvScreenshots.packList(), requiredFeatures = requiredFeatures.joinToString(",").ifBlank { null }, tvCompatible = tvCompatible,+ splitFiles = splitFiles.packSplits(), ) fun CachedAppEntity.toUnifiedApp(): UnifiedApp = UnifiedApp(@@ -155,6 +176,7 @@ fun CachedAppEntity.toUnifiedApp(): UnifiedApp = UnifiedApp( tvScreenshots = tvScreenshots.unpackList(), requiredFeatures = requiredFeatures?.split(",")?.filter { it.isNotBlank() } ?: emptyList(), tvCompatible = tvCompatible,+ splitFiles = splitFiles.unpackSplits(), ) /**@@ -369,7 +391,7 @@ interface CachedAppDao { PinnedStampEntity::class, AccrescentTrustEntity::class, ],- version = 8,+ version = 9, exportSchema = false ) abstract class AppDatabase : RoomDatabase() {@@ -462,6 +484,15 @@ abstract class AppDatabase : RoomDatabase() { connection.execSQL("ALTER TABLE CachedAppEntity ADD COLUMN requiredFeatures TEXT") connection.execSQL("ALTER TABLE CachedAppEntity ADD COLUMN tvCompatible INTEGER") }+ },+ object : Migration(8, 9) {+ override suspend fun migrate(connection: SQLiteConnection) {+ // Rows cached before this lost their split siblings, so a split-set+ // install committed only the base and failed with MISSING_SPLIT.+ // Drop them so no split-less row survives; the next sync repopulates.+ connection.execSQL("ALTER TABLE CachedAppEntity ADD COLUMN splitFiles TEXT")+ connection.execSQL("DELETE FROM CachedAppEntity")+ } } ) }
appstore/src/test/java/com/vayunmathur/appstore/data/CachedAppSplitFilesTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/data/CachedAppSplitFilesTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/data/CachedAppSplitFilesTest.ktnew file mode 100644index 0000000000..3ae17f4f61--- /dev/null+++ b/appstore/src/test/java/com/vayunmathur/appstore/data/CachedAppSplitFilesTest.kt@@ -0,0 +1,49 @@+package com.vayunmathur.appstore.data++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull++/**+ * Installs read the app back from the Room catalogue, so split siblings dropped on the+ * way in leave a split-set install with only its base (INSTALL_FAILED_MISSING_SPLIT).+ */+class CachedAppSplitFilesTest {++ private val base = UnifiedApp(+ packageName = "com.google.android.gms",+ source = AppSource.PROPRIETARY,+ name = "Google Play services",+ apkUrl = "https://maproj.org/proprietary/repo/com.google.android.gms-264261035.apk",+ )++ @Test+ fun splitFilesSurviveRoundTrip() {+ val splits = listOf(+ SplitFile(+ fileName = "/com.google.android.gms/264261035/com.google.android.gms-264261035-config.en.apk",+ url = "https://maproj.org/proprietary/repo/com.google.android.gms-264261035-config.en.apk",+ sha256 = "f003c399fa6d671bcdf773de21910bd3ead73513f3df968f7255aba86f878369",+ size = 1425618L,+ ),+ SplitFile(+ fileName = "config.xxhdpi.apk",+ url = "https://example.org/config.xxhdpi.apk",+ sha256 = null,+ size = 0L,+ ),+ )++ val restored = base.copy(splitFiles = splits).toEntity().toUnifiedApp()++ assertEquals(splits, restored.splitFiles)+ }++ @Test+ fun monolithicAppStoresNoSplits() {+ val entity = base.toEntity()++ assertNull(entity.splitFiles)+ assertEquals(emptyList(), entity.toUnifiedApp().splitFiles)+ }+}