From e4a901732741b84421c3e94a77619853c7f55a2d Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Thu, 18 Jul 2024 22:49:08 +0000 Subject: [PATCH] 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 --- java/sdk_library.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/java/sdk_library.go b/java/sdk_library.go index 1eb7ab834..3931456e4 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1516,6 +1516,13 @@ func (module *SdkLibrary) ComponentDepsMutator(ctx android.BottomUpMutatorContex // 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 {