diff options
author | Jeongik Cha <jeongik@google.com> | 2019-10-29 15:44:45 +0900 |
---|---|---|
committer | Jeongik Cha <jeongik@google.com> | 2019-11-06 19:42:42 +0900 |
commit | 2cc570dc63232b3fcbab00fa65292abeb7828376 (patch) | |
tree | 4d4a531a54c7857ef2bbde6a77de4b95cf083ff3 /java/java.go | |
parent | af60d490ff6fdd716b343e0b29ce5b2bb95e7829 (diff) |
Enforce hidden apis usage in product(soong)
Only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set,
every app and java library in product cannot use hidden APIs anymore.
checkSdkVersion() checks if sdk_version of app and library is narrow enough,
checkLinkType() checks every library that app links agianst
Bug: 132780927
Test: m
Test: set PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE, and check whether build
error occurs.
Change-Id: Ic630503b875040f730feda4fef826ed6d71da111
Diffstat (limited to 'java/java.go')
-rw-r--r-- | java/java.go | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/java/java.go b/java/java.go index d7077d1bb..d043a12fe 100644 --- a/java/java.go +++ b/java/java.go @@ -54,6 +54,18 @@ func init() { android.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory) } +func (j *Module) checkSdkVersion(ctx android.ModuleContext) { + if j.SocSpecific() || j.DeviceSpecific() || + (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { + if sc, ok := ctx.Module().(sdkContext); ok { + if sc.sdkVersion() == "" { + ctx.PropertyErrorf("sdk_version", + "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).") + } + } + } +} + func (j *Module) checkPlatformAPI(ctx android.ModuleContext) { if sc, ok := ctx.Module().(sdkContext); ok { usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis) @@ -447,18 +459,6 @@ var ( usesLibTag = dependencyTag{name: "uses-library"} ) -func defaultSdkVersion(ctx checkVendorModuleContext) string { - if ctx.SocSpecific() || ctx.DeviceSpecific() { - return "system_current" - } - return "" -} - -type checkVendorModuleContext interface { - SocSpecific() bool - DeviceSpecific() bool -} - type sdkDep struct { useModule, useFiles, useDefaultLibs, invalidVersion bool @@ -505,7 +505,7 @@ func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool { } func (j *Module) sdkVersion() string { - return proptools.StringDefault(j.deviceProperties.Sdk_version, defaultSdkVersion(j)) + return String(j.deviceProperties.Sdk_version) } func (j *Module) systemModules() string { @@ -1635,6 +1635,7 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo } func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { + j.checkSdkVersion(ctx) j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary j.dexpreopter.isInstallable = Bool(j.properties.Installable) @@ -1978,7 +1979,7 @@ type Import struct { } func (j *Import) sdkVersion() string { - return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j)) + return String(j.properties.Sdk_version) } func (j *Import) minSdkVersion() string { |