Add support for android:allowBackup default value

The default value of `android:allowBackup` is `true`. Added support for
detecting if the default value is used.
This commit is contained in:
Ed Minnix
2022-08-18 22:04:38 -04:00
parent 6509426fb3
commit dad4a403db
3 changed files with 15 additions and 4 deletions

View File

@@ -74,13 +74,17 @@ class AndroidApplicationXmlElement extends XmlElement {
predicate requiresPermissions() { this.getAnAttribute().(AndroidPermissionXmlAttribute).isFull() }
/**
* Holds if this application element has the attribute `android:allowBackup` set to `true`.
* Holds if this application element enables the `android:allowBackup` attribute.
*
* https://developer.android.com/guide/topics/data/autobackup
*/
predicate allowsBackup() {
exists(AndroidXmlAttribute attr |
// The default value for the attribute `android:allowBackup` is `true`.
// Therefore we also check if it is not present.
not exists(AndroidXmlAttribute attr |
this.getAnAttribute() = attr and
attr.getName() = "allowBackup" and
attr.getValue() = "true"
attr.getValue() = "false"
)
}
}

View File

@@ -17,4 +17,4 @@ from AndroidApplicationXmlElement androidAppElem
where
androidAppElem.allowsBackup() and
androidAppElem.getFile().(AndroidManifestXmlFile).isInBuildDirectory()
select androidAppElem.getAttribute("allowBackup"), "The 'android:allowBackup' attribute is enabled."
select androidAppElem, "The 'android:allowBackup' attribute is enabled."

View File

@@ -0,0 +1,7 @@
<manifest ... >
<!-- BAD: no 'android:allowBackup' set, defaults to 'true' -->
<application>
<activity ... >
</activity>
</application>
</manifest>