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

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

Merge changes Ifbe123d1,Ie2e738a6 into main

* changes:
  Support min_sdk_version overrides in apexes
  Support min_sdk_version overrides in apps
parents 9b9d29b8 50801e20
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -37,11 +37,7 @@ var (
// Accessible via `ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)`
type ApexInfo struct {
	// Name of the apex variation that this module (i.e. the apex variant of the module) is
	// mutated into, or "" for a platform (i.e. non-APEX) variant. Note that this name and the
	// Soong module name of the APEX can be different. That happens when there is
	// `override_apex` that overrides `apex`. In that case, both Soong modules have the same
	// apex variation name which usually is `com.android.foo`. This name is also the `name`
	// in the path `/apex/<name>` where this apex is activated on at runtime.
	// mutated into, or "" for a platform (i.e. non-APEX) variant.
	//
	// Also note that a module can be included in multiple APEXes, in which case, the module is
	// mutated into one or more variants, each of which is for an APEX. The variants then can
+24 −16
Original line number Diff line number Diff line
@@ -137,10 +137,6 @@ type apexBundleProperties struct {
	// Rust binaries with prefer_rlib:true add unnecessary dependencies.
	Unwanted_transitive_deps []string

	// The minimum SDK version that this APEX must support at minimum. This is usually set to
	// the SDK version that the APEX was first introduced.
	Min_sdk_version *string

	// Whether this APEX is considered updatable or not. When set to true, this will enforce
	// additional rules for making sure that the APEX is truly updatable. To be updatable,
	// min_sdk_version should be set as well. This will also disable the size optimizations like
@@ -388,6 +384,10 @@ type overridableProperties struct {

	// Trim against a specific Dynamic Common Lib APEX
	Trim_against *string

	// The minimum SDK version that this APEX must support at minimum. This is usually set to
	// the SDK version that the APEX was first introduced.
	Min_sdk_version *string
}

type apexBundle struct {
@@ -1035,6 +1035,11 @@ func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
	// be built for this apexBundle.

	apexVariationName := mctx.ModuleName() // could be com.android.foo
	if overridable, ok := mctx.Module().(android.OverridableModule); ok && overridable.GetOverriddenBy() != "" {
		// use the overridden name com.mycompany.android.foo
		apexVariationName = overridable.GetOverriddenBy()
	}

	a.properties.ApexVariationName = apexVariationName
	testApexes := []string{}
	if a.testApex {
@@ -1099,7 +1104,7 @@ func apexStrictUpdatibilityLintMutator(mctx android.TopDownMutatorContext) {
	if !mctx.Module().Enabled(mctx) {
		return
	}
	if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting() {
	if apex, ok := mctx.Module().(*apexBundle); ok && apex.checkStrictUpdatabilityLinting(mctx) {
		mctx.WalkDeps(func(child, parent android.Module) bool {
			// b/208656169 Do not propagate strict updatability linting to libcore/
			// These libs are available on the classpath during compilation
@@ -1193,8 +1198,9 @@ var (
	}
)

func (a *apexBundle) checkStrictUpdatabilityLinting() bool {
	return a.Updatable() && !android.InList(a.ApexVariationName(), skipStrictUpdatabilityLintAllowlist)
func (a *apexBundle) checkStrictUpdatabilityLinting(mctx android.TopDownMutatorContext) bool {
	// The allowlist contains the base apex name, so use that instead of the ApexVariationName
	return a.Updatable() && !android.InList(mctx.ModuleName(), skipStrictUpdatabilityLintAllowlist)
}

// apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use
@@ -1295,13 +1301,12 @@ type apexTransitionMutator struct{}
func (a *apexTransitionMutator) Split(ctx android.BaseModuleContext) []string {
	// apexBundle itself is mutated so that it and its dependencies have the same apex variant.
	if ai, ok := ctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
		return []string{ai.ApexVariationName()}
	} else if o, ok := ctx.Module().(*OverrideApex); ok {
		apexBundleName := o.GetOverriddenModuleName()
		if apexBundleName == "" {
			ctx.ModuleErrorf("base property is not set")
		if overridable, ok := ctx.Module().(android.OverridableModule); ok && overridable.GetOverriddenBy() != "" {
			return []string{overridable.GetOverriddenBy()}
		}
		return []string{apexBundleName}
		return []string{ai.ApexVariationName()}
	} else if _, ok := ctx.Module().(*OverrideApex); ok {
		return []string{ctx.ModuleName()}
	}
	return []string{""}
}
@@ -1314,9 +1319,12 @@ func (a *apexTransitionMutator) IncomingTransition(ctx android.IncomingTransitio
	if am, ok := ctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
		return android.IncomingApexTransition(ctx, incomingVariation)
	} else if ai, ok := ctx.Module().(ApexInfoMutator); ok {
		if overridable, ok := ctx.Module().(android.OverridableModule); ok && overridable.GetOverriddenBy() != "" {
			return overridable.GetOverriddenBy()
		}
		return ai.ApexVariationName()
	} else if o, ok := ctx.Module().(*OverrideApex); ok {
		return o.GetOverriddenModuleName()
	} else if _, ok := ctx.Module().(*OverrideApex); ok {
		return ctx.Module().Name()
	}

	return ""
@@ -2652,7 +2660,7 @@ func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string {
	// Only override the minSdkVersion value on Apexes which already specify
	// a min_sdk_version (it's optional for non-updatable apexes), and that its
	// min_sdk_version value is lower than the one to override with.
	minApiLevel := android.MinSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version))
	minApiLevel := android.MinSdkVersionFromValue(ctx, proptools.String(a.overridableProperties.Min_sdk_version))
	if minApiLevel.IsNone() {
		return ""
	}
+81 −5
Original line number Diff line number Diff line
@@ -6476,7 +6476,7 @@ func TestApexAvailable_ApexAvailableNameWithVersionCode(t *testing.T) {
		t.Errorf("expected to find defaultVersion %q; got %q", barExpectedDefaultVersion, barActualDefaultVersion)
	}

	overrideBarManifestRule := result.ModuleForTests("bar", "android_common_myoverrideapex_bar").Rule("apexManifestRule")
	overrideBarManifestRule := result.ModuleForTests("bar", "android_common_myoverrideapex_myoverrideapex").Rule("apexManifestRule")
	overrideBarActualDefaultVersion := overrideBarManifestRule.Args["default_version"]
	if overrideBarActualDefaultVersion != barExpectedDefaultVersion {
		t.Errorf("expected to find defaultVersion %q; got %q", barExpectedDefaultVersion, barActualDefaultVersion)
@@ -6856,7 +6856,7 @@ func TestOverrideApex(t *testing.T) {
	`, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"}))

	originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(android.OverridableModule)
	overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex").Module().(android.OverridableModule)
	overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_override_myapex").Module().(android.OverridableModule)
	if originalVariant.GetOverriddenBy() != "" {
		t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
	}
@@ -6864,7 +6864,7 @@ func TestOverrideApex(t *testing.T) {
		t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
	}

	module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex")
	module := ctx.ModuleForTests("myapex", "android_common_override_myapex_override_myapex")
	apexRule := module.Rule("apexRule")
	copyCmds := apexRule.Args["copy_commands"]

@@ -8956,7 +8956,7 @@ func TestAllowedFiles(t *testing.T) {
		t.Errorf("allowed_files_file: expected %q but got %q", expected, actual)
	}

	rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex").Rule("diffApexContentRule")
	rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_override_myapex").Rule("diffApexContentRule")
	if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual {
		t.Errorf("allowed_files_file: expected %q but got %q", expected, actual)
	}
@@ -11294,7 +11294,7 @@ func TestInstallationRulesForMultipleApexPrebuilts(t *testing.T) {
		variation := func(moduleName string) string {
			ret := "android_common_com.android.foo"
			if moduleName == "com.google.android.foo" {
				ret = "android_common_com.google.android.foo_com.android.foo"
				ret = "android_common_com.google.android.foo_com.google.android.foo"
			}
			return ret
		}
@@ -11598,3 +11598,79 @@ func TestMultiplePrebuiltsWithSameBase(t *testing.T) {
	android.AssertStringDoesContain(t, "not found", androidMk, "LOCAL_MODULE := etc_myfilename.myapex")
	android.AssertStringDoesContain(t, "not found", androidMk, "LOCAL_MODULE := etc_mysubdir_myfilename.myapex")
}

func TestApexMinSdkVersionOverride(t *testing.T) {
	checkMinSdkVersion := func(t *testing.T, module android.TestingModule, expectedMinSdkVersion string) {
		args := module.Rule("apexRule").Args
		optFlags := args["opt_flags"]
		if !strings.Contains(optFlags, "--min_sdk_version "+expectedMinSdkVersion) {
			t.Errorf("%s: Expected min_sdk_version=%s, got: %s", module.Module(), expectedMinSdkVersion, optFlags)
		}
	}

	checkHasDep := func(t *testing.T, ctx *android.TestContext, m android.Module, wantDep android.Module) {
		t.Helper()
		found := false
		ctx.VisitDirectDeps(m, func(dep blueprint.Module) {
			if dep == wantDep {
				found = true
			}
		})
		if !found {
			t.Errorf("Could not find a dependency from %v to %v\n", m, wantDep)
		}
	}

	ctx := testApex(t, `
		apex {
			name: "com.android.apex30",
			min_sdk_version: "30",
			key: "apex30.key",
			java_libs: ["javalib"],
		}

		java_library {
			name: "javalib",
			srcs: ["A.java"],
			apex_available: ["com.android.apex30"],
			min_sdk_version: "30",
			sdk_version: "current",
		}

		override_apex {
			name: "com.mycompany.android.apex30",
			base: "com.android.apex30",
		}

		override_apex {
			name: "com.mycompany.android.apex31",
			base: "com.android.apex30",
			min_sdk_version: "31",
		}

		apex_key {
			name: "apex30.key",
			public_key: "testkey.avbpubkey",
			private_key: "testkey.pem",
		}

	`, android.FixtureMergeMockFs(android.MockFS{
		"system/sepolicy/apex/com.android.apex30-file_contexts": nil,
	}),
	)

	baseModule := ctx.ModuleForTests("com.android.apex30", "android_common_com.android.apex30")
	checkMinSdkVersion(t, baseModule, "30")

	// Override module, but uses same min_sdk_version
	overridingModuleSameMinSdkVersion := ctx.ModuleForTests("com.android.apex30", "android_common_com.mycompany.android.apex30_com.mycompany.android.apex30")
	javalibApex30Variant := ctx.ModuleForTests("javalib", "android_common_apex30")
	checkMinSdkVersion(t, overridingModuleSameMinSdkVersion, "30")
	checkHasDep(t, ctx, overridingModuleSameMinSdkVersion.Module(), javalibApex30Variant.Module())

	// Override module, uses different min_sdk_version
	overridingModuleDifferentMinSdkVersion := ctx.ModuleForTests("com.android.apex30", "android_common_com.mycompany.android.apex31_com.mycompany.android.apex31")
	javalibApex31Variant := ctx.ModuleForTests("javalib", "android_common_apex31")
	checkMinSdkVersion(t, overridingModuleDifferentMinSdkVersion, "31")
	checkHasDep(t, ctx, overridingModuleDifferentMinSdkVersion.Module(), javalibApex31Variant.Module())
}
+1 −12
Original line number Diff line number Diff line
@@ -338,23 +338,12 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	a.generateJavaUsedByApex(ctx)
}

func (a *AndroidApp) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
	defaultMinSdkVersion := a.Module.MinSdkVersion(ctx)
	if proptools.Bool(a.appProperties.Updatable) {
		overrideApiLevel := android.MinSdkVersionFromValue(ctx, ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride())
		if !overrideApiLevel.IsNone() && overrideApiLevel.CompareTo(defaultMinSdkVersion) > 0 {
			return overrideApiLevel
		}
	}
	return defaultMinSdkVersion
}

func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
	if a.Updatable() {
		if !a.SdkVersion(ctx).Stable() {
			ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.SdkVersion(ctx))
		}
		if String(a.deviceProperties.Min_sdk_version) == "" {
		if String(a.overridableProperties.Min_sdk_version) == "" {
			ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
		}

+33 −46
Original line number Diff line number Diff line
@@ -4322,52 +4322,6 @@ func TestPrivappAllowlistAndroidMk(t *testing.T) {
	)
}

func TestApexGlobalMinSdkVersionOverride(t *testing.T) {
	result := android.GroupFixturePreparers(
		PrepareForTestWithJavaDefaultModules,
		android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
			variables.ApexGlobalMinSdkVersionOverride = proptools.StringPtr("Tiramisu")
		}),
	).RunTestWithBp(t, `
		android_app {
			name: "com.android.bar",
			srcs: ["a.java"],
			sdk_version: "current",
		}
		android_app {
			name: "com.android.foo",
			srcs: ["a.java"],
			sdk_version: "current",
			min_sdk_version: "S",
			updatable: true,
		}
		override_android_app {
			name: "com.android.go.foo",
			base: "com.android.foo",
		}
	`)
	foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer")
	fooOverride := result.ModuleForTests("com.android.foo", "android_common_com.android.go.foo").Rule("manifestFixer")
	bar := result.ModuleForTests("com.android.bar", "android_common").Rule("manifestFixer")

	android.AssertStringDoesContain(t,
		"expected manifest fixer to set com.android.bar minSdkVersion to S",
		bar.BuildParams.Args["args"],
		"--minSdkVersion  S",
	)
	android.AssertStringDoesContain(t,
		"com.android.foo: expected manifest fixer to set minSdkVersion to T",
		foo.BuildParams.Args["args"],
		"--minSdkVersion  T",
	)
	android.AssertStringDoesContain(t,
		"com.android.go.foo: expected manifest fixer to set minSdkVersion to T",
		fooOverride.BuildParams.Args["args"],
		"--minSdkVersion  T",
	)

}

func TestAppFlagsPackages(t *testing.T) {
	ctx := testApp(t, `
		android_app {
@@ -4492,3 +4446,36 @@ func TestAppStem(t *testing.T) {
		t.Errorf("Module output does not contain expected apk %s", "foo-new.apk")
	}
}

func TestAppMinSdkVersionOverride(t *testing.T) {
	result := android.GroupFixturePreparers(
		PrepareForTestWithJavaDefaultModules,
	).RunTestWithBp(t, `
		android_app {
			name: "com.android.foo",
			srcs: ["a.java"],
			sdk_version: "current",
			min_sdk_version: "31",
			updatable: true,
		}
		override_android_app {
			name: "com.android.go.foo",
			base: "com.android.foo",
			min_sdk_version: "33",
		}
	`)
	foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer")
	fooOverride := result.ModuleForTests("com.android.foo", "android_common_com.android.go.foo").Rule("manifestFixer")

	android.AssertStringDoesContain(t,
		"com.android.foo: expected manifest fixer to set minSdkVersion to T",
		foo.BuildParams.Args["args"],
		"--minSdkVersion  31",
	)
	android.AssertStringDoesContain(t,
		"com.android.go.foo: expected manifest fixer to set minSdkVersion to T",
		fooOverride.BuildParams.Args["args"],
		"--minSdkVersion  33",
	)

}
Loading