From 8c9ae7ed6770b45f1337722a2e61cb22317659aa Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Fri, 3 Mar 2023 21:20:36 +0000 Subject: [PATCH] Update min_sdk_version from SdkSpec to ApiLevel This relands aosp/2457063. The original change broke T and U since those branches still contain soong modules of type (kind+level). Those soong modules have been cleaned up now Test: Used go/abtd to test T and U branches with this change Bug: 208456999 Change-Id: I0ef7933c055f88cb512a02108f1173e51156ef1c --- android/apex.go | 2 +- android/api_levels.go | 18 ++++++++++++++++++ android/sdk.go | 4 ++-- android/sdk_version.go | 4 ++-- apex/apex.go | 8 ++------ apex/builder.go | 8 ++++---- java/aar.go | 12 ++++++------ java/app.go | 14 +++++++------- java/app_import.go | 4 ++-- java/base.go | 27 +++++++++++++-------------- java/classpath_fragment.go | 6 +++--- java/dex.go | 2 +- java/droiddoc.go | 6 +++--- java/hiddenapi.go | 8 ++++---- java/hiddenapi_modular.go | 2 +- java/java.go | 15 +++++++-------- java/rro.go | 6 +++--- java/sdk_library.go | 8 ++++---- 18 files changed, 83 insertions(+), 71 deletions(-) diff --git a/android/apex.go b/android/apex.go index 358818f47..87bff74c3 100644 --- a/android/apex.go +++ b/android/apex.go @@ -845,7 +845,7 @@ type WalkPayloadDepsFunc func(ctx ModuleContext, do PayloadDepsCallback) // ModuleWithMinSdkVersionCheck represents a module that implements min_sdk_version checks type ModuleWithMinSdkVersionCheck interface { Module - MinSdkVersion(ctx EarlyModuleContext) SdkSpec + MinSdkVersion(ctx EarlyModuleContext) ApiLevel CheckMinSdkVersion(ctx ModuleContext) } diff --git a/android/api_levels.go b/android/api_levels.go index e48a69ea2..0c0b2b433 100644 --- a/android/api_levels.go +++ b/android/api_levels.go @@ -185,6 +185,14 @@ func (l ApiLevel) EffectiveVersionString(ctx EarlyModuleContext) (string, error) return ret.String(), nil } +// Specified returns true if the module is targeting a recognzized api_level. +// It returns false if either +// 1. min_sdk_version is not an int or a recognized codename +// 2. both min_sdk_version and sdk_version are empty. In this case, MinSdkVersion() defaults to SdkSpecPrivate.ApiLevel +func (this ApiLevel) Specified() bool { + return !this.IsInvalid() && !this.IsPrivate() +} + // Returns -1 if the current API level is less than the argument, 0 if they // are equal, and 1 if it is greater than the argument. func (this ApiLevel) CompareTo(other ApiLevel) int { @@ -289,6 +297,16 @@ func ReplaceFinalizedCodenames(config Config, raw string) string { return strconv.Itoa(num) } +// ApiLevelFrom converts the given string `raw` to an ApiLevel. +// If `raw` is invalid (empty string, unrecognized codename etc.) it returns an invalid ApiLevel +func ApiLevelFrom(ctx PathContext, raw string) ApiLevel { + ret, err := ApiLevelFromUser(ctx, raw) + if err != nil { + return NewInvalidApiLevel(raw) + } + return ret +} + // ApiLevelFromUser converts the given string `raw` to an ApiLevel, possibly returning an error. // // `raw` must be non-empty. Passing an empty string results in a panic. diff --git a/android/sdk.go b/android/sdk.go index 8b23d63a9..63e0bbeec 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -25,7 +25,7 @@ import ( // minApiLevelForSdkSnapshot provides access to the min_sdk_version for MinApiLevelForSdkSnapshot type minApiLevelForSdkSnapshot interface { - MinSdkVersion(ctx EarlyModuleContext) SdkSpec + MinSdkVersion(ctx EarlyModuleContext) ApiLevel } // MinApiLevelForSdkSnapshot returns the ApiLevel of the min_sdk_version of the supplied module. @@ -34,7 +34,7 @@ type minApiLevelForSdkSnapshot interface { func MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel { minApiLevel := NoneApiLevel if m, ok := module.(minApiLevelForSdkSnapshot); ok { - minApiLevel = m.MinSdkVersion(ctx).ApiLevel + minApiLevel = m.MinSdkVersion(ctx) } if minApiLevel == NoneApiLevel { // The default min API level is 1. diff --git a/android/sdk_version.go b/android/sdk_version.go index ab6e4f796..2107cbedb 100644 --- a/android/sdk_version.go +++ b/android/sdk_version.go @@ -25,9 +25,9 @@ type SdkContext interface { SdkVersion(ctx EarlyModuleContext) SdkSpec // SystemModules returns the system_modules property of the current module, or an empty string if it is not set. SystemModules() string - // MinSdkVersion returns SdkSpec that corresponds to the min_sdk_version property of the current module, + // 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) SdkSpec + MinSdkVersion(ctx EarlyModuleContext) ApiLevel // ReplaceMaxSdkVersionPlaceholder returns SdkSpec to replace the maxSdkVersion property of permission and // uses-permission tags if it is set. ReplaceMaxSdkVersionPlaceholder(ctx EarlyModuleContext) SdkSpec diff --git a/apex/apex.go b/apex/apex.go index 4424b22d3..68ad95e2f 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2946,12 +2946,8 @@ func (a *apexBundle) minSdkVersionValue(ctx android.EarlyModuleContext) string { } // Returns apex's min_sdk_version SdkSpec, honoring overrides -func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { - return android.SdkSpec{ - Kind: android.SdkNone, - ApiLevel: a.minSdkVersion(ctx), - Raw: a.minSdkVersionValue(ctx), - } +func (a *apexBundle) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { + return a.minSdkVersion(ctx) } // Returns apex's min_sdk_version ApiLevel, honoring overrides diff --git a/apex/builder.go b/apex/builder.go index ee6c473bd..45c52671c 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -1063,10 +1063,10 @@ func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) { } else { toMinSdkVersion := "(no version)" if m, ok := to.(interface { - MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec + MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel }); ok { - if v := m.MinSdkVersion(ctx); !v.ApiLevel.IsNone() { - toMinSdkVersion = v.ApiLevel.String() + if v := m.MinSdkVersion(ctx); !v.IsNone() { + toMinSdkVersion = v.String() } } else if m, ok := to.(interface{ MinSdkVersion() string }); ok { // TODO(b/175678607) eliminate the use of MinSdkVersion returning @@ -1087,7 +1087,7 @@ func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) { return !externalDep }) - a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(ctx).Raw, depInfos) + a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(ctx).String(), depInfos) ctx.Build(pctx, android.BuildParams{ Rule: android.Phony, diff --git a/java/aar.go b/java/aar.go index 4bc5465aa..4e5ac1f36 100644 --- a/java/aar.go +++ b/java/aar.go @@ -220,12 +220,12 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkConte linkDeps = append(linkDeps, assetDeps...) // Returns the effective version for {min|target}_sdk_version - effectiveVersionString := func(sdkVersion android.SdkSpec, minSdkVersion android.SdkSpec) string { + effectiveVersionString := func(sdkVersion android.SdkSpec, minSdkVersion android.ApiLevel) string { // If {min|target}_sdk_version is current, use sdk_version to determine the effective level // This is necessary for vendor modules. // The effective version does not _only_ depend on {min|target}_sdk_version(level), // but also on the sdk_version (kind+level) - if minSdkVersion.ApiLevel.IsCurrent() { + if minSdkVersion.IsCurrent() { ret, err := sdkVersion.EffectiveVersionString(ctx) if err != nil { ctx.ModuleErrorf("invalid sdk_version: %s", err) @@ -689,7 +689,7 @@ type AARImport struct { jniPackages android.Paths sdkVersion android.SdkSpec - minSdkVersion android.SdkSpec + minSdkVersion android.ApiLevel } var _ android.OutputFileProducer = (*AARImport)(nil) @@ -714,11 +714,11 @@ func (a *AARImport) SystemModules() string { return "" } -func (a *AARImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { +func (a *AARImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { if a.properties.Min_sdk_version != nil { - return android.SdkSpecFrom(ctx, *a.properties.Min_sdk_version) + return android.ApiLevelFrom(ctx, *a.properties.Min_sdk_version) } - return a.SdkVersion(ctx) + return a.SdkVersion(ctx).ApiLevel } func (a *AARImport) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec { diff --git a/java/app.go b/java/app.go index 8b54bc8cd..52caf6d38 100755 --- a/java/app.go +++ b/java/app.go @@ -752,7 +752,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { type appDepsInterface interface { SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec - MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec + MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel RequiresStableAPIs(ctx android.BaseModuleContext) bool } @@ -865,10 +865,10 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) { } else { toMinSdkVersion := "(no version)" if m, ok := to.(interface { - MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec + MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel }); ok { - if v := m.MinSdkVersion(ctx); !v.ApiLevel.IsNone() { - toMinSdkVersion = v.ApiLevel.String() + if v := m.MinSdkVersion(ctx); !v.IsNone() { + toMinSdkVersion = v.String() } } else if m, ok := to.(interface{ MinSdkVersion() string }); ok { // TODO(b/175678607) eliminate the use of MinSdkVersion returning @@ -1524,9 +1524,9 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) { manifestValues := &manifestValueAttribute{} // TODO(b/274474008 ): Directly convert deviceProperties.Min_sdk_version in bp2build // MinSdkVersion(ctx) calls SdkVersion(ctx) if no value for min_sdk_version is set - minSdkSpec := a.MinSdkVersion(ctx) - if !minSdkSpec.ApiLevel.IsPreview() && minSdkSpec.Valid() { - minSdkStr, err := minSdkSpec.EffectiveVersionString(ctx) + minSdkVersion := a.MinSdkVersion(ctx) + if !minSdkVersion.IsPreview() && !minSdkVersion.IsInvalid() { + minSdkStr, err := minSdkVersion.EffectiveVersionString(ctx) if err == nil { manifestValues.MinSdkVersion = &minSdkStr } diff --git a/java/app_import.go b/java/app_import.go index e24e7804e..c1de66745 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -426,8 +426,8 @@ func (a *AndroidAppImport) SdkVersion(ctx android.EarlyModuleContext) android.Sd return android.SdkSpecPrivate } -func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { - return android.SdkSpecPrivate +func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { + return android.SdkSpecPrivate.ApiLevel } func (a *AndroidAppImport) LintDepSets() LintDepSets { diff --git a/java/base.go b/java/base.go index 7e95abd02..a3f6e3cd1 100644 --- a/java/base.go +++ b/java/base.go @@ -489,7 +489,7 @@ type Module struct { hideApexVariantFromMake bool sdkVersion android.SdkSpec - minSdkVersion android.SdkSpec + minSdkVersion android.ApiLevel maxSdkVersion android.SdkSpec sourceExtensions []string @@ -665,11 +665,11 @@ func (j *Module) SystemModules() string { return proptools.String(j.deviceProperties.System_modules) } -func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { +func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { if j.deviceProperties.Min_sdk_version != nil { - return android.SdkSpecFrom(ctx, *j.deviceProperties.Min_sdk_version) + return android.ApiLevelFrom(ctx, *j.deviceProperties.Min_sdk_version) } - return j.SdkVersion(ctx) + return j.SdkVersion(ctx).ApiLevel } func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { @@ -685,7 +685,7 @@ func (j *Module) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) } func (j *Module) MinSdkVersionString() string { - return j.minSdkVersion.Raw + return j.minSdkVersion.String() } func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { @@ -881,7 +881,7 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt j.ignoredAidlPermissionList = android.PathsForModuleSrcExcludes(ctx, exceptions, nil) } - aidlMinSdkVersion := j.MinSdkVersion(ctx).ApiLevel.String() + aidlMinSdkVersion := j.MinSdkVersion(ctx).String() flags = append(flags, "--min_sdk_version="+aidlMinSdkVersion) return strings.Join(flags, " "), deps @@ -1542,9 +1542,9 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { } if ctx.Device() { - lintSDKVersion := func(sdkSpec android.SdkSpec) int { - if v := sdkSpec.ApiLevel; !v.IsPreview() { - return v.FinalInt() + lintSDKVersion := func(apiLevel android.ApiLevel) int { + if !apiLevel.IsPreview() { + return apiLevel.FinalInt() } else { // When running metalava, we pass --version-codename. When that value // is not REL, metalava will add 1 to the --current-version argument. @@ -1575,8 +1575,8 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...) j.linter.classes = j.implementationJarFile j.linter.minSdkVersion = lintSDKVersion(j.MinSdkVersion(ctx)) - j.linter.targetSdkVersion = lintSDKVersion(j.TargetSdkVersion(ctx)) - j.linter.compileSdkVersion = lintSDKVersion(j.SdkVersion(ctx)) + j.linter.targetSdkVersion = lintSDKVersion(j.TargetSdkVersion(ctx).ApiLevel) + j.linter.compileSdkVersion = lintSDKVersion(j.SdkVersion(ctx).ApiLevel) j.linter.compileSdkKind = j.SdkVersion(ctx).Kind j.linter.javaLanguageLevel = flags.javaVersion.String() j.linter.kotlinLanguageLevel = "1.3" @@ -1846,15 +1846,14 @@ func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu // Implements android.ApexModule func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { sdkVersionSpec := j.SdkVersion(ctx) - minSdkVersionSpec := j.MinSdkVersion(ctx) - if !minSdkVersionSpec.Specified() { + minSdkVersion := j.MinSdkVersion(ctx) + if !minSdkVersion.Specified() { return fmt.Errorf("min_sdk_version is not specified") } // If the module is compiling against core (via sdk_version), skip comparison check. if sdkVersionSpec.Kind == android.SdkCore { return nil } - minSdkVersion := minSdkVersionSpec.ApiLevel if minSdkVersion.GreaterThan(sdkVersion) { return fmt.Errorf("newer SDK(%v)", minSdkVersion) } diff --git a/java/classpath_fragment.go b/java/classpath_fragment.go index cf81ddb5d..45e6175f2 100644 --- a/java/classpath_fragment.go +++ b/java/classpath_fragment.go @@ -130,13 +130,13 @@ func configuredJarListToClasspathJars(ctx android.ModuleContext, configuredJars if s, ok := m.(*SdkLibrary); ok { // TODO(208456999): instead of mapping "current" to latest, min_sdk_version should never be set to "current" if s.minSdkVersion.Specified() { - if s.minSdkVersion.ApiLevel.IsCurrent() { + if s.minSdkVersion.IsCurrent() { jar.minSdkVersion = ctx.Config().DefaultAppTargetSdk(ctx).String() } else { - jar.minSdkVersion = s.minSdkVersion.ApiLevel.String() + jar.minSdkVersion = s.minSdkVersion.String() } } - if s.maxSdkVersion.Specified() { + if s.maxSdkVersion.ApiLevel.Specified() { if s.maxSdkVersion.ApiLevel.IsCurrent() { jar.maxSdkVersion = ctx.Config().DefaultAppTargetSdk(ctx).String() } else { diff --git a/java/dex.go b/java/dex.go index 7b6a99a8a..4d6aa3456 100644 --- a/java/dex.go +++ b/java/dex.go @@ -343,7 +343,7 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl type compileDexParams struct { flags javaBuilderFlags sdkVersion android.SdkSpec - minSdkVersion android.SdkSpec + minSdkVersion android.ApiLevel classesJar android.Path jarName string } diff --git a/java/droiddoc.go b/java/droiddoc.go index e98b9ea29..3e210088b 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -248,8 +248,8 @@ func (j *Javadoc) SystemModules() string { return proptools.String(j.properties.System_modules) } -func (j *Javadoc) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { - return j.SdkVersion(ctx) +func (j *Javadoc) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { + return j.SdkVersion(ctx).ApiLevel } func (j *Javadoc) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec { @@ -304,7 +304,7 @@ func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Op flags = append(flags, "-I"+src.String()) } - minSdkVersion := j.MinSdkVersion(ctx).ApiLevel.FinalOrFutureInt() + minSdkVersion := j.MinSdkVersion(ctx).FinalOrFutureInt() flags = append(flags, fmt.Sprintf("--min_sdk_version=%v", minSdkVersion)) return strings.Join(flags, " "), deps diff --git a/java/hiddenapi.go b/java/hiddenapi.go index c4fc65f2e..d25096b15 100644 --- a/java/hiddenapi.go +++ b/java/hiddenapi.go @@ -73,7 +73,7 @@ type hiddenAPIModule interface { android.Module hiddenAPIIntf - MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec + MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel } type hiddenAPIIntf interface { @@ -157,7 +157,7 @@ func (h *hiddenAPI) hiddenAPIEncodeDex(ctx android.ModuleContext, dexJar android // Create a copy of the dex jar which has been encoded with hiddenapi flags. flagsCSV := hiddenAPISingletonPaths(ctx).flags outputDir := android.PathForModuleOut(ctx, "hiddenapi").OutputPath - encodedDex := hiddenAPIEncodeDex(ctx, dexJar, flagsCSV, uncompressDex, android.SdkSpecNone, outputDir) + encodedDex := hiddenAPIEncodeDex(ctx, dexJar, flagsCSV, uncompressDex, android.NoneApiLevel, outputDir) // Use the encoded dex jar from here onwards. return encodedDex @@ -253,7 +253,7 @@ var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", bluepr // The encode dex rule requires unzipping, encoding and rezipping the classes.dex files along with // all the resources from the input jar. It also ensures that if it was uncompressed in the input // it stays uncompressed in the output. -func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Path, uncompressDex bool, minSdkVersion android.SdkSpec, outputDir android.OutputPath) android.OutputPath { +func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Path, uncompressDex bool, minSdkVersion android.ApiLevel, outputDir android.OutputPath) android.OutputPath { // The output file has the same name as the input file and is in the output directory. output := outputDir.Join(ctx, dexInput.Base()) @@ -283,7 +283,7 @@ func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Pa // If the library is targeted for Q and/or R then make sure that they do not // have any S+ flags encoded as that will break the runtime. - minApiLevel := minSdkVersion.ApiLevel + minApiLevel := minSdkVersion if !minApiLevel.IsNone() { if minApiLevel.LessThanOrEqualTo(android.ApiLevelOrPanic(ctx, "R")) { hiddenapiFlags = hiddenapiFlags + " --max-hiddenapi-level=max-target-r" diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index e2db0cd6b..c6176e67c 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -1278,7 +1278,7 @@ type bootDexInfo struct { uncompressDex bool // The minimum sdk version that the dex jar will be used on. - minSdkVersion android.SdkSpec + minSdkVersion android.ApiLevel } // bootDexInfoByModule is a map from module name (as returned by module.Name()) to the boot dex diff --git a/java/java.go b/java/java.go index 0841dad5e..287bdace3 100644 --- a/java/java.go +++ b/java/java.go @@ -811,7 +811,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 // snapshot. if j.deviceProperties.Min_sdk_version != nil { - canonical := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.ApiLevel.String()) + canonical := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String()) p.MinSdkVersion = proptools.StringPtr(canonical) } @@ -1874,7 +1874,7 @@ type Import struct { hideApexVariantFromMake bool sdkVersion android.SdkSpec - minSdkVersion android.SdkSpec + minSdkVersion android.ApiLevel } var _ PermittedPackagesForUpdatableBootJars = (*Import)(nil) @@ -1891,11 +1891,11 @@ func (j *Import) SystemModules() string { return "none" } -func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { +func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { if j.properties.Min_sdk_version != nil { - return android.SdkSpecFrom(ctx, *j.properties.Min_sdk_version) + return android.ApiLevelFrom(ctx, *j.properties.Min_sdk_version) } - return j.SdkVersion(ctx) + return j.SdkVersion(ctx).ApiLevel } func (j *Import) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec { @@ -2161,15 +2161,14 @@ func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { sdkVersionSpec := j.SdkVersion(ctx) - minSdkVersionSpec := j.MinSdkVersion(ctx) - if !minSdkVersionSpec.Specified() { + minSdkVersion := j.MinSdkVersion(ctx) + if !minSdkVersion.Specified() { return fmt.Errorf("min_sdk_version is not specified") } // If the module is compiling against core (via sdk_version), skip comparison check. if sdkVersionSpec.Kind == android.SdkCore { return nil } - minSdkVersion := minSdkVersionSpec.ApiLevel if minSdkVersion.GreaterThan(sdkVersion) { return fmt.Errorf("newer SDK(%v)", minSdkVersion) } diff --git a/java/rro.go b/java/rro.go index 9d0667cf0..49737b946 100644 --- a/java/rro.go +++ b/java/rro.go @@ -175,11 +175,11 @@ func (r *RuntimeResourceOverlay) SystemModules() string { return "" } -func (r *RuntimeResourceOverlay) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { +func (r *RuntimeResourceOverlay) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { if r.properties.Min_sdk_version != nil { - return android.SdkSpecFrom(ctx, *r.properties.Min_sdk_version) + return android.ApiLevelFrom(ctx, *r.properties.Min_sdk_version) } - return r.SdkVersion(ctx) + return r.SdkVersion(ctx).ApiLevel } func (r *RuntimeResourceOverlay) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec { diff --git a/java/sdk_library.go b/java/sdk_library.go index d2fbfd953..5477ed664 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1231,7 +1231,7 @@ func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) var _ android.ModuleWithMinSdkVersionCheck = (*SdkLibrary)(nil) func (module *SdkLibrary) CheckMinSdkVersion(ctx android.ModuleContext) { - android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx).ApiLevel, func(c android.ModuleContext, do android.PayloadDepsCallback) { + android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx), func(c android.ModuleContext, do android.PayloadDepsCallback) { ctx.WalkDeps(func(child android.Module, parent android.Module) bool { isExternal := !module.depIsInSameApex(ctx, child) if am, ok := child.(android.ApexModule); ok { @@ -1775,7 +1775,7 @@ func (module *SdkLibrary) UniqueApexVariations() bool { // Creates the xml file that publicizes the runtime library func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) { - moduleMinApiLevel := module.Library.MinSdkVersion(mctx).ApiLevel + moduleMinApiLevel := module.Library.MinSdkVersion(mctx) var moduleMinApiLevelStr = moduleMinApiLevel.String() if moduleMinApiLevel == android.NoneApiLevel { moduleMinApiLevelStr = "current" @@ -2414,8 +2414,8 @@ func (module *SdkLibraryImport) UniqueApexVariations() bool { } // MinSdkVersion - Implements hiddenAPIModule -func (module *SdkLibraryImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { - return android.SdkSpecNone +func (module *SdkLibraryImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { + return android.NoneApiLevel } var _ hiddenAPIModule = (*SdkLibraryImport)(nil)