Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c6b7bb0 authored by Peter Kalauskas's avatar Peter Kalauskas Committed by Android (Google) Code Review
Browse files

Merge "Fix SystemUI lint checks" into main

parents 48059597 0de3277c
Loading
Loading
Loading
Loading
+4 −29
Original line number Diff line number Diff line
@@ -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",
            },
    ],
    },
}
+0 −1
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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,
+1 −19
Original line number Diff line number Diff line
@@ -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),
    )
+12 −14
Original line number Diff line number Diff line
@@ -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
}
Loading