Support min_sdk_version overrides in apps
This replaces the global override of min_sdk_version (via `APEX_GLOBAL_MIN_SDK_VERSION_OVERRIDE`) with an min_sdk_version override that can be set by each individual soong override_app. The use case for this are go apps which are only installed in T and above, even though the base AOSP apexes might be installable on < T devices. Test: added a unit test Bug: 295311875 Change-Id: Ie2e738a6786bb24417c675617f7c78358017c96c
This commit is contained in:
parent
229b0098bd
commit
b9c58350ca
5 changed files with 43 additions and 66 deletions
13
java/app.go
13
java/app.go
|
@ -360,23 +360,12 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
a.generateJavaUsedByApex(ctx)
|
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) {
|
func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
|
||||||
if a.Updatable() {
|
if a.Updatable() {
|
||||||
if !a.SdkVersion(ctx).Stable() {
|
if !a.SdkVersion(ctx).Stable() {
|
||||||
ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.SdkVersion(ctx))
|
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.")
|
ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
func TestAppFlagsPackages(t *testing.T) {
|
||||||
ctx := testApp(t, `
|
ctx := testApp(t, `
|
||||||
android_app {
|
android_app {
|
||||||
|
@ -4492,3 +4446,36 @@ func TestAppStem(t *testing.T) {
|
||||||
t.Errorf("Module output does not contain expected apk %s", "foo-new.apk")
|
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",
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
12
java/base.go
12
java/base.go
|
@ -229,10 +229,6 @@ type DeviceProperties struct {
|
||||||
// If the SDK kind is empty, it will be set to public.
|
// If the SDK kind is empty, it will be set to public.
|
||||||
Sdk_version *string
|
Sdk_version *string
|
||||||
|
|
||||||
// if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
|
|
||||||
// Defaults to sdk_version if not set. See sdk_version for possible values.
|
|
||||||
Min_sdk_version *string
|
|
||||||
|
|
||||||
// if not blank, set the maximum version of the sdk that the compiled artifacts will run against.
|
// if not blank, set the maximum version of the sdk that the compiled artifacts will run against.
|
||||||
// Defaults to empty string "". See sdk_version for possible values.
|
// Defaults to empty string "". See sdk_version for possible values.
|
||||||
Max_sdk_version *string
|
Max_sdk_version *string
|
||||||
|
@ -312,6 +308,10 @@ type OverridableProperties struct {
|
||||||
// Otherwise, both the overridden and the overriding modules will have the same output name, which
|
// Otherwise, both the overridden and the overriding modules will have the same output name, which
|
||||||
// can cause the duplicate output error.
|
// can cause the duplicate output error.
|
||||||
Stem *string
|
Stem *string
|
||||||
|
|
||||||
|
// if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
|
||||||
|
// Defaults to sdk_version if not set. See sdk_version for possible values.
|
||||||
|
Min_sdk_version *string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functionality common to Module and Import
|
// Functionality common to Module and Import
|
||||||
|
@ -738,8 +738,8 @@ func (j *Module) SystemModules() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
|
func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
|
||||||
if j.deviceProperties.Min_sdk_version != nil {
|
if j.overridableProperties.Min_sdk_version != nil {
|
||||||
return android.ApiLevelFrom(ctx, *j.deviceProperties.Min_sdk_version)
|
return android.ApiLevelFrom(ctx, *j.overridableProperties.Min_sdk_version)
|
||||||
}
|
}
|
||||||
return j.SdkVersion(ctx).ApiLevel
|
return j.SdkVersion(ctx).ApiLevel
|
||||||
}
|
}
|
||||||
|
|
|
@ -909,7 +909,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
|
||||||
// Check min_sdk_version of the transitive dependencies if this module is created from
|
// Check min_sdk_version of the transitive dependencies if this module is created from
|
||||||
// java_sdk_library.
|
// java_sdk_library.
|
||||||
if j.deviceProperties.Min_sdk_version != nil && j.SdkLibraryName() != nil {
|
if j.overridableProperties.Min_sdk_version != nil && j.SdkLibraryName() != nil {
|
||||||
j.CheckDepsMinSdkVersion(ctx)
|
j.CheckDepsMinSdkVersion(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1097,7 +1097,7 @@ func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberCo
|
||||||
|
|
||||||
// If the min_sdk_version was set then add the canonical representation of the API level to the
|
// If the min_sdk_version was set then add the canonical representation of the API level to the
|
||||||
// snapshot.
|
// snapshot.
|
||||||
if j.deviceProperties.Min_sdk_version != nil {
|
if j.overridableProperties.Min_sdk_version != nil {
|
||||||
canonical, err := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String())
|
canonical, err := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ModuleErrorf("%s", err)
|
ctx.ModuleErrorf("%s", err)
|
||||||
|
|
|
@ -1842,6 +1842,7 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext)
|
||||||
&module.dexProperties,
|
&module.dexProperties,
|
||||||
&module.dexpreoptProperties,
|
&module.dexpreoptProperties,
|
||||||
&module.linter.properties,
|
&module.linter.properties,
|
||||||
|
&module.overridableProperties,
|
||||||
&props,
|
&props,
|
||||||
module.sdkComponentPropertiesForChildLibrary(),
|
module.sdkComponentPropertiesForChildLibrary(),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue