From 7c7083163a4957f6b56bbcd8a89c247966fe54e4 Mon Sep 17 00:00:00 2001 From: Jeongik Cha Date: Tue, 28 Jan 2020 13:52:36 +0900 Subject: [PATCH] Apply sdk version check to product apps 1. Check if system sdk version of apps from product partition is one of BOARD_SYSTEMSDK_VERSIONS. 2. The logic that check system sdk version doesn't work after aosp/1212908 because it always returns early Bug: 147711383 Test: m Test: set sdk_version the version that doesn't exist in BOARD_SYSTEMSDK_VERSIONS, and check if it cannot build Change-Id: I923477cffbcd9c763ee2deb5e7cce29aa005c715 --- java/sdk.go | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/java/sdk.go b/java/sdk.go index 1e60d6774..d230ccd96 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -283,6 +283,28 @@ func sdkSpecFrom(str string) sdkSpec { } } +func (s sdkSpec) validateSystemSdk(ctx android.EarlyModuleContext) bool { + // Ensures that the specified system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor/product Java module) + // Assuming that BOARD_SYSTEMSDK_VERSIONS := 28 29, + // sdk_version of the modules in vendor/product that use system sdk must be either system_28, system_29 or system_current + if s.kind != sdkSystem || !s.version.isNumbered() { + return true + } + allowedVersions := ctx.DeviceConfig().PlatformSystemSdkVersions() + if ctx.DeviceSpecific() || ctx.SocSpecific() || (ctx.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { + systemSdkVersions := ctx.DeviceConfig().SystemSdkVersions() + if len(systemSdkVersions) > 0 { + allowedVersions = systemSdkVersions + } + } + if len(allowedVersions) > 0 && !android.InList(s.version.String(), allowedVersions) { + ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q", + s.raw, allowedVersions) + return false + } + return true +} + func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep { sdkVersion := sdkContext.sdkVersion() if !sdkVersion.valid() { @@ -293,6 +315,9 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep if ctx.Config().IsPdkBuild() { sdkVersion = sdkVersion.forPdkBuild(ctx) } + if !sdkVersion.validateSystemSdk(ctx) { + return sdkDep{} + } if sdkVersion.usePrebuilt(ctx) { dir := filepath.Join("prebuilts", "sdk", sdkVersion.version.String(), sdkVersion.kind.String()) @@ -340,21 +365,6 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep } } - // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks) - // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set) - if sdkVersion.kind == sdkSystem && sdkVersion.version.isNumbered() { - allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions() - if ctx.DeviceSpecific() || ctx.SocSpecific() { - if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 { - allowed_versions = ctx.DeviceConfig().SystemSdkVersions() - } - } - if len(allowed_versions) > 0 && !android.InList(sdkVersion.version.String(), allowed_versions) { - ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q", - sdkVersion.raw, allowed_versions) - } - } - switch sdkVersion.kind { case sdkPrivate: return sdkDep{