appstore: install split-set versions as one session (Uber fix)
- Commit
35642d77a21dbc9634dcac5319e513ebd0d4c04d- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-22 02:29 UTC (1 month ago)
- Parents
9cd045f
Diff
appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.ktindex 30623a2410..a4f127357a 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt@@ -84,6 +84,13 @@ data class UnifiedApp( val repoUrl: String? = null, val offerType: Int = 0, val containsSplit: Boolean = false,+ /**+ * Sibling APKs that must install in the same session as [apkUrl] (split-set+ * versions: base + config splits sharing one versionCode). Empty for+ * monolithic APKs. URLs are absolute; each carries its own hash/size for+ * per-file verification — see `InstallCoordinator.installFromUrl`.+ */+ val splitFiles: List<SplitFile> = emptyList(), val isFree: Boolean = true, /** Listing screenshots, in the order the source published them. */ val screenshots: List<String> = emptyList(),@@ -143,6 +150,18 @@ data class UnifiedApp( val heroImage: String? get() = featureGraphic ?: screenshots.firstOrNull() } +/**+ * One sibling APK of a split-set version ([UnifiedApp.splitFiles]): anything+ * sharing the chosen entry's versionCode. Downloaded and installed in the same+ * [PackageInstaller] session as [UnifiedApp.apkUrl].+ */+data class SplitFile(+ val fileName: String,+ val url: String,+ val sha256: String? = null,+ val size: Long = 0L,+)+ /** The fields [SearchRanking] looks at, for a listing from any source. */ fun UnifiedApp.searchCandidate(): SearchRanking.Candidate = SearchRanking.Candidate( name = name,
appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.ktindex fd5001392a..5f7bd4f05c 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt@@ -215,6 +215,7 @@ object FDroidRepository { var nativeCode: List<String> = emptyList() var whatsNew: String? = null var requiredFeatures: List<String> = emptyList()+ var requiredSplitTypes: List<String> = emptyList() fun build(): VersionCandidate? { val name = fileName ?: return null@@ -230,6 +231,7 @@ object FDroidRepository { nativeCode = nativeCode, whatsNew = whatsNew, requiredFeatures = requiredFeatures,+ requiredSplitTypes = requiredSplitTypes, ) } }@@ -258,6 +260,29 @@ object FDroidRepository { // that has no installable APK behind it. val latest = selectVersion(b.versions, deviceAbis) ?: return null + // Split-set versions install as a set: when the chosen entry requires+ // splits, every indexed file sharing its versionCode belongs in the+ // same installer session (base + config splits). Without this the+ // system refuses with INSTALL_FAILED_MISSING_SPLIT on Android 14+.+ // Sibling order is deterministic (base first: shortest file name tends+ // to be the base; ties broken alphabetically) — the session writer+ // doesn't care about order, but humans reading logs do.+ val splitFiles = if (latest.requiredSplitTypes.isEmpty()) {+ emptyList()+ } else {+ b.versions+ .filter { it.versionCode == latest.versionCode && it.fileName != latest.fileName }+ .sortedWith(compareBy({ it.fileName.length }, { it.fileName }))+ .map {+ SplitFile(+ fileName = it.fileName,+ url = repoBase + "/" + it.fileName.trimStart('/'),+ sha256 = it.sha256,+ size = it.size,+ )+ }+ }+ // index-v2 file names are repo-absolute ("/com.example_12.apk"). val apkUrl = repoBase + "/" + latest.fileName.trimStart('/') val tvCompatible = deriveTvCompatible(b.categories, b.tvScreenshots, latest.requiredFeatures)@@ -291,6 +316,8 @@ object FDroidRepository { repoUrl = repoBase, requiredFeatures = latest.requiredFeatures, tvCompatible = tvCompatible,+ containsSplit = latest.requiredSplitTypes.isNotEmpty() || splitFiles.isNotEmpty(),+ splitFiles = splitFiles, ) } @@ -409,6 +436,11 @@ object FDroidRepository { // The ABIs this APK carries native libraries for. // Absent means it has none and runs anywhere. "nativecode" -> v.nativeCode = readStringArray(reader)+ // Split types this APK requires at install time+ // (`requiredSplitTypes`, e.g. ["config", "density"]). Absent on+ // monolithic APKs. A non-empty list means the version installs+ // only as a set — see selectVersion's sibling gathering.+ "requiredSplitTypes" -> v.requiredSplitTypes = readStringArray(reader) // `<uses-feature>` entries, as `[{ "name": "android.hardware.camera" }, …]`. // Kept verbatim for TV-compat filtering — a leanback entry marks a TV build, // phone-hardware entries mark one a TV should not be offered.@@ -472,6 +504,7 @@ object FDroidRepository { val nativeCode: List<String> = emptyList(), val whatsNew: String? = null, val requiredFeatures: List<String> = emptyList(),+ val requiredSplitTypes: List<String> = emptyList(), ) /**
appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.ktindex de888c72e7..61ddef429a 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt@@ -219,11 +219,18 @@ class InstallCoordinator( // This store's own Play mirror: the same release key signs the index, but // the APKs carry the developers' keys, so the per-version signers from // the signed index are the anchor — not this store's own certificate.+ // Split siblings are keyed by their LOCAL file names (the verifier+ // matches on File.name): base keeps `${package}.apk`, splits land+ // as `${package}.splitN.apk` — see the download loop below. AppSource.PROPRIETARY -> InstallRequirement( expectedPackage = app.packageName, requiredSigners = app.expectedSigners.toSet(),- expectedSha256 = app.apkSha256- ?.let { mapOf("${app.packageName}.apk" to it) } ?: emptyMap(),+ expectedSha256 = buildMap {+ app.apkSha256?.let { put("${app.packageName}.apk", it) }+ app.splitFiles.forEachIndexed { index, split ->+ split.sha256?.let { put("${app.packageName}.split$index.apk", it) }+ }+ }, signerOrigin = "this store's Play mirror", requireTvCompatible = isTv, )@@ -242,8 +249,33 @@ class InstallCoordinator( stage(app.packageName, InstallStage.Downloading(fraction)) } + // Split-set versions install every file in one session: the base+ // plus the sibling splits sharing its versionCode. Without the set,+ // Android 14+ refuses with INSTALL_FAILED_MISSING_SPLIT.+ // Aggregate progress mirrors installFromAccrescent's split loop.+ val files = if (app.splitFiles.isEmpty()) {+ listOf(file)+ } else {+ val totalSize =+ (app.sizeBytes + app.splitFiles.sumOf { it.size }).takeIf { it > 0 } ?: -1L+ var downloadedBytes = file.length()+ val siblings = app.splitFiles.mapIndexed { index, split ->+ val splitFile = File(context.cacheDir, "${app.packageName}.split$index.apk")+ val start = downloadedBytes+ download(split.url, splitFile, split.size) { fileFraction ->+ if (totalSize > 0) {+ val overall = (start + fileFraction * split.size) / totalSize+ stage(app.packageName, InstallStage.Downloading(overall.coerceIn(0f, 1f)))+ }+ }+ downloadedBytes += splitFile.length()+ splitFile+ }+ listOf(file) + siblings+ }+ stage(app.packageName, InstallStage.Verifying)- sessionInstaller.installSplits(app.packageName, listOf(file), requirement, file.length())+ sessionInstaller.installSplits(app.packageName, files, requirement, files.sumOf { it.length() }) } private fun download(