Skip to content

Commit b364d28

Browse files
authored
Merge pull request #308 from opalj/feature/move-androidentrypointsfinder
Move AndroidEntryPointsFinder to BR
2 parents b335f93 + 4dc9112 commit b364d28

File tree

4 files changed

+49
-41
lines changed

4 files changed

+49
-41
lines changed

OPAL/br/src/main/resources/reference.conf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,32 @@ org.opalj {
171171
L0SelfReferenceLeakage {
172172
debug = true // default is "false"
173173
}
174+
},
175+
176+
android {
177+
AndroidEntryPointFinder {
178+
# These methods are considered entry points for an Android app.
179+
entryPoints = [
180+
{cf = "android/app/Activity", name = "onCreate", desc = "(Landroid/os/Bundle;)V"}
181+
{cf = "android/app/Activity", name = "onRestart", desc = "()V"},
182+
{cf = "android/app/Activity", name = "onStart", desc = "()V"},
183+
{cf = "android/app/Activity", name = "onResume", desc = "()V"},
184+
{cf = "android/app/Activity", name = "onStop", desc = "()V"},
185+
{cf = "android/app/Activity", name = "onDestroy", desc = "()V"},
186+
{cf = "android/app/Activity", name = "onActivityResult", desc = "()V"},
187+
{cf = "android/app/Service", name = "onCreate", desc = "()V"},
188+
{cf = "android/app/Service", name = "onStartCommand", desc = "(Landroid/content/Intent;II)V"},
189+
{cf = "android/app/Service", name = "onBind", desc = "(Landroid/content/Intent;)Landroid/os/IBinder;"},
190+
{cf = "android/app/Service", name = "onRebind", desc = "(Landroid/content/Intent;)V"},
191+
{cf = "android/app/Service", name = "onStart", desc = "(Landroid/content/Intent;I)V"},
192+
{cf = "android/app/Service", name = "onDestroy", desc = "()V"},
193+
{cf = "android/content/ContentProvider",name = "onCreate", desc = "()V"},
194+
{cf = "android/location/LocationListener",name = "onProviderDisabled", desc = "(Ljava/lang/String;)V"},
195+
{cf = "android/location/LocationListener",name = "onProviderEnabled", desc = "(Ljava/lang/String;)V"},
196+
{cf = "android/location/LocationListener",name = "onStatusChanged", desc = "(Ljava/lang/String;ILandroid/os/Bundle;)V"},
197+
{cf = "android/content/BroadcastReceiver",name = "onReceive",desc = "(Landroid/content/Context;Landroid/content/Intent;)V"}
198+
]
199+
}
174200
}
175201
}
176202

Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
/* BSD 2-Clause License - see OPAL/LICENSE for details. */
22
package org.opalj
3-
package tac
4-
package cg
3+
package br
54
package android
65

76
import scala.collection.mutable.ArrayBuffer
8-
import scala.jdk.CollectionConverters.CollectionHasAsScala
97

108
import org.opalj.br.Method
119
import org.opalj.br.MethodDescriptor
1210
import org.opalj.br.ReferenceType
1311
import org.opalj.br.analyses.ProjectInformationKeys
1412
import org.opalj.br.analyses.SomeProject
1513
import org.opalj.br.analyses.cg.EntryPointFinder
16-
import org.opalj.br.android.AndroidManifest
17-
import org.opalj.br.android.AndroidManifestKey
18-
import org.opalj.tac.fpcf.analyses.MethodDescription
14+
15+
import net.ceedubs.ficus.Ficus._
1916

2017
/**
21-
* The AndroidEntryPointFinder considers specific methods of launcher Activity Clases as entry points.
18+
* The AndroidEntryPointFinder considers specific methods of launcher Activity Classes as entry points.
2219
* An activity is a launcher activity if it contains an intent filter with action "android.intent.action.MAIN"
2320
* and category "android.intent.category.LAUNCHER". Requires Android Manifest to be loaded.
2421
*
2522
* @author Julius Naeumann
2623
*/
27-
object AndroidEntryPointsFinder extends EntryPointFinder {
24+
object AndroidEntryPointFinder extends EntryPointFinder {
2825

29-
val configKey = "org.opalj.tac.cg.android.AndroidEntryPointsFinder.entryPoints"
26+
val configKey = "org.opalj.fpcf.android.AndroidEntryPointFinder.entryPoints"
3027

3128
override def requirements(project: SomeProject): ProjectInformationKeys = {
3229
super.requirements(project) ++ Seq(AndroidManifestKey)
@@ -44,8 +41,12 @@ object AndroidEntryPointsFinder extends EntryPointFinder {
4441
// iterate over launchable classes, collect their respective entry point methods according to config
4542
for (componentClass <- launchableClasses) {
4643
for (epd <- entryPointDescriptions) {
47-
if (classHierarchy.isASubtypeOf(ReferenceType(componentClass.fqn), ReferenceType(epd.cf)).isYesOrUnknown) {
48-
entryPoints ++= componentClass.findMethod(epd.name, MethodDescriptor(epd.desc))
44+
if (classHierarchy.isASubtypeOf(
45+
ReferenceType(componentClass.fqn),
46+
ReferenceType(epd.declaringClass)
47+
).isYesOrUnknown
48+
) {
49+
entryPoints ++= componentClass.findMethod(epd.name, MethodDescriptor(epd.descriptor))
4950
}
5051
}
5152
}
@@ -54,8 +55,15 @@ object AndroidEntryPointsFinder extends EntryPointFinder {
5455
}
5556

5657
private def getConfiguredEntryPoints(project: SomeProject) = {
57-
val entryPointDescriptionsConfig = project.config.getConfigList(configKey).asScala.toArray
58-
val entryPointDescriptions = entryPointDescriptionsConfig.map(c => MethodDescription.reader.read(c, ""))
59-
entryPointDescriptions
58+
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
59+
project.config.as[List[EntryPointContainer]](configKey)
60+
6061
}
62+
63+
/* Required by Ficus' `ArbitraryTypeReader`*/
64+
private case class EntryPointContainer(
65+
declaringClass: String,
66+
name: String,
67+
descriptor: String
68+
)
6169
}

OPAL/br/src/main/scala/org/opalj/br/android/AndroidManifestArg.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object AndroidManifestArg extends PlainArg[File] with ProjectBasedArg[File, File
2424
if (value.isDefined) {
2525
opalConfig.withValue(
2626
InitialEntryPointsKey.ConfigKey,
27-
ConfigValueFactory.fromAnyRef("org.opalj.tac.cg.android.AndroidEntryPointsFinder")
27+
ConfigValueFactory.fromAnyRef("org.opalj.br.android.AndroidEntryPointFinder")
2828
)
2929
} else opalConfig
3030
}

OPAL/tac/src/main/resources/reference.conf

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,32 +1589,6 @@ org.opalj {
15891589
"org.opalj.tac.fpcf.analyses.fieldaccess.TriggeredFieldAccessInformationAnalysis",
15901590
"org.opalj.tac.fpcf.analyses.fieldaccess.reflection.ReflectionRelatedFieldAccessesAnalysisScheduler",
15911591
]
1592-
},
1593-
1594-
android {
1595-
AndroidEntryPointsFinder {
1596-
# These methods are considered entry points for an Android app.
1597-
entryPoints = [
1598-
{cf = "android/app/Activity", name = "onCreate", desc = "(Landroid/os/Bundle;)V"}
1599-
{cf = "android/app/Activity", name = "onRestart", desc = "()V"},
1600-
{cf = "android/app/Activity", name = "onStart", desc = "()V"},
1601-
{cf = "android/app/Activity", name ="onResume", desc = "()V"},
1602-
{cf = "android/app/Activity", name = "onStop", desc = "()V"},
1603-
{cf = "android/app/Activity", name = "onDestroy", desc = "()V"},
1604-
{cf = "android/app/Activity", name = "onActivityResult", desc = "()V"},
1605-
{cf = "android/app/Service", name = "onCreate", desc = "()V"},
1606-
{cf = "android/app/Service", name ="onStartCommand", desc = "(Landroid/content/Intent;II)V")},
1607-
{cf = "android/app/Service", name ="onBind", desc = "(Landroid/content/Intent;)Landroid/os/IBinder;"},
1608-
{cf = "android/app/Service", name ="onRebind", desc = "(Landroid/content/Intent;)V"},
1609-
{cf = "android/app/Service", name ="onStart", desc = "(Landroid/content/Intent;I)V"},
1610-
{cf = "android/app/Service", name = "onDestroy", desc = "()V"},
1611-
{cf = "android/content/ContentProvider",name = "onCreate", desc = "()V"},
1612-
{cf = "android/location/LocationListener",name = "onProviderDisabled", desc = "(Ljava/lang/String;)V"},
1613-
{cf = "android/location/LocationListener",name = "onProviderEnabled", desc = "(Ljava/lang/String;)V"},
1614-
{cf = "android/location/LocationListener",name = "onStatusChanged", desc = "(Ljava/lang/String;ILandroid/os/Bundle;)V"},
1615-
{cf = "android/content/BroadcastReceiver",name = "onReceive",desc = "(Landroid/content/Context;Landroid/content/Intent;)V"}
1616-
]
1617-
}
16181592
}
16191593
}
16201594
}

0 commit comments

Comments
 (0)