Skip to content

Commit b7a5252

Browse files
committed
Refactor inAndroidApplication
1 parent 8dcef82 commit b7a5252

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

java/ql/lib/semmle/code/java/frameworks/android/Android.qll

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ import java
66
private import semmle.code.xml.AndroidManifest
77

88
/**
9-
* There is an android manifest file which defines an activity, service or
10-
* content provider (so it corresponds to an android application rather than a
11-
* library), and `file` is in a subfolder of the folder that contains it.
9+
* Holds if in `file`'s directory or some parent directory there is an `AndroidManifestXmlFile`
10+
* that defines at least one activity, service or contest provider, suggesting this file is
11+
* part of an android application.
1212
*/
1313
predicate inAndroidApplication(File file) {
1414
file.isSourceFile() and
15-
exists(AndroidComponentXmlElement acxe, AndroidManifestXmlFile amxf |
16-
amxf.getManifestElement().getApplicationElement().getAComponentElement() = acxe and
17-
(
18-
acxe instanceof AndroidActivityXmlElement or
19-
acxe instanceof AndroidServiceXmlElement or
20-
acxe instanceof AndroidProviderXmlElement
21-
)
15+
exists(AndroidManifestXmlFile amxf, Folder amxfDir |
16+
amxf.definesAndroidApplication() and amxfDir = amxf.getParentContainer()
2217
|
23-
file.getParentContainer+() = amxf.getParentContainer()
18+
file.getParentContainer+() = amxfDir
2419
)
2520
}
2621

java/ql/lib/semmle/code/xml/AndroidManifest.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ class AndroidManifestXmlFile extends XmlFile {
2323
* Holds if this Android manifest file is located in a build directory.
2424
*/
2525
predicate isInBuildDirectory() { this.getFile().getRelativePath().matches("%build%") }
26+
27+
/**
28+
* Holds if `amxf` defines at least one activity, service or contest provider,
29+
* and so it corresponds to an android application rather than a library.
30+
*/
31+
predicate definesAndroidApplication() {
32+
exists(AndroidComponentXmlElement acxe |
33+
this.getManifestElement().getApplicationElement().getAComponentElement() = acxe and
34+
(
35+
acxe instanceof AndroidActivityXmlElement or
36+
acxe instanceof AndroidServiceXmlElement or
37+
acxe instanceof AndroidProviderXmlElement
38+
)
39+
)
40+
}
2641
}
2742

2843
/**

0 commit comments

Comments
 (0)