diff --git a/android/sdk_version.go b/android/sdk_version.go index 9a3dce9de..7ace638b5 100644 --- a/android/sdk_version.go +++ b/android/sdk_version.go @@ -31,9 +31,9 @@ type SdkContext interface { // ReplaceMaxSdkVersionPlaceholder returns SdkSpec to replace the maxSdkVersion property of permission and // uses-permission tags if it is set. ReplaceMaxSdkVersionPlaceholder(ctx EarlyModuleContext) SdkSpec - // TargetSdkVersion returns the SdkSpec that corresponds to the target_sdk_version property of the current module, + // TargetSdkVersion returns the ApiLevel that corresponds to the target_sdk_version property of the current module, // or from sdk_version if it is not set. - TargetSdkVersion(ctx EarlyModuleContext) SdkSpec + TargetSdkVersion(ctx EarlyModuleContext) ApiLevel } // SdkKind represents a particular category of an SDK spec like public, system, test, etc. diff --git a/java/aar.go b/java/aar.go index 4e5ac1f36..f162a1722 100644 --- a/java/aar.go +++ b/java/aar.go @@ -725,8 +725,8 @@ func (a *AARImport) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleConte return android.SdkSpecFrom(ctx, "") } -func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { - return a.SdkVersion(ctx) +func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { + return a.SdkVersion(ctx).ApiLevel } func (a *AARImport) javaVersion() string { diff --git a/java/android_manifest.go b/java/android_manifest.go index f6457a096..dbcf09830 100644 --- a/java/android_manifest.go +++ b/java/android_manifest.go @@ -44,14 +44,14 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger", // When TARGET_BUILD_APPS is not empty, this method returns 10000 for modules targeting an unreleased SDK // This enables release builds (that run with TARGET_BUILD_APPS=[val...]) to target APIs that have not yet been finalized as part of an SDK func targetSdkVersionForManifestFixer(ctx android.ModuleContext, params ManifestFixerParams) string { - targetSdkVersionSpec := params.SdkContext.TargetSdkVersion(ctx) + targetSdkVersionLevel := params.SdkContext.TargetSdkVersion(ctx) // Check if we want to return 10000 // TODO(b/240294501): Determine the rules for handling test apexes - if shouldReturnFinalOrFutureInt(ctx, targetSdkVersionSpec, params.EnforceDefaultTargetSdkVersion) { + if shouldReturnFinalOrFutureInt(ctx, targetSdkVersionLevel, params.EnforceDefaultTargetSdkVersion) { return strconv.Itoa(android.FutureApiLevel.FinalOrFutureInt()) } - targetSdkVersion, err := targetSdkVersionSpec.EffectiveVersionString(ctx) + targetSdkVersion, err := targetSdkVersionLevel.EffectiveVersionString(ctx) if err != nil { ctx.ModuleErrorf("invalid targetSdkVersion: %s", err) } @@ -62,11 +62,11 @@ func targetSdkVersionForManifestFixer(ctx android.ModuleContext, params Manifest // 1. The module is built in unbundled mode (TARGET_BUILD_APPS not empty) // 2. The module is run as part of MTS, and should be testable on stable branches // Do not return 10000 if we are enforcing default targetSdkVersion and sdk has been finalised -func shouldReturnFinalOrFutureInt(ctx android.ModuleContext, targetSdkVersionSpec android.SdkSpec, enforceDefaultTargetSdkVersion bool) bool { +func shouldReturnFinalOrFutureInt(ctx android.ModuleContext, targetSdkVersionLevel android.ApiLevel, enforceDefaultTargetSdkVersion bool) bool { if enforceDefaultTargetSdkVersion && ctx.Config().PlatformSdkFinal() { return false } - return targetSdkVersionSpec.ApiLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module())) + return targetSdkVersionLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module())) } // Helper function that casts android.Module to java.androidTestApp diff --git a/java/app_test.go b/java/app_test.go index 5b16cea28..561be684e 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -3077,13 +3077,17 @@ func TestTargetSdkVersionManifestFixer(t *testing.T) { }, } for _, testCase := range testCases { + targetSdkVersionTemplate := "" + if testCase.targetSdkVersionInBp != "" { + targetSdkVersionTemplate = fmt.Sprintf(`target_sdk_version: "%s",`, testCase.targetSdkVersionInBp) + } bp := fmt.Sprintf(` android_app { name: "foo", sdk_version: "current", - target_sdk_version: "%v", + %s } - `, testCase.targetSdkVersionInBp) + `, targetSdkVersionTemplate) fixture := android.GroupFixturePreparers( prepareForJavaTest, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { @@ -3161,16 +3165,20 @@ func TestDefaultAppTargetSdkVersionForUpdatableModules(t *testing.T) { }, } for _, testCase := range testCases { + targetSdkVersionTemplate := "" + if testCase.targetSdkVersionInBp != nil { + targetSdkVersionTemplate = fmt.Sprintf(`target_sdk_version: "%s",`, *testCase.targetSdkVersionInBp) + } bp := fmt.Sprintf(` android_app { name: "foo", sdk_version: "current", min_sdk_version: "29", - target_sdk_version: "%v", + %s updatable: %t, enforce_default_target_sdk_version: %t } - `, proptools.String(testCase.targetSdkVersionInBp), testCase.updatable, testCase.updatable) // enforce default target sdk version if app is updatable + `, targetSdkVersionTemplate, testCase.updatable, testCase.updatable) // enforce default target sdk version if app is updatable fixture := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, diff --git a/java/base.go b/java/base.go index a3f6e3cd1..2d213a192 100644 --- a/java/base.go +++ b/java/base.go @@ -688,11 +688,11 @@ func (j *Module) MinSdkVersionString() string { return j.minSdkVersion.String() } -func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { +func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { if j.deviceProperties.Target_sdk_version != nil { - return android.SdkSpecFrom(ctx, *j.deviceProperties.Target_sdk_version) + return android.ApiLevelFrom(ctx, *j.deviceProperties.Target_sdk_version) } - return j.SdkVersion(ctx) + return j.SdkVersion(ctx).ApiLevel } func (j *Module) AvailableFor(what string) bool { @@ -1575,7 +1575,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...) j.linter.classes = j.implementationJarFile j.linter.minSdkVersion = lintSDKVersion(j.MinSdkVersion(ctx)) - j.linter.targetSdkVersion = lintSDKVersion(j.TargetSdkVersion(ctx).ApiLevel) + j.linter.targetSdkVersion = lintSDKVersion(j.TargetSdkVersion(ctx)) j.linter.compileSdkVersion = lintSDKVersion(j.SdkVersion(ctx).ApiLevel) j.linter.compileSdkKind = j.SdkVersion(ctx).Kind j.linter.javaLanguageLevel = flags.javaVersion.String() diff --git a/java/droiddoc.go b/java/droiddoc.go index 3e210088b..c5a957e26 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -256,8 +256,8 @@ func (j *Javadoc) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext return j.SdkVersion(ctx) } -func (j *Javadoc) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { - return j.SdkVersion(ctx) +func (j *Javadoc) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { + return j.SdkVersion(ctx).ApiLevel } func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { diff --git a/java/java.go b/java/java.go index 287bdace3..2a7e4e1bf 100644 --- a/java/java.go +++ b/java/java.go @@ -1905,8 +1905,8 @@ func (j *Import) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) return android.SdkSpecFrom(ctx, "") } -func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { - return j.SdkVersion(ctx) +func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { + return j.SdkVersion(ctx).ApiLevel } func (j *Import) Prebuilt() *android.Prebuilt { diff --git a/java/rro.go b/java/rro.go index 49737b946..6a9ad9aaa 100644 --- a/java/rro.go +++ b/java/rro.go @@ -186,8 +186,8 @@ func (r *RuntimeResourceOverlay) ReplaceMaxSdkVersionPlaceholder(ctx android.Ear return android.SdkSpecFrom(ctx, "") } -func (r *RuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { - return r.SdkVersion(ctx) +func (r *RuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { + return r.SdkVersion(ctx).ApiLevel } func (r *RuntimeResourceOverlay) Certificate() Certificate {