Support min_sdk_version overrides in apexes

The use case for this are go apexes which are only installed in T and
above, even though the base AOSP apexes might be installable on < T
devices.

If provided, the overridden min_sdk_version will be
1. Used as the `min_sdk_version` in the manifest file of the
   top-level override apex binary
2. Used to build the transitive closure of its dependency with that
   min_sdk_version, i.e. with a different apex variant.

(2) requires some special handling. At ToT, the outgoing transition
value is the base apex name (e.g. com.android.foo). Since
min_sdk_version of the overridding apex can be different than the
overridden apex, the base apex name is no longer sufficient. Instead,
transition to the name of the overriding apex com.mycompany.android.foo.
If deduping is possible, transitive deps will get deduped to
`apex_<min_sdk_version>` later.

Test: added a unit test
Test: in internal, modified min_sdk_version of com.google.android.go.art
locally, built BA and Go apexes, and used `aapt2 dump badging` to verify
that BA has minSdkVersion of 31 and Go has minSdkVersion of 33

Bug: 295311875

Change-Id: Ifbe123d1517fccbc0c058042b8a6eeb3609b6787
This commit is contained in:
Spandan Das
2024-05-13 18:29:45 +00:00
parent b9c58350ca
commit 50801e20a3
4 changed files with 121 additions and 27 deletions

View File

@@ -6463,7 +6463,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)
@@ -6843,7 +6843,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())
}
@@ -6851,7 +6851,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"]
@@ -8943,7 +8943,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)
}
@@ -11267,7 +11267,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
}
@@ -11571,3 +11571,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())
}