Support APK splits in metadata
This commit is contained in:
parent
46e8a46c63
commit
af2bf4f60a
5 changed files with 38 additions and 0 deletions
|
@ -70,6 +70,7 @@ data class PackageMetadata(
|
||||||
internal val system: Boolean = false,
|
internal val system: Boolean = false,
|
||||||
internal val version: Long? = null,
|
internal val version: Long? = null,
|
||||||
internal val installer: String? = null,
|
internal val installer: String? = null,
|
||||||
|
internal val splits: List<ApkSplit>? = null,
|
||||||
internal val sha256: String? = null,
|
internal val sha256: String? = null,
|
||||||
internal val signatures: List<String>? = null
|
internal val signatures: List<String>? = null
|
||||||
) {
|
) {
|
||||||
|
@ -78,11 +79,19 @@ data class PackageMetadata(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class ApkSplit(
|
||||||
|
val name: String,
|
||||||
|
val sha256: String
|
||||||
|
// There's also a revisionCode, but it doesn't seem to be used just yet
|
||||||
|
)
|
||||||
|
|
||||||
internal const val JSON_PACKAGE_TIME = "time"
|
internal const val JSON_PACKAGE_TIME = "time"
|
||||||
internal const val JSON_PACKAGE_STATE = "state"
|
internal const val JSON_PACKAGE_STATE = "state"
|
||||||
internal const val JSON_PACKAGE_SYSTEM = "system"
|
internal const val JSON_PACKAGE_SYSTEM = "system"
|
||||||
internal const val JSON_PACKAGE_VERSION = "version"
|
internal const val JSON_PACKAGE_VERSION = "version"
|
||||||
internal const val JSON_PACKAGE_INSTALLER = "installer"
|
internal const val JSON_PACKAGE_INSTALLER = "installer"
|
||||||
|
internal const val JSON_PACKAGE_SPLITS = "splits"
|
||||||
|
internal const val JSON_PACKAGE_SPLIT_NAME = "name"
|
||||||
internal const val JSON_PACKAGE_SHA256 = "sha256"
|
internal const val JSON_PACKAGE_SHA256 = "sha256"
|
||||||
internal const val JSON_PACKAGE_SIGNATURES = "signatures"
|
internal const val JSON_PACKAGE_SIGNATURES = "signatures"
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,7 @@ class MetadataManager(
|
||||||
system = packageInfo.isSystemApp(),
|
system = packageInfo.isSystemApp(),
|
||||||
version = packageMetadata.version,
|
version = packageMetadata.version,
|
||||||
installer = packageMetadata.installer,
|
installer = packageMetadata.installer,
|
||||||
|
splits = packageMetadata.splits,
|
||||||
sha256 = packageMetadata.sha256,
|
sha256 = packageMetadata.sha256,
|
||||||
signatures = packageMetadata.signatures
|
signatures = packageMetadata.signatures
|
||||||
)
|
)
|
||||||
|
|
|
@ -112,6 +112,7 @@ internal class MetadataReaderImpl(private val crypto: Crypto) : MetadataReader {
|
||||||
system = pSystem,
|
system = pSystem,
|
||||||
version = if (pVersion == 0L) null else pVersion,
|
version = if (pVersion == 0L) null else pVersion,
|
||||||
installer = if (pInstaller == "") null else pInstaller,
|
installer = if (pInstaller == "") null else pInstaller,
|
||||||
|
splits = getSplits(p),
|
||||||
sha256 = if (pSha256 == "") null else pSha256,
|
sha256 = if (pSha256 == "") null else pSha256,
|
||||||
signatures = signatures
|
signatures = signatures
|
||||||
)
|
)
|
||||||
|
@ -130,4 +131,18 @@ internal class MetadataReaderImpl(private val crypto: Crypto) : MetadataReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getSplits(p: JSONObject): List<ApkSplit>? {
|
||||||
|
val jsonSplits = p.optJSONArray(JSON_PACKAGE_SPLITS) ?: return null
|
||||||
|
val splits = ArrayList<ApkSplit>(jsonSplits.length())
|
||||||
|
for (i in 0 until jsonSplits.length()) {
|
||||||
|
val jsonApkSplit = jsonSplits.getJSONObject(i)
|
||||||
|
val apkSplit = ApkSplit(
|
||||||
|
name = jsonApkSplit.getString(JSON_PACKAGE_SPLIT_NAME),
|
||||||
|
sha256 = jsonApkSplit.getString(JSON_PACKAGE_SHA256)
|
||||||
|
)
|
||||||
|
splits.add(apkSplit)
|
||||||
|
}
|
||||||
|
return splits
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,14 @@ internal class MetadataWriterImpl(private val crypto: Crypto) : MetadataWriter {
|
||||||
}
|
}
|
||||||
packageMetadata.version?.let { put(JSON_PACKAGE_VERSION, it) }
|
packageMetadata.version?.let { put(JSON_PACKAGE_VERSION, it) }
|
||||||
packageMetadata.installer?.let { put(JSON_PACKAGE_INSTALLER, it) }
|
packageMetadata.installer?.let { put(JSON_PACKAGE_INSTALLER, it) }
|
||||||
|
packageMetadata.splits?.let { splits ->
|
||||||
|
put(JSON_PACKAGE_SPLITS, JSONArray().apply {
|
||||||
|
for (split in splits) put(JSONObject().apply {
|
||||||
|
put(JSON_PACKAGE_SPLIT_NAME, split.name)
|
||||||
|
put(JSON_PACKAGE_SHA256, split.sha256)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
packageMetadata.sha256?.let { put(JSON_PACKAGE_SHA256, it) }
|
packageMetadata.sha256?.let { put(JSON_PACKAGE_SHA256, it) }
|
||||||
packageMetadata.signatures?.let { put(JSON_PACKAGE_SIGNATURES, JSONArray(it)) }
|
packageMetadata.signatures?.let { put(JSON_PACKAGE_SIGNATURES, JSONArray(it)) }
|
||||||
})
|
})
|
||||||
|
|
|
@ -54,6 +54,11 @@ internal class MetadataWriterDecoderTest {
|
||||||
state = APK_AND_DATA,
|
state = APK_AND_DATA,
|
||||||
version = Random.nextLong(),
|
version = Random.nextLong(),
|
||||||
installer = getRandomString(),
|
installer = getRandomString(),
|
||||||
|
splits = listOf(
|
||||||
|
ApkSplit(getRandomString(), getRandomString()),
|
||||||
|
ApkSplit(getRandomString(), getRandomString()),
|
||||||
|
ApkSplit(getRandomString(), getRandomString())
|
||||||
|
),
|
||||||
sha256 = getRandomString(),
|
sha256 = getRandomString(),
|
||||||
signatures = listOf(getRandomString(), getRandomString())
|
signatures = listOf(getRandomString(), getRandomString())
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue