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

Commit f5d39065 authored by Spandan Das's avatar Spandan Das Committed by Gerrit Code Review
Browse files

Merge "Update target_sdk_version from SdkSpec to ApiLevel"

parents 45d47ae5 ca70fc40
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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.
+2 −2
Original line number Diff line number Diff line
@@ -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 {
+5 −5
Original line number Diff line number Diff line
@@ -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
+12 −4
Original line number Diff line number Diff line
@@ -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,
+4 −4
Original line number Diff line number Diff line
@@ -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()
Loading