@@ -3,8 +3,6 @@ private import semmle.code.java.dataflow.DataFlow
3
3
private import semmle.code.java.dataflow.ExternalFlow
4
4
private import semmle.code.java.dataflow.FlowSteps
5
5
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.
8
6
/**
9
7
* The class `android.content.Intent`.
10
8
*/
@@ -66,21 +64,13 @@ class AndroidReceiveIntentMethod extends Method {
66
64
}
67
65
}
68
66
69
- // ! not sure if I like the name of the below class, but
70
- // ! trying to be consistent with `AndroidReceiveIntentMethod`
71
- // ! and `AndroidGetIntentMethod`...
72
67
/**
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`.
76
70
*/
77
71
class AndroidServiceIntentMethod extends Method {
78
72
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
84
74
this .getDeclaringType ( ) instanceof TypeService
85
75
}
86
76
}
@@ -127,20 +117,13 @@ class SendBroadcastMethod extends Method {
127
117
}
128
118
}
129
119
130
- // ! remove reference from below QLDoc?
131
120
/**
132
121
* The method `Context.startService`, `startForegroundService`,
133
122
* `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()."
137
123
*/
138
124
class StartServiceMethod extends Method {
139
125
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
144
127
this .getDeclaringType ( ) instanceof TypeContext
145
128
}
146
129
}
@@ -254,25 +237,6 @@ class GrantWriteUriPermissionFlag extends GrantUriPermissionFlag {
254
237
GrantWriteUriPermissionFlag ( ) { this .hasName ( "FLAG_GRANT_WRITE_URI_PERMISSION" ) }
255
238
}
256
239
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
- // }
276
240
/*
277
241
* // ! TODO: create a parent class for the below three steps?
278
242
* // ! e.g. something like the below?
@@ -283,9 +247,13 @@ class GrantWriteUriPermissionFlag extends GrantUriPermissionFlag {
283
247
* // class StartComponentIntentStep extends AdditionalValueStep { }
284
248
*/
285
249
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
+ */
289
257
private Argument getClassArgOfIntentConstructor ( ClassInstanceExpr classInstanceExpr ) {
290
258
classInstanceExpr .getConstructedType ( ) instanceof TypeIntent and
291
259
if classInstanceExpr .getNumArgument ( ) = 2
@@ -298,9 +266,13 @@ private Argument getClassArgOfIntentConstructor(ClassInstanceExpr classInstanceE
298
266
* a `getIntent` call in the Activity the Intent pointed to in its constructor.
299
267
*/
300
268
private 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
+ */
304
276
private Argument getIntentArgOfStartActMethod ( MethodAccess methodAccess ) {
305
277
methodAccess .getMethod ( ) .overrides * ( any ( StartActivityMethod m ) ) and
306
278
if
@@ -310,15 +282,6 @@ private class StartActivityIntentStep extends AdditionalValueStep {
310
282
else result = methodAccess .getArgument ( 0 )
311
283
}
312
284
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
- // }
322
285
override predicate step ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
323
286
exists ( MethodAccess startActivity , MethodAccess getIntent , ClassInstanceExpr newIntent |
324
287
startActivity .getMethod ( ) .overrides * ( any ( StartActivityMethod m ) ) and
@@ -353,7 +316,6 @@ private class SendBroadcastReceiverIntentStep extends AdditionalValueStep {
353
316
}
354
317
}
355
318
356
- // ! potentially reword QLDoc
357
319
/**
358
320
* A value-preserving step from the Intent argument of a `startService` call to
359
321
* the `Intent` parameter in an `AndroidServiceIntentMethod` of the Service the
0 commit comments