Refactor inAndroidApplication

This commit is contained in:
Owen Mansel-Chan
2024-07-13 07:35:02 +01:00
parent 8dcef8223f
commit b7a5252cb0
2 changed files with 21 additions and 11 deletions

View File

@@ -6,21 +6,16 @@ import java
private import semmle.code.xml.AndroidManifest
/**
* There is an android manifest file which defines an activity, service or
* content provider (so it corresponds to an android application rather than a
* library), and `file` is in a subfolder of the folder that contains it.
* Holds if in `file`'s directory or some parent directory there is an `AndroidManifestXmlFile`
* that defines at least one activity, service or contest provider, suggesting this file is
* part of an android application.
*/
predicate inAndroidApplication(File file) {
file.isSourceFile() and
exists(AndroidComponentXmlElement acxe, AndroidManifestXmlFile amxf |
amxf.getManifestElement().getApplicationElement().getAComponentElement() = acxe and
(
acxe instanceof AndroidActivityXmlElement or
acxe instanceof AndroidServiceXmlElement or
acxe instanceof AndroidProviderXmlElement
)
exists(AndroidManifestXmlFile amxf, Folder amxfDir |
amxf.definesAndroidApplication() and amxfDir = amxf.getParentContainer()
|
file.getParentContainer+() = amxf.getParentContainer()
file.getParentContainer+() = amxfDir
)
}

View File

@@ -23,6 +23,21 @@ class AndroidManifestXmlFile extends XmlFile {
* Holds if this Android manifest file is located in a build directory.
*/
predicate isInBuildDirectory() { this.getFile().getRelativePath().matches("%build%") }
/**
* Holds if `amxf` defines at least one activity, service or contest provider,
* and so it corresponds to an android application rather than a library.
*/
predicate definesAndroidApplication() {
exists(AndroidComponentXmlElement acxe |
this.getManifestElement().getApplicationElement().getAComponentElement() = acxe and
(
acxe instanceof AndroidActivityXmlElement or
acxe instanceof AndroidServiceXmlElement or
acxe instanceof AndroidProviderXmlElement
)
)
}
}
/**