Specify Is_stubs_module property in top level sdk library
java_sdk_library's "magic" will always resolve to stubs when either of
the following conditions are met:
- the module sets `api_only` property to "true": this signifies that
the module does not create an implementation library, thus the "magic"
always returns stubs
- the module sets `default_to_stubs` property set to "true": this
signifies that the reverse dependencies outside of the same apex will
always get the stubs, even when the rdep does not specify the
sdk_version.
This change utilize this information and mark the top level sdk_library
as a stubs module when any of the above conditions are met, in order to
minimize the false positives in container violation errors.
Test: Run container enforcement and observe results
Bug: 354029496
Change-Id: I04b52c5662f635ab1837eb33a39f187ae8998238
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 1eb7ab8..3931456 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1516,6 +1516,13 @@
// Add other dependencies as normal.
func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
+ // If the module does not create an implementation library or defaults to stubs,
+ // mark the top level sdk library as stubs module as the module will provide stubs via
+ // "magic" when listed as a dependency in the Android.bp files.
+ notCreateImplLib := proptools.Bool(module.sdkLibraryProperties.Api_only)
+ preferStubs := proptools.Bool(module.sdkLibraryProperties.Default_to_stubs)
+ module.properties.Is_stubs_module = proptools.BoolPtr(notCreateImplLib || preferStubs)
+
var missingApiModules []string
for _, apiScope := range module.getGeneratedApiScopes(ctx) {
if apiScope.unstable {