Enable hiddenapi check for exportable stubs
This change modifies the dependencies of the hiddenapi to always depend
on the exportable stubs, instead of the currently utilized everything
stubs.
To support this, the full api surface exportable stubs are defined in a
separate change at the `frameworks/base` project. Note that the full api
surface exportable stubs are only used for the hiddenapi purpose, and
`sdk_version` continues to utilize the currently existing everything
stubs.
Currently, this feature is hidden behind the build flag
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS". This feature will be fully
enabled once metalava fully supports handling of the flagged apis.
Test: ENABLE_HIDDENAPI_FLAGS=true m
Bug: 317426356
Change-Id: I109b7cd27b20ceffcdf1766ab8106b0c276be2b3
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 058862b..74e2da4 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -104,9 +104,16 @@
// The name of the property in the java_sdk_library_import
propertyName string
- // The tag to use to depend on the stubs library module.
+ // The tag to use to depend on the stubs library module if the parent module
+ // does not differentiate everything and exportable stubs (e.g. sdk_library_import).
stubsTag scopeDependencyTag
+ // The tag to use to depend on the everything stubs library module.
+ everythingStubsTag scopeDependencyTag
+
+ // The tag to use to depend on the exportable stubs library module.
+ exportableStubsTag scopeDependencyTag
+
// The tag to use to depend on the stubs source module (if separate from the API module).
stubsSourceTag scopeDependencyTag
@@ -172,6 +179,16 @@
apiScope: scope,
depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency,
}
+ scope.everythingStubsTag = scopeDependencyTag{
+ name: name + "-stubs-everything",
+ apiScope: scope,
+ depInfoExtractor: (*scopePaths).extractEverythingStubsLibraryInfoFromDependency,
+ }
+ scope.exportableStubsTag = scopeDependencyTag{
+ name: name + "-stubs-exportable",
+ apiScope: scope,
+ depInfoExtractor: (*scopePaths).extractExportableStubsLibraryInfoFromDependency,
+ }
scope.stubsSourceTag = scopeDependencyTag{
name: name + "-stubs-source",
apiScope: scope,
@@ -669,6 +686,11 @@
// This is not the implementation jar, it still only contains stubs.
stubsDexJarPath OptionalDexJarPath
+ // The exportable dex jar for the stubs.
+ // This is not the implementation jar, it still only contains stubs.
+ // Includes unflagged apis and flagged apis enabled by release configurations.
+ exportableStubsDexJarPath OptionalDexJarPath
+
// The API specification file, e.g. system_current.txt.
currentApiFilePath android.OptionalPath
@@ -695,6 +717,30 @@
libDep := dep.(UsesLibraryDependency)
paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx)
+ paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx)
+ return nil
+ } else {
+ return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library")
+ }
+}
+
+func (paths *scopePaths) extractEverythingStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
+ if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
+ paths.stubsHeaderPath = lib.HeaderJars
+ paths.stubsImplPath = lib.ImplementationJars
+
+ libDep := dep.(UsesLibraryDependency)
+ paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx)
+ return nil
+ } else {
+ return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library")
+ }
+}
+
+func (paths *scopePaths) extractExportableStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
+ if _, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
+ libDep := dep.(UsesLibraryDependency)
+ paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx)
return nil
} else {
return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library")
@@ -1132,6 +1178,16 @@
}
// to satisfy SdkLibraryDependency interface
+func (c *commonToSdkLibraryAndImport) SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath {
+ paths := c.selectScopePaths(ctx, kind)
+ if paths == nil {
+ return makeUnsetDexJarPath()
+ }
+
+ return paths.exportableStubsDexJarPath
+}
+
+// to satisfy SdkLibraryDependency interface
func (c *commonToSdkLibraryAndImport) SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath {
apiScope := sdkKindToApiScope(kind)
paths := c.findScopePaths(apiScope)
@@ -1249,10 +1305,16 @@
// they are identical to the corresponding header jars.
SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths
- // SdkApiStubDexJar returns the dex jar for the stubs. It is needed by the hiddenapi processing
- // tool which processes dex files.
+ // SdkApiStubDexJar returns the dex jar for the stubs for the prebuilt
+ // java_sdk_library_import module. It is needed by the hiddenapi processing tool which
+ // processes dex files.
SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath
+ // SdkApiExportableStubDexJar returns the exportable dex jar for the stubs for
+ // java_sdk_library module. It is needed by the hiddenapi processing tool which processes
+ // dex files.
+ SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath
+
// SdkRemovedTxtFile returns the optional path to the removed.txt file for the specified sdk kind.
SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath
@@ -1365,8 +1427,10 @@
for _, apiScope := range module.getGeneratedApiScopes(ctx) {
// Add dependencies to the stubs library
stubModuleName := module.stubsLibraryModuleName(apiScope)
+ ctx.AddVariationDependencies(nil, apiScope.everythingStubsTag, stubModuleName)
- ctx.AddVariationDependencies(nil, apiScope.stubsTag, stubModuleName)
+ exportableStubModuleName := module.exportableStubsLibraryModuleName(apiScope)
+ ctx.AddVariationDependencies(nil, apiScope.exportableStubsTag, exportableStubModuleName)
// Add a dependency on the stubs source in order to access both stubs source and api information.
ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope))