Merge "Enforce mainline modules to have latest target sdk version by default."

This commit is contained in:
Harshit Mahajan
2022-09-27 17:04:27 +00:00
committed by Gerrit Code Review
5 changed files with 244 additions and 30 deletions

View File

@@ -101,6 +101,15 @@ type appProperties struct {
PreventInstall bool `blueprint:"mutated"`
IsCoverageVariant bool `blueprint:"mutated"`
// It can be set to test the behaviour of default target sdk version.
// Only required when updatable: false. It is an error if updatable: true and this is false.
Enforce_default_target_sdk_version *bool
// If set, the targetSdkVersion for the target is set to the latest default API level.
// This would be by default false, unless updatable: true or
// enforce_default_target_sdk_version: true in which case this defaults to true.
EnforceDefaultTargetSdkVersion bool `blueprint:"mutated"`
// Whether this app is considered mainline updatable or not. When set to true, this will enforce
// additional rules to make sure an app can safely be updated. Default is false.
// Prefer using other specific properties if build behaviour must be changed; avoid using this
@@ -296,6 +305,18 @@ func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
} else {
ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
}
if !BoolDefault(a.appProperties.Enforce_default_target_sdk_version, true) {
ctx.PropertyErrorf("enforce_default_target_sdk_version", "Updatable apps must enforce default target sdk version")
}
// TODO(b/227460469) after all the modules removes the target sdk version, throw an error if the target sdk version is explicitly set.
if a.deviceProperties.Target_sdk_version == nil {
a.SetEnforceDefaultTargetSdkVersion(true)
}
}
if Bool(a.appProperties.Enforce_default_target_sdk_version) {
a.SetEnforceDefaultTargetSdkVersion(true)
}
a.checkPlatformAPI(ctx)
@@ -427,7 +448,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
a.aapt.defaultManifestVersion = android.DefaultUpdatableModuleVersion
}
a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts,
a.usesLibraryProperties.Exclude_uses_libs, aaptLinkFlags...)
a.usesLibraryProperties.Exclude_uses_libs, a.enforceDefaultTargetSdkVersion(), aaptLinkFlags...)
// apps manifests are handled by aapt, don't let Module see them
a.properties.Manifest = nil
@@ -865,6 +886,14 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) {
a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(ctx).String(), depsInfo)
}
func (a *AndroidApp) enforceDefaultTargetSdkVersion() bool {
return a.appProperties.EnforceDefaultTargetSdkVersion
}
func (a *AndroidApp) SetEnforceDefaultTargetSdkVersion(val bool) {
a.appProperties.EnforceDefaultTargetSdkVersion = val
}
func (a *AndroidApp) Updatable() bool {
return Bool(a.appProperties.Updatable)
}