mirror of
https://github.com/github/codeql.git
synced 2026-04-22 07:15:15 +02:00
Refactor inAndroidApplication
This commit is contained in:
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user