@@ -3,8 +3,6 @@ private import semmle.code.java.dataflow.DataFlow
33private import semmle.code.java.dataflow.ExternalFlow
44private import semmle.code.java.dataflow.FlowSteps
55
6- // ! Remember to add 'private' annotation as needed to new classes/predicates below.
7- // ! and clean-up comments, etc. in below in general before marking as ready-for-review.
86/**
97 * The class `android.content.Intent`.
108 */
@@ -66,21 +64,13 @@ class AndroidReceiveIntentMethod extends Method {
6664 }
6765}
6866
69- // ! not sure if I like the name of the below class, but
70- // ! trying to be consistent with `AndroidReceiveIntentMethod`
71- // ! and `AndroidGetIntentMethod`...
7267/**
73- * A method of type Service that receives an Intent.
74- * Namely, `Service.onStart`, `onStartCommand`, `onBind`,
75- * `onRebind`, `onUnbind`, or `onTaskRemoved`
68+ * The method `Service.onStart`, `onStartCommand`,
69+ * `onBind`, `onRebind`, `onUnbind`, or `onTaskRemoved`.
7670 */
7771class AndroidServiceIntentMethod extends Method {
7872 AndroidServiceIntentMethod ( ) {
79- (
80- this .getName ( ) .matches ( "onStart%" ) or
81- this .getName ( ) .matches ( "on%ind" ) or
82- this .hasName ( "onTaskRemoved" )
83- ) and
73+ this .getName ( ) .matches ( [ "onStart%" , "on%ind" , "onTaskRemoved" ] ) and
8474 this .getDeclaringType ( ) instanceof TypeService
8575 }
8676}
@@ -127,20 +117,13 @@ class SendBroadcastMethod extends Method {
127117 }
128118}
129119
130- // ! remove reference from below QLDoc?
131120/**
132121 * The method `Context.startService`, `startForegroundService`,
133122 * `bindIsolatedService`, `bindService`, or `bindServiceAsUser`.
134- *
135- * From https://developer.android.com/reference/android/app/Service:
136- * "Services can be started with Context.startService() and Context.bindService()."
137123 */
138124class StartServiceMethod extends Method {
139125 StartServiceMethod ( ) {
140- (
141- this .getName ( ) .matches ( "start%Service" ) or
142- this .getName ( ) .matches ( "bind%Service%" )
143- ) and
126+ this .getName ( ) .matches ( [ "start%Service" , "bind%Service%" ] ) and
144127 this .getDeclaringType ( ) instanceof TypeContext
145128 }
146129}
@@ -254,25 +237,6 @@ class GrantWriteUriPermissionFlag extends GrantUriPermissionFlag {
254237 GrantWriteUriPermissionFlag ( ) { this .hasName ( "FLAG_GRANT_WRITE_URI_PERMISSION" ) }
255238}
256239
257- // ! OLD VERSION - need to delete - keeping for now for reference
258- // /**
259- // * A value-preserving step from the Intent argument of a `startActivity` call to
260- // * a `getIntent` call in the Activity the Intent pointed to in its constructor.
261- // */
262- // private class StartActivityIntentStep extends AdditionalValueStep {
263- // override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
264- // exists(MethodAccess startActivity, MethodAccess getIntent, ClassInstanceExpr newIntent |
265- // startActivity.getMethod().overrides*(any(ContextStartActivityMethod m)) and
266- // getIntent.getMethod().overrides*(any(AndroidGetIntentMethod m)) and
267- // newIntent.getConstructedType() instanceof TypeIntent and
268- // DataFlow::localExprFlow(newIntent, startActivity.getArgument(0)) and
269- // newIntent.getArgument(1).getType().(ParameterizedType).getATypeArgument() =
270- // getIntent.getReceiverType() and
271- // n1.asExpr() = startActivity.getArgument(0) and
272- // n2.asExpr() = getIntent
273- // )
274- // }
275- // }
276240/*
277241 * // ! TODO: create a parent class for the below three steps?
278242 * // ! e.g. something like the below?
@@ -283,9 +247,13 @@ class GrantWriteUriPermissionFlag extends GrantUriPermissionFlag {
283247 * // class StartComponentIntentStep extends AdditionalValueStep { }
284248 */
285249
286- // The `android.Content.Intent` class has two constructors with an argument of type
287- // `Class<?>`. One has the argument at position 1 and the other at position 3.
288- // https://developer.android.com/reference/android/content/Intent#public-constructors
250+ /**
251+ * Gets the `Class<?>` argument of an `android.content.Intent`constructor.
252+ *
253+ * The `android.content.Intent` class has two constructors with an argument of type
254+ * `Class<?>`. One has the argument at position 1 and the other at position 3.
255+ * https://developer.android.com/reference/android/content/Intent#public-constructors
256+ */
289257private Argument getClassArgOfIntentConstructor ( ClassInstanceExpr classInstanceExpr ) {
290258 classInstanceExpr .getConstructedType ( ) instanceof TypeIntent and
291259 if classInstanceExpr .getNumArgument ( ) = 2
@@ -298,9 +266,13 @@ private Argument getClassArgOfIntentConstructor(ClassInstanceExpr classInstanceE
298266 * a `getIntent` call in the Activity the Intent pointed to in its constructor.
299267 */
300268private class StartActivityIntentStep extends AdditionalValueStep {
301- // The `startActivityFromChild` and `startActivityFromFragment` methods have
302- // an argument of type `Intent` at position 1, but the rest of the methods of
303- // type `StartActivityMethod` have an argument of type `Intent` at position 0.
269+ /**
270+ * Gets the `Intent` argument of an Android `StartActivityMethod`.
271+ *
272+ * The `startActivityFromChild` and `startActivityFromFragment` methods have
273+ * an argument of type `Intent` at position 1, but the rest of the methods of
274+ * type `StartActivityMethod` have an argument of type `Intent` at position 0.
275+ */
304276 private Argument getIntentArgOfStartActMethod ( MethodAccess methodAccess ) {
305277 methodAccess .getMethod ( ) .overrides * ( any ( StartActivityMethod m ) ) and
306278 if
@@ -310,15 +282,6 @@ private class StartActivityIntentStep extends AdditionalValueStep {
310282 else result = methodAccess .getArgument ( 0 )
311283 }
312284
313- // // The `android.Content.Intent` class has two constructors with an argument of type
314- // // `Class<?>`. One has the argument at position 1 and the other at position 3.
315- // // https://developer.android.com/reference/android/content/Intent#public-constructors
316- // private Argument getClassArgOfIntentConstructor(ClassInstanceExpr classInstanceExpr) {
317- // classInstanceExpr.getConstructedType() instanceof TypeIntent and
318- // if classInstanceExpr.getNumArgument() = 2
319- // then result = classInstanceExpr.getArgument(1)
320- // else result = classInstanceExpr.getArgument(3)
321- // }
322285 override predicate step ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
323286 exists ( MethodAccess startActivity , MethodAccess getIntent , ClassInstanceExpr newIntent |
324287 startActivity .getMethod ( ) .overrides * ( any ( StartActivityMethod m ) ) and
@@ -353,7 +316,6 @@ private class SendBroadcastReceiverIntentStep extends AdditionalValueStep {
353316 }
354317}
355318
356- // ! potentially reword QLDoc
357319/**
358320 * A value-preserving step from the Intent argument of a `startService` call to
359321 * the `Intent` parameter in an `AndroidServiceIntentMethod` of the Service the
0 commit comments