diff options
| author | 2024-04-15 10:41:23 -0700 | |
|---|---|---|
| committer | 2024-04-17 16:32:35 -0700 | |
| commit | 0de3277cbe0b7271f767cdbf91c5bff0306229eb (patch) | |
| tree | 78a14493d71c5a3d245464d99ec175926f0fb27f | |
| parent | 46f27a9cba3e1ef0f98554a202f05ffae23aad5e (diff) | |
Fix SystemUI lint checks
- Remove unnecessary @Supress and @Test annotations
- Rename test functions to start with "test" so they are picked up
correctly.
- Use "AndroidLintCheckerTestDefaults", simplifying Soong build rules,
remove unnecessary glob match for java files.
- Fix "moreInfo" go-link URL
- Use androidx.annotation_annotation-nodeps instead of
androidx.annotation_annotation to avoid pulling in unnecessary
dependencies.
- Remove unnecessary imports in tests
- Re-enable CleanArchitectureDependencyViolationDetectorTest
- Remove println
Flag: NONE
Bug: 334172345
Bug: 254533331
Test: atest SystemUILintCheckerTest --no-bazel-mode
Change-Id: I0758c38678fcbd2fa816a6017237c46827f2b89b
17 files changed, 81 insertions, 151 deletions
diff --git a/packages/SystemUI/checks/Android.bp b/packages/SystemUI/checks/Android.bp index 4cbc18c3a295..f65d797c5df8 100644 --- a/packages/SystemUI/checks/Android.bp +++ b/packages/SystemUI/checks/Android.bp @@ -24,10 +24,7 @@ package { java_library_host { name: "SystemUILintChecker", - srcs: [ - "src/**/*.kt", - "src/**/*.java", - ], + srcs: ["src/**/*.kt"], plugins: ["auto_service_plugin"], libs: [ "auto_service_annotations", @@ -38,35 +35,13 @@ java_library_host { java_test_host { name: "SystemUILintCheckerTest", - srcs: [ - "tests/**/*.kt", - "tests/**/*.java", - ], + defaults: ["AndroidLintCheckerTestDefaults"], + srcs: ["tests/**/*.kt"], data: [ ":framework", - ":androidx.annotation_annotation", + ":androidx.annotation_annotation-nodeps", ], static_libs: [ "SystemUILintChecker", - "junit", - "lint", - "lint_tests", ], - test_options: { - unit_test: true, - tradefed_options: [ - { - // lint bundles in some classes that were built with older versions - // of libraries, and no longer load. Since tradefed tries to load - // all classes in the jar to look for tests, it crashes loading them. - // Exclude these classes from tradefed's search. - name: "exclude-paths", - value: "org/apache", - }, - { - name: "exclude-paths", - value: "META-INF", - }, - ], - }, } diff --git a/packages/SystemUI/checks/src/com/android/internal/systemui/lint/DumpableNotRegisteredDetector.kt b/packages/SystemUI/checks/src/com/android/internal/systemui/lint/DumpableNotRegisteredDetector.kt index 30e2a2527a93..f9bf306b55fe 100644 --- a/packages/SystemUI/checks/src/com/android/internal/systemui/lint/DumpableNotRegisteredDetector.kt +++ b/packages/SystemUI/checks/src/com/android/internal/systemui/lint/DumpableNotRegisteredDetector.kt @@ -34,7 +34,6 @@ import org.jetbrains.uast.UClass * Checks if any class has implemented the `Dumpable` interface but has not registered itself with * the `DumpManager`. */ -@Suppress("UnstableApiUsage") class DumpableNotRegisteredDetector : Detector(), SourceCodeScanner { private var isDumpable: Boolean = false diff --git a/packages/SystemUI/checks/src/com/android/internal/systemui/lint/RegisterReceiverViaContextDetector.kt b/packages/SystemUI/checks/src/com/android/internal/systemui/lint/RegisterReceiverViaContextDetector.kt index 5840e8f8dfb6..024c3946b05e 100644 --- a/packages/SystemUI/checks/src/com/android/internal/systemui/lint/RegisterReceiverViaContextDetector.kt +++ b/packages/SystemUI/checks/src/com/android/internal/systemui/lint/RegisterReceiverViaContextDetector.kt @@ -59,7 +59,7 @@ class RegisterReceiverViaContextDetector : Detector(), SourceCodeScanner { `BroadcastDispatcher` instead, which registers the receiver on a \ background thread. `BroadcastDispatcher` also improves our visibility \ into ANRs.""", - moreInfo = "go/identifying-broadcast-threads", + moreInfo = "http://go/identifying-broadcast-threads", category = Category.PERFORMANCE, priority = 8, severity = Severity.WARNING, diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/AndroidStubs.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/AndroidStubs.kt index 141dd0535986..f3b24a35f91f 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/AndroidStubs.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/AndroidStubs.kt @@ -16,15 +16,8 @@ package com.android.internal.systemui.lint -import com.android.annotations.NonNull -import com.android.tools.lint.checks.infrastructure.LintDetectorTest.java import com.android.tools.lint.checks.infrastructure.TestFiles.LibraryReferenceTestFile import java.io.File -import org.intellij.lang.annotations.Language - -@Suppress("UnstableApiUsage") -@NonNull -private fun indentedJava(@NonNull @Language("JAVA") source: String) = java(source).indented() /* * This file contains stubs of framework APIs and System UI classes for testing purposes only. The @@ -33,16 +26,5 @@ private fun indentedJava(@NonNull @Language("JAVA") source: String) = java(sourc internal val androidStubs = arrayOf( LibraryReferenceTestFile(File("framework.jar").canonicalFile), - LibraryReferenceTestFile(File("androidx.annotation_annotation.jar").canonicalFile), - indentedJava( - """ -package com.android.systemui.settings; -import android.content.pm.UserInfo; - -public interface UserTracker { - int getUserId(); - UserInfo getUserInfo(); -} -""" - ), + LibraryReferenceTestFile(File("androidx.annotation_annotation-nodeps.jar").canonicalFile), ) diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/BindServiceOnMainThreadDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/BindServiceOnMainThreadDetectorTest.kt index 4c4185dc82f9..c9bc8b35a34b 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/BindServiceOnMainThreadDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/BindServiceOnMainThreadDetectorTest.kt @@ -19,17 +19,14 @@ package com.android.internal.systemui.lint import com.android.tools.lint.checks.infrastructure.TestFiles import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue -import org.junit.Ignore import org.junit.Test -@Suppress("UnstableApiUsage") class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = BindServiceOnMainThreadDetector() override fun getIssues(): List<Issue> = listOf(BindServiceOnMainThreadDetector.ISSUE) - @Ignore @Test fun testBindService() { lint() @@ -37,7 +34,9 @@ class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { TestFiles.java( """ package test.pkg; + import android.content.Context; + import android.content.Intent; public class TestClass { public void bind(Context context) { @@ -48,13 +47,13 @@ class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BindServiceOnMainThreadDetector.ISSUE) .run() .expect( """ - src/test/pkg/TestClass.java:7: Warning: This method should be annotated with @WorkerThread because it calls bindService [BindServiceOnMainThread] + src/test/pkg/TestClass.java:9: Warning: This method should be annotated with @WorkerThread because it calls bindService [BindServiceOnMainThread] context.bindService(intent, null, 0); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0 errors, 1 warnings @@ -62,7 +61,6 @@ class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { ) } - @Ignore @Test fun testBindServiceAsUser() { lint() @@ -70,7 +68,9 @@ class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { TestFiles.java( """ package test.pkg; + import android.content.Context; + import android.content.Intent; import android.os.UserHandle; public class TestClass { @@ -82,13 +82,13 @@ class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BindServiceOnMainThreadDetector.ISSUE) .run() .expect( """ - src/test/pkg/TestClass.java:8: Warning: This method should be annotated with @WorkerThread because it calls bindServiceAsUser [BindServiceOnMainThread] + src/test/pkg/TestClass.java:10: Warning: This method should be annotated with @WorkerThread because it calls bindServiceAsUser [BindServiceOnMainThread] context.bindServiceAsUser(intent, null, 0, UserHandle.ALL); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0 errors, 1 warnings @@ -114,7 +114,7 @@ class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BindServiceOnMainThreadDetector.ISSUE) .run() @@ -147,7 +147,7 @@ class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BindServiceOnMainThreadDetector.ISSUE) .run() @@ -181,7 +181,7 @@ class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BindServiceOnMainThreadDetector.ISSUE) .run() @@ -219,12 +219,10 @@ class BindServiceOnMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BindServiceOnMainThreadDetector.ISSUE) .run() .expectClean() } - - private val stubs = androidStubs } diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/BroadcastSentViaContextDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/BroadcastSentViaContextDetectorTest.kt index 30b68f7e7a75..3788dda7975f 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/BroadcastSentViaContextDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/BroadcastSentViaContextDetectorTest.kt @@ -21,7 +21,6 @@ import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue import org.junit.Test -@Suppress("UnstableApiUsage") class BroadcastSentViaContextDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = BroadcastSentViaContextDetector() @@ -30,7 +29,6 @@ class BroadcastSentViaContextDetectorTest : SystemUILintDetectorTest() { @Test fun testSendBroadcast() { - println(stubs.size) lint() .files( TestFiles.java( @@ -47,7 +45,7 @@ class BroadcastSentViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BroadcastSentViaContextDetector.ISSUE) .run() @@ -80,7 +78,7 @@ class BroadcastSentViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BroadcastSentViaContextDetector.ISSUE) .run() @@ -114,7 +112,7 @@ class BroadcastSentViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BroadcastSentViaContextDetector.ISSUE) .run() @@ -149,7 +147,7 @@ class BroadcastSentViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BroadcastSentViaContextDetector.ISSUE) .run() @@ -176,7 +174,7 @@ class BroadcastSentViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BroadcastSentViaContextDetector.ISSUE) .run() @@ -201,12 +199,10 @@ class BroadcastSentViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(BroadcastSentViaContextDetector.ISSUE) .run() .expectClean() } - - private val stubs = androidStubs } diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/CleanArchitectureDependencyViolationDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/CleanArchitectureDependencyViolationDetectorTest.kt index ff150c8cba13..2c2032123f05 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/CleanArchitectureDependencyViolationDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/CleanArchitectureDependencyViolationDetectorTest.kt @@ -21,11 +21,8 @@ import com.android.tools.lint.checks.infrastructure.TestFiles import com.android.tools.lint.checks.infrastructure.TestMode import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue -import org.junit.Ignore import org.junit.Test -@Suppress("UnstableApiUsage") -@Ignore("b/254533331") class CleanArchitectureDependencyViolationDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector { return CleanArchitectureDependencyViolationDetector() diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/DemotingTestWithoutBugDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/DemotingTestWithoutBugDetectorTest.kt index ee6e0ce72713..0652e6908cc6 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/DemotingTestWithoutBugDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/DemotingTestWithoutBugDetectorTest.kt @@ -24,7 +24,6 @@ import com.android.tools.lint.detector.api.Scope import java.util.EnumSet import org.junit.Test -@Suppress("UnstableApiUsage") class DemotingTestWithoutBugDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = DemotingTestWithoutBugDetector() diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/DumpableNotRegisteredDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/DumpableNotRegisteredDetectorTest.kt index 3d6cbc749569..6c6c26355ad9 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/DumpableNotRegisteredDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/DumpableNotRegisteredDetectorTest.kt @@ -21,7 +21,6 @@ import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue import org.junit.Test -@Suppress("UnstableApiUsage") class DumpableNotRegisteredDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = DumpableNotRegisteredDetector() @@ -37,7 +36,8 @@ class DumpableNotRegisteredDetectorTest : SystemUILintDetectorTest() { class SomeClass() { } - """.trimIndent() + """ + .trimIndent() ), *stubs, ) @@ -67,7 +67,8 @@ class DumpableNotRegisteredDetectorTest : SystemUILintDetectorTest() { pw.println("testDump"); } } - """.trimIndent() + """ + .trimIndent() ), *stubs, ) @@ -97,7 +98,8 @@ class DumpableNotRegisteredDetectorTest : SystemUILintDetectorTest() { pw.println("testDump"); } } - """.trimIndent() + """ + .trimIndent() ), *stubs, ) @@ -127,7 +129,8 @@ class DumpableNotRegisteredDetectorTest : SystemUILintDetectorTest() { pw.println("testDump"); } } - """.trimIndent() + """ + .trimIndent() ), *stubs, ) diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/NonInjectedMainThreadDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/NonInjectedMainThreadDetectorTest.kt index ed3d14a1f33f..bb34d917d326 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/NonInjectedMainThreadDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/NonInjectedMainThreadDetectorTest.kt @@ -21,7 +21,6 @@ import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue import org.junit.Test -@Suppress("UnstableApiUsage") class NonInjectedMainThreadDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = NonInjectedMainThreadDetector() @@ -46,7 +45,7 @@ class NonInjectedMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(NonInjectedMainThreadDetector.ISSUE) .run() @@ -79,7 +78,7 @@ class NonInjectedMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(NonInjectedMainThreadDetector.ISSUE) .run() @@ -104,7 +103,7 @@ class NonInjectedMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(NonInjectedMainThreadDetector.ISSUE) .run() @@ -136,7 +135,7 @@ class NonInjectedMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(NonInjectedMainThreadDetector.ISSUE) .run() @@ -149,6 +148,4 @@ class NonInjectedMainThreadDetectorTest : SystemUILintDetectorTest() { """ ) } - - private val stubs = androidStubs } diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/NonInjectedServiceDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/NonInjectedServiceDetectorTest.kt index 846129aa12c1..fe5b576c5d21 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/NonInjectedServiceDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/NonInjectedServiceDetectorTest.kt @@ -21,7 +21,6 @@ import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue import org.junit.Test -@Suppress("UnstableApiUsage") class NonInjectedServiceDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = NonInjectedServiceDetector() @@ -44,7 +43,7 @@ class NonInjectedServiceDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(NonInjectedServiceDetector.ISSUE) .run() @@ -76,7 +75,7 @@ class NonInjectedServiceDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(NonInjectedServiceDetector.ISSUE) .run() @@ -109,7 +108,7 @@ class NonInjectedServiceDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(NonInjectedServiceDetector.ISSUE) .run() @@ -134,7 +133,7 @@ class NonInjectedServiceDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(NonInjectedServiceDetector.ISSUE) .run() @@ -147,6 +146,4 @@ class NonInjectedServiceDetectorTest : SystemUILintDetectorTest() { """ ) } - - private val stubs = androidStubs } diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/RegisterReceiverViaContextDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/RegisterReceiverViaContextDetectorTest.kt index 0ac8f8e7c672..3f12569dfc61 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/RegisterReceiverViaContextDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/RegisterReceiverViaContextDetectorTest.kt @@ -21,7 +21,6 @@ import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue import org.junit.Test -@Suppress("UnstableApiUsage") class RegisterReceiverViaContextDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = RegisterReceiverViaContextDetector() @@ -35,9 +34,8 @@ class RegisterReceiverViaContextDetectorTest : SystemUILintDetectorTest() { TestFiles.java( """ package test.pkg; - import android.content.BroadcastReceiver; + import android.content.Context; - import android.content.IntentFilter; public class TestClass { public void bind(Context context, BroadcastReceiver receiver, @@ -48,13 +46,13 @@ class RegisterReceiverViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(RegisterReceiverViaContextDetector.ISSUE) .run() .expect( """ - src/test/pkg/TestClass.java:9: Warning: Register BroadcastReceiver using BroadcastDispatcher instead of Context [RegisterReceiverViaContext] + src/test/pkg/TestClass.java:8: Warning: Register BroadcastReceiver using BroadcastDispatcher instead of Context [RegisterReceiverViaContext] context.registerReceiver(receiver, filter, 0); ~~~~~~~~~~~~~~~~ 0 errors, 1 warnings @@ -69,9 +67,8 @@ class RegisterReceiverViaContextDetectorTest : SystemUILintDetectorTest() { TestFiles.java( """ package test.pkg; - import android.content.BroadcastReceiver; + import android.content.Context; - import android.content.IntentFilter; @SuppressWarnings("RegisterReceiverViaContext") public class TestClass { @@ -83,7 +80,7 @@ class RegisterReceiverViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(RegisterReceiverViaContextDetector.ISSUE) .run() @@ -97,11 +94,8 @@ class RegisterReceiverViaContextDetectorTest : SystemUILintDetectorTest() { TestFiles.java( """ package test.pkg; - import android.content.BroadcastReceiver; + import android.content.Context; - import android.content.IntentFilter; - import android.os.Handler; - import android.os.UserHandle; public class TestClass { public void bind(Context context, BroadcastReceiver receiver, @@ -113,13 +107,13 @@ class RegisterReceiverViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(RegisterReceiverViaContextDetector.ISSUE) .run() .expect( """ - src/test/pkg/TestClass.java:11: Warning: Register BroadcastReceiver using BroadcastDispatcher instead of Context [RegisterReceiverViaContext] + src/test/pkg/TestClass.java:8: Warning: Register BroadcastReceiver using BroadcastDispatcher instead of Context [RegisterReceiverViaContext] context.registerReceiverAsUser(receiver, UserHandle.ALL, filter, ~~~~~~~~~~~~~~~~~~~~~~ 0 errors, 1 warnings @@ -134,11 +128,8 @@ class RegisterReceiverViaContextDetectorTest : SystemUILintDetectorTest() { TestFiles.java( """ package test.pkg; - import android.content.BroadcastReceiver; + import android.content.Context; - import android.content.IntentFilter; - import android.os.Handler; - import android.os.UserHandle; public class TestClass { public void bind(Context context, BroadcastReceiver receiver, @@ -150,19 +141,17 @@ class RegisterReceiverViaContextDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(RegisterReceiverViaContextDetector.ISSUE) .run() .expect( """ - src/test/pkg/TestClass.java:11: Warning: Register BroadcastReceiver using BroadcastDispatcher instead of Context [RegisterReceiverViaContext] + src/test/pkg/TestClass.java:8: Warning: Register BroadcastReceiver using BroadcastDispatcher instead of Context [RegisterReceiverViaContext] context.registerReceiverForAllUsers(receiver, filter, "permission", ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0 errors, 1 warnings """ ) } - - private val stubs = androidStubs } diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SlowUserQueryDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SlowUserQueryDetectorTest.kt index 34a424918a79..7944ce3efe0f 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SlowUserQueryDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SlowUserQueryDetectorTest.kt @@ -21,7 +21,6 @@ import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue import org.junit.Test -@Suppress("UnstableApiUsage") class SlowUserQueryDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = SlowUserQueryDetector() @@ -182,5 +181,19 @@ class SlowUserQueryDetectorTest : SystemUILintDetectorTest() { .expectClean() } - private val stubs = androidStubs + private val stubs = + arrayOf( + *androidStubs, + java( + """ +package com.android.systemui.settings; +import android.content.pm.UserInfo; +public interface UserTracker { + int getUserId(); + UserInfo getUserInfo(); +} +""" + ) + .indented() + ) } diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SoftwareBitmapDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SoftwareBitmapDetectorTest.kt index 34becc6a5b04..756751c79e24 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SoftwareBitmapDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SoftwareBitmapDetectorTest.kt @@ -21,7 +21,6 @@ import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue import org.junit.Test -@Suppress("UnstableApiUsage") class SoftwareBitmapDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = SoftwareBitmapDetector() @@ -45,7 +44,7 @@ class SoftwareBitmapDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(SoftwareBitmapDetector.ISSUE) .run() @@ -80,7 +79,7 @@ class SoftwareBitmapDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(SoftwareBitmapDetector.ISSUE) .run() @@ -102,12 +101,10 @@ class SoftwareBitmapDetectorTest : SystemUILintDetectorTest() { } """ ), - *stubs + *androidStubs ) .issues(SoftwareBitmapDetector.ISSUE) .run() .expectClean() } - - private val stubs = androidStubs } diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/StaticSettingsProviderDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/StaticSettingsProviderDetectorTest.kt index efe4c90ec44f..fd0001818d17 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/StaticSettingsProviderDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/StaticSettingsProviderDetectorTest.kt @@ -21,7 +21,6 @@ import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue import org.junit.Test -@Suppress("UnstableApiUsage") class StaticSettingsProviderDetectorTest : SystemUILintDetectorTest() { override fun getDetector(): Detector = StaticSettingsProviderDetector() @@ -85,7 +84,7 @@ class StaticSettingsProviderDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(StaticSettingsProviderDetector.ISSUE) .run() @@ -226,12 +225,10 @@ class StaticSettingsProviderDetectorTest : SystemUILintDetectorTest() { """ ) .indented(), - *stubs + *androidStubs ) .issues(StaticSettingsProviderDetector.ISSUE) .run() .expectClean() } - - private val stubs = androidStubs } diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SystemUILintDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SystemUILintDetectorTest.kt index 3f93f075fe8b..29b3828c5c4b 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SystemUILintDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/SystemUILintDetectorTest.kt @@ -10,7 +10,6 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 import org.junit.runners.model.Statement -@Suppress("UnstableApiUsage") @RunWith(JUnit4::class) abstract class SystemUILintDetectorTest : LintDetectorTest() { @@ -18,7 +17,7 @@ abstract class SystemUILintDetectorTest : LintDetectorTest() { @ClassRule @JvmField val libraryChecker: LibraryExists = - LibraryExists("framework.jar", "androidx.annotation_annotation.jar") + LibraryExists("framework.jar", "androidx.annotation_annotation-nodeps.jar") } class LibraryExists(vararg val libraryNames: String) : TestRule { diff --git a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/TestFunctionNameViolationDetectorTest.kt b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/TestFunctionNameViolationDetectorTest.kt index db73154c02d9..a4e82a779de9 100644 --- a/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/TestFunctionNameViolationDetectorTest.kt +++ b/packages/SystemUI/checks/tests/com/android/internal/systemui/lint/TestFunctionNameViolationDetectorTest.kt @@ -18,28 +18,22 @@ package com.android.internal.systemui.lint import com.android.tools.lint.checks.infrastructure.TestFile +import com.android.tools.lint.checks.infrastructure.TestFiles import com.android.tools.lint.detector.api.Detector import com.android.tools.lint.detector.api.Issue import org.junit.Test -@Suppress("UnstableApiUsage") class TestFunctionNameViolationDetectorTest : SystemUILintDetectorTest() { - override fun getDetector(): Detector { - return TestFunctionNameViolationDetector() - } + override fun getDetector(): Detector = TestFunctionNameViolationDetector() - override fun getIssues(): List<Issue> { - return listOf( - TestFunctionNameViolationDetector.ISSUE, - ) - } + override fun getIssues(): List<Issue> = listOf(TestFunctionNameViolationDetector.ISSUE) @Test fun violations() { lint() .files( - kotlin( - """ + TestFiles.kotlin( + """ package test.pkg.name import org.junit.Test @@ -64,13 +58,11 @@ class TestFunctionNameViolationDetectorTest : SystemUILintDetectorTest() { } } """ - .trimIndent() - ), - testAnnotationStub, - ) - .issues( - TestFunctionNameViolationDetector.ISSUE, + ) + .indented(), + testAnnotationStub ) + .issues(TestFunctionNameViolationDetector.ISSUE) .run() .expectWarningCount(0) .expect( |