Skip to content

Commit f096868

Browse files
committed
Visit parcelable definitions in AidlDefinitionDetector
Fixes: 278871118 Test: UnstableAidlDefinitionDetectorTest Change-Id: I2dc194a2f532ebcfdc4ca948e2ce74958d2600cf
1 parent 5eba355 commit f096868

File tree

10 files changed

+676
-9
lines changed

10 files changed

+676
-9
lines changed

health/connect/connect-client/lint-baseline.xml

+207
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,96 @@
154154
file="src/main/java/androidx/health/platform/client/impl/ipc/internal/ServiceConnection.java"/>
155155
</issue>
156156

157+
<issue
158+
id="RequireUnstableAidlAnnotation"
159+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
160+
errorLine1="parcelable AggregateDataRequest;"
161+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
162+
<location
163+
file="src/main/aidl/androidx/health/platform/client/request/AggregateDataRequest.aidl"/>
164+
</issue>
165+
166+
<issue
167+
id="RequireUnstableAidlAnnotation"
168+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
169+
errorLine1="parcelable AggregateDataResponse;"
170+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
171+
<location
172+
file="src/main/aidl/androidx/health/platform/client/response/AggregateDataResponse.aidl"/>
173+
</issue>
174+
175+
<issue
176+
id="RequireUnstableAidlAnnotation"
177+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
178+
errorLine1="parcelable ChangesEvent;"
179+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~">
180+
<location
181+
file="src/main/aidl/androidx/health/platform/client/changes/ChangesEvent.aidl"/>
182+
</issue>
183+
184+
<issue
185+
id="RequireUnstableAidlAnnotation"
186+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
187+
errorLine1="parcelable DeleteDataRangeRequest;"
188+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
189+
<location
190+
file="src/main/aidl/androidx/health/platform/client/request/DeleteDataRangeRequest.aidl"/>
191+
</issue>
192+
193+
<issue
194+
id="RequireUnstableAidlAnnotation"
195+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
196+
errorLine1="parcelable DeleteDataRequest;"
197+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
198+
<location
199+
file="src/main/aidl/androidx/health/platform/client/request/DeleteDataRequest.aidl"/>
200+
</issue>
201+
202+
<issue
203+
id="RequireUnstableAidlAnnotation"
204+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
205+
errorLine1="parcelable ErrorStatus;"
206+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~">
207+
<location
208+
file="src/main/aidl/androidx/health/platform/client/error/ErrorStatus.aidl"/>
209+
</issue>
210+
211+
<issue
212+
id="RequireUnstableAidlAnnotation"
213+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
214+
errorLine1="parcelable GetChangesRequest;"
215+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
216+
<location
217+
file="src/main/aidl/androidx/health/platform/client/request/GetChangesRequest.aidl"/>
218+
</issue>
219+
220+
<issue
221+
id="RequireUnstableAidlAnnotation"
222+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
223+
errorLine1="parcelable GetChangesResponse;"
224+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
225+
<location
226+
file="src/main/aidl/androidx/health/platform/client/response/GetChangesResponse.aidl"/>
227+
</issue>
228+
229+
<issue
230+
id="RequireUnstableAidlAnnotation"
231+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
232+
errorLine1="parcelable GetChangesTokenRequest;"
233+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
234+
<location
235+
file="src/main/aidl/androidx/health/platform/client/request/GetChangesTokenRequest.aidl"/>
236+
</issue>
237+
238+
<issue
239+
id="RequireUnstableAidlAnnotation"
240+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
241+
errorLine1="parcelable GetChangesTokenResponse;"
242+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
243+
<location
244+
file="src/main/aidl/androidx/health/platform/client/response/GetChangesTokenResponse.aidl"/>
245+
</issue>
246+
157247
<issue
158248
id="RequireUnstableAidlAnnotation"
159249
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
@@ -370,6 +460,123 @@
370460
file="src/main/aidl/androidx/health/platform/client/service/IUpsertExerciseRouteCallback.aidl"/>
371461
</issue>
372462

463+
<issue
464+
id="RequireUnstableAidlAnnotation"
465+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
466+
errorLine1="parcelable InsertDataResponse;"
467+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
468+
<location
469+
file="src/main/aidl/androidx/health/platform/client/response/InsertDataResponse.aidl"/>
470+
</issue>
471+
472+
<issue
473+
id="RequireUnstableAidlAnnotation"
474+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
475+
errorLine1="parcelable Permission;"
476+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~">
477+
<location
478+
file="src/main/aidl/androidx/health/platform/client/permission/Permission.aidl"/>
479+
</issue>
480+
481+
<issue
482+
id="RequireUnstableAidlAnnotation"
483+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
484+
errorLine1="parcelable ReadDataRangeRequest;"
485+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
486+
<location
487+
file="src/main/aidl/androidx/health/platform/client/request/ReadDataRangeRequest.aidl"/>
488+
</issue>
489+
490+
<issue
491+
id="RequireUnstableAidlAnnotation"
492+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
493+
errorLine1="parcelable ReadDataRangeResponse;"
494+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
495+
<location
496+
file="src/main/aidl/androidx/health/platform/client/response/ReadDataRangeResponse.aidl"/>
497+
</issue>
498+
499+
<issue
500+
id="RequireUnstableAidlAnnotation"
501+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
502+
errorLine1="parcelable ReadDataRequest;"
503+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~">
504+
<location
505+
file="src/main/aidl/androidx/health/platform/client/request/ReadDataRequest.aidl"/>
506+
</issue>
507+
508+
<issue
509+
id="RequireUnstableAidlAnnotation"
510+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
511+
errorLine1="parcelable ReadDataResponse;"
512+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
513+
<location
514+
file="src/main/aidl/androidx/health/platform/client/response/ReadDataResponse.aidl"/>
515+
</issue>
516+
517+
<issue
518+
id="RequireUnstableAidlAnnotation"
519+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
520+
errorLine1="parcelable ReadExerciseRouteRequest;"
521+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
522+
<location
523+
file="src/main/aidl/androidx/health/platform/client/request/ReadExerciseRouteRequest.aidl"/>
524+
</issue>
525+
526+
<issue
527+
id="RequireUnstableAidlAnnotation"
528+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
529+
errorLine1="parcelable ReadExerciseRouteResponse;"
530+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
531+
<location
532+
file="src/main/aidl/androidx/health/platform/client/response/ReadExerciseRouteResponse.aidl"/>
533+
</issue>
534+
535+
<issue
536+
id="RequireUnstableAidlAnnotation"
537+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
538+
errorLine1="parcelable RegisterForDataNotificationsRequest;"
539+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
540+
<location
541+
file="src/main/aidl/androidx/health/platform/client/request/RegisterForDataNotificationsRequest.aidl"/>
542+
</issue>
543+
544+
<issue
545+
id="RequireUnstableAidlAnnotation"
546+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
547+
errorLine1="parcelable RequestContext;"
548+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~">
549+
<location
550+
file="src/main/aidl/androidx/health/platform/client/request/RequestContext.aidl"/>
551+
</issue>
552+
553+
<issue
554+
id="RequireUnstableAidlAnnotation"
555+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
556+
errorLine1="parcelable UnregisterFromDataNotificationsRequest;"
557+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
558+
<location
559+
file="src/main/aidl/androidx/health/platform/client/request/UnregisterFromDataNotificationsRequest.aidl"/>
560+
</issue>
561+
562+
<issue
563+
id="RequireUnstableAidlAnnotation"
564+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
565+
errorLine1="parcelable UpsertDataRequest;"
566+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
567+
<location
568+
file="src/main/aidl/androidx/health/platform/client/request/UpsertDataRequest.aidl"/>
569+
</issue>
570+
571+
<issue
572+
id="RequireUnstableAidlAnnotation"
573+
message="Unstable AIDL files must be annotated with `@RequiresOptIn` marker"
574+
errorLine1="parcelable UpsertExerciseRouteRequest;"
575+
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
576+
<location
577+
file="src/main/aidl/androidx/health/platform/client/request/UpsertExerciseRouteRequest.aidl"/>
578+
</issue>
579+
373580
<issue
374581
id="UnknownNullness"
375582
message="Unknown nullability; explicitly declare as `@Nullable` or `@NonNull` to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations"

lint-checks/src/main/java/androidx/build/lint/AndroidXIssueRegistry.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ class AndroidXIssueRegistry : IssueRegistry() {
7171
IgnoreClassLevelDetector.ISSUE,
7272
ExperimentalPropertyAnnotationDetector.ISSUE,
7373
BanRestrictToTestsScope.ISSUE,
74-
// Temporarily disable AIDL lint check due to b/278871118.
75-
// UnstableAidlAnnotationDetector.ISSUE,
74+
UnstableAidlAnnotationDetector.ISSUE,
7675
// MissingJvmDefaultWithCompatibilityDetector is intentionally left out of the
7776
// registry, see comments on the class for more details.
7877
BanVisibleForTestingParams.ISSUE,

lint-checks/src/main/java/androidx/build/lint/UnstableAidlAnnotationDetector.kt

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.build.lint.aidl.getLocation
2121
import androidx.com.android.tools.idea.lang.aidl.psi.AidlAnnotationElement
2222
import androidx.com.android.tools.idea.lang.aidl.psi.AidlDeclaration
2323
import androidx.com.android.tools.idea.lang.aidl.psi.AidlInterfaceDeclaration
24+
import androidx.com.android.tools.idea.lang.aidl.psi.AidlParcelableDeclaration
2425
import com.android.tools.lint.detector.api.Category
2526
import com.android.tools.lint.detector.api.Context
2627
import com.android.tools.lint.detector.api.Implementation
@@ -41,8 +42,20 @@ private const val JAVA_PASSTHROUGH = "JavaPassthrough"
4142

4243
class UnstableAidlAnnotationDetector : AidlDefinitionDetector() {
4344

45+
override fun visitAidlParcelableDeclaration(context: Context, node: AidlParcelableDeclaration) {
46+
checkDeclaration(context, node, node.annotationElementList)
47+
}
48+
4449
override fun visitAidlInterfaceDeclaration(context: Context, node: AidlInterfaceDeclaration) {
45-
var passthruAnnotations: List<AidlAnnotationElement> = node.annotationElementList.filter {
50+
checkDeclaration(context, node, node.annotationElementList)
51+
}
52+
53+
private fun checkDeclaration(
54+
context: Context,
55+
node: AidlDeclaration,
56+
annotations: List<AidlAnnotationElement>
57+
) {
58+
var passthruAnnotations: List<AidlAnnotationElement> = annotations.filter {
4659
annotationElement ->
4760
annotationElement.qualifiedName.name.equals(JAVA_PASSTHROUGH)
4861
}

lint-checks/src/main/java/androidx/build/lint/aidl/AidlDefinitionDetector.kt

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.com.android.tools.idea.lang.aidl.psi.AidlFile
2323
import androidx.com.android.tools.idea.lang.aidl.psi.AidlInterfaceDeclaration
2424
import androidx.com.android.tools.idea.lang.aidl.psi.AidlMethodDeclaration
2525
import androidx.com.android.tools.idea.lang.aidl.psi.AidlParcelableDeclaration
26+
import androidx.com.android.tools.idea.lang.aidl.psi.AidlUnionDeclaration
2627
import com.android.tools.lint.detector.api.Context
2728
import com.android.tools.lint.detector.api.Detector
2829
import com.android.tools.lint.detector.api.Location
@@ -72,10 +73,19 @@ abstract class AidlDefinitionDetector : Detector(), OtherFileScanner {
7273
when (aidlDeclaration) {
7374
is AidlInterfaceDeclaration ->
7475
visitAidlInterfaceDeclaration(context, aidlDeclaration)
75-
is AidlMethodDeclaration ->
76-
visitAidlMethodDeclaration(context, aidlDeclaration)
7776
is AidlParcelableDeclaration ->
7877
visitAidlParcelableDeclaration(context, aidlDeclaration)
78+
is AidlUnionDeclaration -> {
79+
listOf(
80+
aidlDeclaration.interfaceDeclarationList,
81+
aidlDeclaration.parcelableDeclarationList,
82+
aidlDeclaration.unionDeclarationList
83+
).forEach { declarationList ->
84+
declarationList.forEach { declaration ->
85+
visitAidlDeclaration(context, declaration)
86+
}
87+
}
88+
}
7989
}
8090
}
8191

lint-checks/src/test/java/androidx/build/lint/UnstableAidlAnnotationDetectorTest.kt

+25-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,31 @@ class UnstableAidlAnnotationDetectorTest : AbstractLintDetectorTest(
5858
}
5959

6060
@Test
61-
fun wrongAnnotation() {
61+
fun wrongAnnotationParcelable() {
62+
val input = aidl(
63+
"android/support/v4/os/ResultReceiver.aidl",
64+
"""
65+
package android.support.v4.os;
66+
67+
@JavaOnlyStableParcelable
68+
parcelable Receiver;
69+
""".trimIndent()
70+
)
71+
72+
/* ktlint-disable max-line-length */
73+
val expected = """
74+
src/main/aidl/android/support/v4/os/ResultReceiver.aidl:4: Error: Unstable AIDL files must be annotated with @RequiresOptIn marker [RequireUnstableAidlAnnotation]
75+
parcelable Receiver;
76+
~~~~~~~~~~~~~~~~~~~~
77+
1 errors, 0 warnings
78+
""".trimIndent()
79+
/* ktlint-enable max-line-length */
80+
81+
check(input).expect(expected)
82+
}
83+
84+
@Test
85+
fun wrongAnnotationInterface() {
6286
val input = arrayOf(
6387
java(
6488
"src/androidx/core/MyAnnotation.java",

0 commit comments

Comments
 (0)