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
This commit is contained in:
29
java/java.go
29
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 {
|
||||
|
Reference in New Issue
Block a user