Enforce newapi check only if min_sdk_version < compile_sdk_version

- NewApi check should be enforced only if min_sdk_version is less than
  the compile_sdk_version (the opposite direction should be a different
  build-time error)
- Change the datatype of *sdkVersion to android.ApiLevel (from string)
  to support version comparisons

Test: go build ./java
Test: no changes in ninja file
Bug: 228956345

Change-Id: Ic408857db7760d912ef4694d2ed72c0b7106eb04
This commit is contained in:
Spandan Das
2022-04-22 17:28:25 +00:00
parent 77b99b097b
commit ba7e532a11
2 changed files with 12 additions and 12 deletions

View File

@@ -75,9 +75,9 @@ type linter struct {
extraLintCheckJars android.Paths
test bool
library bool
minSdkVersion string
targetSdkVersion string
compileSdkVersion string
minSdkVersion android.ApiLevel
targetSdkVersion android.ApiLevel
compileSdkVersion android.ApiLevel
compileSdkKind android.SdkKind
javaLanguageLevel string
kotlinLanguageLevel string
@@ -300,7 +300,7 @@ func (l *linter) generateManifest(ctx android.ModuleContext, rule *android.RuleB
Text(`echo "<manifest xmlns:android='http://schemas.android.com/apk/res/android'" &&`).
Text(`echo " android:versionCode='1' android:versionName='1' >" &&`).
Textf(`echo " <uses-sdk android:minSdkVersion='%s' android:targetSdkVersion='%s'/>" &&`,
l.minSdkVersion, l.targetSdkVersion).
l.minSdkVersion.String(), l.targetSdkVersion.String()).
Text(`echo "</manifest>"`).
Text(") >").Output(manifestPath)
@@ -325,7 +325,7 @@ func (l *linter) lint(ctx android.ModuleContext) {
return
}
if l.minSdkVersion != l.compileSdkVersion {
if l.minSdkVersion.CompareTo(l.compileSdkVersion) == -1 {
l.extraMainlineLintErrors = append(l.extraMainlineLintErrors, updatabilityChecks...)
_, filtered := android.FilterList(l.properties.Lint.Warning_checks, updatabilityChecks)
if len(filtered) != 0 {
@@ -427,7 +427,7 @@ func (l *linter) lint(ctx android.ModuleContext) {
FlagWithOutput("--html ", html).
FlagWithOutput("--text ", text).
FlagWithOutput("--xml ", xml).
FlagWithArg("--compile-sdk-version ", l.compileSdkVersion).
FlagWithArg("--compile-sdk-version ", l.compileSdkVersion.String()).
FlagWithArg("--java-language-level ", l.javaLanguageLevel).
FlagWithArg("--kotlin-language-level ", l.kotlinLanguageLevel).
FlagWithArg("--url ", fmt.Sprintf(".=.,%s=out", android.PathForOutput(ctx).String())).