Loading android/apex.go +13 −0 Original line number Diff line number Diff line Loading @@ -934,6 +934,19 @@ func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayl }) } // Construct ApiLevel object from min_sdk_version string value func MinSdkVersionFromValue(ctx EarlyModuleContext, value string) ApiLevel { if value == "" { return NoneApiLevel } apiLevel, err := ApiLevelFromUser(ctx, value) if err != nil { ctx.PropertyErrorf("min_sdk_version", "%s", err.Error()) return NoneApiLevel } return apiLevel } // Implemented by apexBundle. type ApexTestInterface interface { // Return true if the apex bundle is an apex_test Loading apex/apex.go +3 −16 Original line number Diff line number Diff line Loading @@ -2730,13 +2730,13 @@ 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 := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version)) minApiLevel := android.MinSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version)) if minApiLevel.IsNone() { return "" } overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride() overrideApiLevel := minSdkVersionFromValue(ctx, overrideMinSdkValue) overrideApiLevel := android.MinSdkVersionFromValue(ctx, overrideMinSdkValue) if !overrideApiLevel.IsNone() && overrideApiLevel.CompareTo(minApiLevel) > 0 { minApiLevel = overrideApiLevel } Loading @@ -2751,20 +2751,7 @@ func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLe // Returns apex's min_sdk_version ApiLevel, honoring overrides func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { return minSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx)) } // Construct ApiLevel object from min_sdk_version string value func minSdkVersionFromValue(ctx android.EarlyModuleContext, value string) android.ApiLevel { if value == "" { return android.NoneApiLevel } apiLevel, err := android.ApiLevelFromUser(ctx, value) if err != nil { ctx.PropertyErrorf("min_sdk_version", "%s", err.Error()) return android.NoneApiLevel } return apiLevel return android.MinSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx)) } // Ensures that a lib providing stub isn't statically linked Loading java/app.go +11 −0 Original line number Diff line number Diff line Loading @@ -316,6 +316,17 @@ 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() { Loading java/app_test.go +46 −0 Original line number Diff line number Diff line Loading @@ -4137,3 +4137,49 @@ func TestPrivappAllowlistAndroidMk(t *testing.T) { "\\S+soong/.intermediates/foo/android_common_bar/privapp_allowlist_com.google.android.foo.xml:\\S+/target/product/test_device/system/etc/permissions/bar.xml", ) } 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", ) } Loading
android/apex.go +13 −0 Original line number Diff line number Diff line Loading @@ -934,6 +934,19 @@ func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayl }) } // Construct ApiLevel object from min_sdk_version string value func MinSdkVersionFromValue(ctx EarlyModuleContext, value string) ApiLevel { if value == "" { return NoneApiLevel } apiLevel, err := ApiLevelFromUser(ctx, value) if err != nil { ctx.PropertyErrorf("min_sdk_version", "%s", err.Error()) return NoneApiLevel } return apiLevel } // Implemented by apexBundle. type ApexTestInterface interface { // Return true if the apex bundle is an apex_test Loading
apex/apex.go +3 −16 Original line number Diff line number Diff line Loading @@ -2730,13 +2730,13 @@ 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 := minSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version)) minApiLevel := android.MinSdkVersionFromValue(ctx, proptools.String(a.properties.Min_sdk_version)) if minApiLevel.IsNone() { return "" } overrideMinSdkValue := ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride() overrideApiLevel := minSdkVersionFromValue(ctx, overrideMinSdkValue) overrideApiLevel := android.MinSdkVersionFromValue(ctx, overrideMinSdkValue) if !overrideApiLevel.IsNone() && overrideApiLevel.CompareTo(minApiLevel) > 0 { minApiLevel = overrideApiLevel } Loading @@ -2751,20 +2751,7 @@ func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLe // Returns apex's min_sdk_version ApiLevel, honoring overrides func (a *apexBundle) minSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { return minSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx)) } // Construct ApiLevel object from min_sdk_version string value func minSdkVersionFromValue(ctx android.EarlyModuleContext, value string) android.ApiLevel { if value == "" { return android.NoneApiLevel } apiLevel, err := android.ApiLevelFromUser(ctx, value) if err != nil { ctx.PropertyErrorf("min_sdk_version", "%s", err.Error()) return android.NoneApiLevel } return apiLevel return android.MinSdkVersionFromValue(ctx, a.minSdkVersionValue(ctx)) } // Ensures that a lib providing stub isn't statically linked Loading
java/app.go +11 −0 Original line number Diff line number Diff line Loading @@ -316,6 +316,17 @@ 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() { Loading
java/app_test.go +46 −0 Original line number Diff line number Diff line Loading @@ -4137,3 +4137,49 @@ func TestPrivappAllowlistAndroidMk(t *testing.T) { "\\S+soong/.intermediates/foo/android_common_bar/privapp_allowlist_com.google.android.foo.xml:\\S+/target/product/test_device/system/etc/permissions/bar.xml", ) } 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", ) }