Don't check project codename
project.minSdkVersion.codename is annotated @Nullable in java, but here in kotlin code it's passed to a non-null String. Soong is making a change that will no longer pass the codename to android lint, and cause it to have a null codename, and then this checker would crash. Checking the codename doesn't appear to be necessary in this case, checking the featureLevel should be enough. The difference between featureLevel and apiLevel is that featureLevel will be apiLevel+1 if a codename is set, so it should already have the codename logic built in. Bug: 215567981 Test: m lint-check with aosp/2072628 Change-Id: I003390021f0badfea3a79c8cf87d089d65a58e34
This commit is contained in:
@@ -48,18 +48,9 @@ class SaferParcelChecker : Detector(), SourceCodeScanner {
|
||||
return "$prefix$name($parameters)"
|
||||
}
|
||||
|
||||
/** Taken from androidx-main:core/core/src/main/java/androidx/core/os/BuildCompat.java */
|
||||
private fun isAtLeastT(context: Context): Boolean {
|
||||
val project = if (context.isGlobalAnalysis()) context.mainProject else context.project
|
||||
return project.isAndroidProject
|
||||
&& project.minSdkVersion.featureLevel >= 32
|
||||
&& isAtLeastPreReleaseCodename("Tiramisu", project.minSdkVersion.codename)
|
||||
}
|
||||
|
||||
/** Taken from androidx-main:core/core/src/main/java/androidx/core/os/BuildCompat.java */
|
||||
private fun isAtLeastPreReleaseCodename(min: String, actual: String): Boolean {
|
||||
if (actual == "REL") return false
|
||||
return actual.uppercase(Locale.ROOT) >= min.uppercase(Locale.ROOT)
|
||||
return project.isAndroidProject && project.minSdkVersion.featureLevel >= 33
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -729,7 +729,7 @@ class SaferParcelCheckerTest : LintDetectorTest() {
|
||||
|
||||
private val includes =
|
||||
arrayOf(
|
||||
manifest().minSdk("Tiramisu"),
|
||||
manifest().minSdk("33"),
|
||||
java(
|
||||
"""
|
||||
package android.os;
|
||||
|
||||
Reference in New Issue
Block a user