Create public stub for platform's sysprop_library
Java modules using SystemAPI can now link against platform owned
sysprop_library with public stub. This allows modules to use platform's
public sysprops (which should be regarded as an API) without any hidden
API usages, if using dynamic linking and boot class path.
This doesn't affect any vendor or odm owned sysprop_library.
Bug: 141246285
Bug: 145167888
Test: m
Change-Id: I99824fb24a75cc8282211c2ad6c6296ae9fca393
diff --git a/java/java.go b/java/java.go
index d8db5f8..2d97b7f 100644
--- a/java/java.go
+++ b/java/java.go
@@ -585,8 +585,36 @@
}
}
- ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
- ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
+ syspropPublicStubs := syspropPublicStubs(ctx.Config())
+
+ // rewriteSyspropLibs validates if a java module can link against platform's sysprop_library,
+ // and redirects dependency to public stub depending on the link type.
+ rewriteSyspropLibs := func(libs []string, prop string) []string {
+ // make a copy
+ ret := android.CopyOf(libs)
+
+ for idx, lib := range libs {
+ stub, ok := syspropPublicStubs[lib]
+
+ if !ok {
+ continue
+ }
+
+ linkType, _ := j.getLinkType(ctx.ModuleName())
+ if linkType == javaSystem {
+ ret[idx] = stub
+ } else if linkType != javaPlatform {
+ ctx.PropertyErrorf("sdk_version",
+ "can't link against sysprop_library %q from a module using public or core API",
+ lib)
+ }
+ }
+
+ return ret
+ }
+
+ ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...)
+ ctx.AddVariationDependencies(nil, staticLibTag, rewriteSyspropLibs(j.properties.Static_libs, "static_libs")...)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)