Skip to content

Commit

Permalink
Support diffing uses-permission counts
Browse files Browse the repository at this point in the history
There might be significant differences in blame attribution for AndroidManifest.xml. We usually pay close attention to changes in versionCode, targetSdk, and the count of uses-permissions. Adding an extra line to display the result.
  • Loading branch information
Goooler committed Apr 30, 2024
1 parent 5e00c4b commit 7d4727c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AndroidManifest private constructor(
val packageName: String,
val versionName: String?,
val versionCode: Long?,
val usesPermissionCount: Int?,
) {
companion object {
const val NAME = "AndroidManifest.xml"
Expand Down Expand Up @@ -167,8 +168,9 @@ class AndroidManifest private constructor(
} else {
null
}
val usesPermissionCount = manifestElement.getElementsByTagName("uses-permission").length

return AndroidManifest(toFormattedXml(), packageName, versionName, versionCode)
return AndroidManifest(toFormattedXml(), packageName, versionName, versionCode, usesPermissionCount)
}

private fun Document.toFormattedXml() = buildString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ internal class ManifestDiff(
) {
internal val parsedPropertiesChanged = oldManifest.packageName != newManifest.packageName ||
oldManifest.versionName != newManifest.versionName ||
oldManifest.versionCode != newManifest.versionCode
oldManifest.versionCode != newManifest.versionCode ||
oldManifest.usesPermissionCount != newManifest.usesPermissionCount

val diff: List<String> = run {
val oldLines = oldManifest.xml.lines()
Expand All @@ -34,6 +35,7 @@ internal fun ManifestDiff.toDetailReport() = buildString {
row("package", oldManifest.packageName, newManifest.packageName)
row("version code", oldManifest.versionCode, newManifest.versionCode)
row("version name", oldManifest.versionName, newManifest.versionName)
row("uses-permission count", oldManifest.usesPermissionCount, newManifest.usesPermissionCount)
},
)
}
Expand Down

0 comments on commit 7d4727c

Please sign in to comment.