|
| 1 | +/** |
| 2 | + * Provides classes and predicates for working with Android components. |
| 3 | + */ |
| 4 | + |
| 5 | +import java |
| 6 | +import semmle.code.xml.AndroidManifest |
| 7 | + |
| 8 | +/** |
| 9 | + * An Android component. That is, either an activity, a service, |
| 10 | + * a broadcast receiver, or a content provider. |
| 11 | + */ |
| 12 | +class AndroidComponent extends Class { |
| 13 | + AndroidComponent() { |
| 14 | + this.getASupertype*().hasQualifiedName("android.app", "Activity") or |
| 15 | + this.getASupertype*().hasQualifiedName("android.app", "Service") or |
| 16 | + this.getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver") or |
| 17 | + this.getASupertype*().hasQualifiedName("android.content", "ContentProvider") |
| 18 | + } |
| 19 | + |
| 20 | + /** The XML element corresponding to this Android component. */ |
| 21 | + AndroidComponentXmlElement getAndroidComponentXmlElement() { |
| 22 | + result.getResolvedComponentName() = this.getQualifiedName() |
| 23 | + } |
| 24 | + |
| 25 | + /** Holds if this Android component is configured as `exported` in an `AndroidManifest.xml` file. */ |
| 26 | + predicate isExported() { getAndroidComponentXmlElement().isExported() } |
| 27 | + |
| 28 | + /** Holds if this Android component has an intent filter configured in an `AndroidManifest.xml` file. */ |
| 29 | + predicate hasIntentFilter() { exists(getAndroidComponentXmlElement().getAnIntentFilterElement()) } |
| 30 | +} |
| 31 | + |
| 32 | +/** An Android activity. */ |
| 33 | +class AndroidActivity extends AndroidComponent { |
| 34 | + AndroidActivity() { this.getASupertype*().hasQualifiedName("android.app", "Activity") } |
| 35 | +} |
| 36 | + |
| 37 | +/** An Android service. */ |
| 38 | +class AndroidService extends AndroidComponent { |
| 39 | + AndroidService() { this.getASupertype*().hasQualifiedName("android.app", "Service") } |
| 40 | +} |
| 41 | + |
| 42 | +/** An Android broadcast receiver. */ |
| 43 | +class AndroidBroadcastReceiver extends AndroidComponent { |
| 44 | + AndroidBroadcastReceiver() { |
| 45 | + this.getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver") |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +/** An Android content provider. */ |
| 50 | +class AndroidContentProvider extends AndroidComponent { |
| 51 | + AndroidContentProvider() { |
| 52 | + this.getASupertype*().hasQualifiedName("android.content", "ContentProvider") |
| 53 | + } |
| 54 | +} |
0 commit comments