Update max_sdk_version from SdkSpec to ApiLevel

max_sdk_version signifies device version and does not need an sdkKind to
describe it fully. Update the type and cleanup existing usages. As a
side benefit, we also get better error handling since users can no
longer enter something like `public_30` as a valid max_sdk_version in bp
files

Bug: 208456999
Test: no change in ninja file (this should be a no-op)
Test: TH
Change-Id: I304b5ad802bde200137d8e225182828dfd6f7227
This commit is contained in:
Spandan Das 2023-03-02 00:56:06 +00:00
parent ca70fc40bd
commit a26eda7f2c
7 changed files with 28 additions and 23 deletions

View file

@ -28,9 +28,9 @@ type SdkContext interface {
// MinSdkVersion returns ApiLevel that corresponds to the min_sdk_version property of the current module,
// or from sdk_version if it is not set.
MinSdkVersion(ctx EarlyModuleContext) ApiLevel
// ReplaceMaxSdkVersionPlaceholder returns SdkSpec to replace the maxSdkVersion property of permission and
// ReplaceMaxSdkVersionPlaceholder returns Apilevel to replace the maxSdkVersion property of permission and
// uses-permission tags if it is set.
ReplaceMaxSdkVersionPlaceholder(ctx EarlyModuleContext) SdkSpec
ReplaceMaxSdkVersionPlaceholder(ctx EarlyModuleContext) ApiLevel
// TargetSdkVersion returns the ApiLevel that corresponds to the target_sdk_version property of the current module,
// or from sdk_version if it is not set.
TargetSdkVersion(ctx EarlyModuleContext) ApiLevel

View file

@ -721,8 +721,8 @@ func (a *AARImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLev
return a.SdkVersion(ctx).ApiLevel
}
func (a *AARImport) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom(ctx, "")
func (a *AARImport) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel {
return android.SdkSpecFrom(ctx, "").ApiLevel
}
func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {

View file

@ -490,7 +490,7 @@ type Module struct {
sdkVersion android.SdkSpec
minSdkVersion android.ApiLevel
maxSdkVersion android.SdkSpec
maxSdkVersion android.ApiLevel
sourceExtensions []string
}
@ -672,16 +672,20 @@ func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel
return j.SdkVersion(ctx).ApiLevel
}
func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
maxSdkVersion := proptools.StringDefault(j.deviceProperties.Max_sdk_version, "")
// SdkSpecFrom returns SdkSpecPrivate for this, which may be confusing.
// TODO(b/208456999): ideally MaxSdkVersion should be an ApiLevel and not SdkSpec.
return android.SdkSpecFrom(ctx, maxSdkVersion)
func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
if j.deviceProperties.Max_sdk_version != nil {
return android.ApiLevelFrom(ctx, *j.deviceProperties.Max_sdk_version)
}
// Default is PrivateApiLevel
return android.SdkSpecPrivate.ApiLevel
}
func (j *Module) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec {
replaceMaxSdkVersionPlaceholder := proptools.StringDefault(j.deviceProperties.Replace_max_sdk_version_placeholder, "")
return android.SdkSpecFrom(ctx, replaceMaxSdkVersionPlaceholder)
func (j *Module) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel {
if j.deviceProperties.Replace_max_sdk_version_placeholder != nil {
return android.ApiLevelFrom(ctx, *j.deviceProperties.Replace_max_sdk_version_placeholder)
}
// Default is PrivateApiLevel
return android.SdkSpecPrivate.ApiLevel
}
func (j *Module) MinSdkVersionString() string {

View file

@ -136,11 +136,11 @@ func configuredJarListToClasspathJars(ctx android.ModuleContext, configuredJars
jar.minSdkVersion = s.minSdkVersion.String()
}
}
if s.maxSdkVersion.ApiLevel.Specified() {
if s.maxSdkVersion.ApiLevel.IsCurrent() {
if s.maxSdkVersion.Specified() {
if s.maxSdkVersion.IsCurrent() {
jar.maxSdkVersion = ctx.Config().DefaultAppTargetSdk(ctx).String()
} else {
jar.maxSdkVersion = s.maxSdkVersion.ApiLevel.String()
jar.maxSdkVersion = s.maxSdkVersion.String()
}
}
}

View file

@ -252,8 +252,8 @@ func (j *Javadoc) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel
return j.SdkVersion(ctx).ApiLevel
}
func (j *Javadoc) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec {
return j.SdkVersion(ctx)
func (j *Javadoc) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel {
return j.SdkVersion(ctx).ApiLevel
}
func (j *Javadoc) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {

View file

@ -1898,11 +1898,12 @@ func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel
return j.SdkVersion(ctx).ApiLevel
}
func (j *Import) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec {
func (j *Import) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel {
if j.properties.Replace_max_sdk_version_placeholder != nil {
return android.SdkSpecFrom(ctx, *j.properties.Replace_max_sdk_version_placeholder)
return android.ApiLevelFrom(ctx, *j.properties.Replace_max_sdk_version_placeholder)
}
return android.SdkSpecFrom(ctx, "")
// Default is PrivateApiLevel
return android.SdkSpecPrivate.ApiLevel
}
func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {

View file

@ -182,8 +182,8 @@ func (r *RuntimeResourceOverlay) MinSdkVersion(ctx android.EarlyModuleContext) a
return r.SdkVersion(ctx).ApiLevel
}
func (r *RuntimeResourceOverlay) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom(ctx, "")
func (r *RuntimeResourceOverlay) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel {
return android.SdkSpecPrivate.ApiLevel
}
func (r *RuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {