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

Commit fec466ad authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Create an Android Lint rule to prevent creation of log enforcement vars" into main

parents 3ca44187 3d28fff0
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -300,6 +300,7 @@ android_app {
            "UseSparseArrays",
            "UseSparseArrays",
            "UseValueOf",
            "UseValueOf",
        ],
        ],
        extra_check_modules: ["BluetoothLintChecker"],
        baseline_filename: "lint-baseline.xml",
        baseline_filename: "lint-baseline.xml",
    },
    },


tools/lint/Android.bp

0 → 100644
+63 −0
Original line number Original line Diff line number Diff line
// Copyright (C) 2024 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

java_library_host {
    name: "BluetoothLintChecker",
    srcs: [
        "checks/src/**/*.java",
        "checks/src/**/*.kt",
    ],
    plugins: ["auto_service_plugin"],
    libs: [
        "auto_service_annotations",
        "lint_api",
    ],
    kotlincflags: ["-Xjvm-default=all"],
}

java_test_host {
    name: "BluetoothLintCheckerTest",
    team: "trendy_team_bluetooth",
    srcs: [
        "checks/tests/**/*.java",
        "checks/tests/**/*.kt",
    ],
    static_libs: [
        "BluetoothLintChecker",
        "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",
            },
        ],
    },
}

tools/lint/OWNERS

0 → 100644
+3 −0
Original line number Original line Diff line number Diff line
# Additional OWNERS for Bluetooth AndroidLint
licorne@google.com
salsavage@google.com

tools/lint/README.md

0 → 100644
+50 −0
Original line number Original line Diff line number Diff line
# Bluetooth Lint Checks for AOSP

Custom Android Lint checks are written here to be executed against Bluetooth
Java and Kotlin source code. These will appear as part of errorprone builds,
which are notably ran as part of pre/post-submit testing of Bluetooth code.

## How to run Bluetooth lint checks against the code base

While lint checks should be automatically run by Gerrit, you may want to run it manually on the
code base.

Step 1: Build the lint report:
```
m Bluetooth-lint
```

Step 2: Find your lint output:
```
croot;
find out/soong/.intermediates/packages/modules/Bluetooth/ -type f -name "*lint-report*" -print;
```

Or:
```
aninja -t query Bluetooth-lint
```

Step 3: Identify the lint report you want to view the results of, typically in the following format:
```
out/soong/.intermediates/packages/modules/Bluetooth/android/app/Bluetooth/android_common/<run-identifier>/lint/lint-report.html
```

Step 4: Open the file in your favorite web browser.

## How to run Bluetooth lint unit tests

Unit tests can be ran with the following command:
```
atest BluetoothLintCheckerTest --host
```

## Documentation

- [Android Lint Docs](https://googlesamples.github.io/android-custom-lint-rules/)
- [Custom lint creation example from Android SystemUI team](https://g3doc.corp.google.com/company/teams/android-sysui/general_guides/writing_a_linter.md?cl=head)
- [Lint Check Unit Testing](https://googlesamples.github.io/android-custom-lint-rules/api-guide/unit-testing.md.html)
- [Android Lint source files](https://source.corp.google.com/studio-main/tools/base/lint/libs/lint-api/src/main/java/com/android/tools/lint/)
- [PSI source files](https://github.com/JetBrains/intellij-community/tree/master/java/java-psi-api/src/com/intellij/psi)
- [UAST source files](https://upsource.jetbrains.com/idea-ce/structure/idea-ce-7b9b8cc138bbd90aec26433f82cd2c6838694003/uast/uast-common/src/org/jetbrains/uast)
- [IntelliJ plugin for viewing PSI tree of files](https://plugins.jetbrains.com/plugin/227-psiviewer)
+41 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.lint

import com.android.tools.lint.client.api.IssueRegistry
import com.android.tools.lint.client.api.Vendor
import com.android.tools.lint.detector.api.CURRENT_API
import com.google.auto.service.AutoService

@AutoService(IssueRegistry::class)
@Suppress("UnstableApiUsage")
class BluetoothLintCheckerIssueRegistry : IssueRegistry() {
    override val issues = listOf(LogEnforcementVariableCreationDetector.ISSUE)

    override val api: Int
        get() = CURRENT_API

    override val minApi: Int
        get() = 11

    override val vendor =
        Vendor(
            vendorName = "Android",
            feedbackUrl = "http://b/issues/new?component=27441",
            contact = "android-bluetooth@google.com"
        )
}
Loading