From 0a420e771a2201c99f570cf48bd09a6bd837cce2 Mon Sep 17 00:00:00 2001 From: satayev Date: Mon, 29 Nov 2021 17:25:52 +0000 Subject: [PATCH] Introduce max_sdk_version device property. Artifacts that go into apexes should only be active on certain SDK versions. There is now a need to upper bound the range to support expressiong statements like "this jar should only run on platforms 30-31". Bug: 190818041 Test: presubmit Change-Id: I6985ebb671841cdd9f0f37f916267ac5ed76e4f4 --- java/base.go | 12 ++++++++++++ java/java.go | 1 + 2 files changed, 13 insertions(+) diff --git a/java/base.go b/java/base.go index d9b126059..2f90db2b8 100644 --- a/java/base.go +++ b/java/base.go @@ -197,6 +197,10 @@ type DeviceProperties struct { // 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. + // Defaults to empty string "". See sdk_version for possible values. + Max_sdk_version *string + // if not blank, set the targetSdkVersion in the AndroidManifest.xml. // Defaults to sdk_version if not set. See sdk_version for possible values. Target_sdk_version *string @@ -460,6 +464,7 @@ type Module struct { sdkVersion android.SdkSpec minSdkVersion android.SdkSpec + maxSdkVersion android.SdkSpec } func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error { @@ -617,6 +622,13 @@ func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { return j.SdkVersion(ctx) } +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) MinSdkVersionString() string { return j.minSdkVersion.Raw } diff --git a/java/java.go b/java/java.go index 2f9e03a80..e8a8236f7 100644 --- a/java/java.go +++ b/java/java.go @@ -545,6 +545,7 @@ func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.sdkVersion = j.SdkVersion(ctx) j.minSdkVersion = j.MinSdkVersion(ctx) + j.maxSdkVersion = j.MaxSdkVersion(ctx) apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) if !apexInfo.IsForPlatform() {