summaryrefslogtreecommitdiff
path: root/java/droidstubs.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/droidstubs.go')
-rw-r--r--java/droidstubs.go59
1 files changed, 51 insertions, 8 deletions
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 08caf9109..730be14b0 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -604,6 +604,11 @@ func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *a
}
}
+// AndroidPlusUpdatableJar is the name of some extra jars added into `module-lib` and
+// `system-server` directories that contain all the APIs provided by the platform and updatable
+// modules because the `android.jar` files do not. See b/337836752.
+const AndroidPlusUpdatableJar = "android-plus-updatable.jar"
+
func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsType StubsType, apiVersionsXml android.WritablePath) {
if len(d.properties.Api_levels_annotations_dirs) == 0 {
ctx.PropertyErrorf("api_levels_annotations_dirs",
@@ -621,7 +626,8 @@ func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *an
// privileged apps that are only defined since API level 21 (Lollipop), fallback to public stubs
// for older releases. Similarly, module-lib falls back to system API.
var sdkDirs []string
- switch proptools.StringDefault(d.properties.Api_levels_sdk_type, "public") {
+ apiLevelsSdkType := proptools.StringDefault(d.properties.Api_levels_sdk_type, "public")
+ switch apiLevelsSdkType {
case "system-server":
sdkDirs = []string{"system-server", "module-lib", "system", "public"}
case "module-lib":
@@ -635,9 +641,22 @@ func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *an
return
}
+ // Construct a pattern to match the appropriate extensions that should be included in the
+ // generated api-versions.xml file.
+ //
// Use the first item in the sdkDirs array as that is the sdk type for the target API levels
// being generated but has the advantage over `Api_levels_sdk_type` as it has been validated.
- extensionsPattern := fmt.Sprintf(`/extensions/[0-9]+/%s/.*\.jar`, sdkDirs[0])
+ // The exception is for system-server which needs to include module-lib and system-server. That
+ // is because while system-server extends module-lib the system-server extension directory only
+ // contains service-* modules which provide system-server APIs it does not list the modules which
+ // only provide a module-lib, so they have to be included separately.
+ extensionSurfacesPattern := sdkDirs[0]
+ if apiLevelsSdkType == "system-server" {
+ // Take the first two items in sdkDirs, which are system-server and module-lib, and construct
+ // a pattern that will match either.
+ extensionSurfacesPattern = strings.Join(sdkDirs[0:2], "|")
+ }
+ extensionsPattern := fmt.Sprintf(`/extensions/[0-9]+/(%s)/.*\.jar`, extensionSurfacesPattern)
var dirs []string
var extensions_dir string
@@ -648,16 +667,24 @@ func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *an
// Grab the first extensions_dir and we find while scanning ExportedDroiddocDir.deps;
// ideally this should be read from prebuiltApis.properties.Extensions_*
for _, dep := range t.deps {
+ // Check to see if it matches an extension first.
+ depBase := dep.Base()
if extRegex.MatchString(dep.String()) && d.properties.Extensions_info_file != nil {
if extensions_dir == "" {
extensions_dir = t.dir.String() + "/extensions"
}
cmd.Implicit(dep)
- }
- if dep.Base() == filename {
+ } else if depBase == filename {
+ // Check to see if it matches a dessert release for an SDK, e.g. Android, Car, Wear, etc..
cmd.Implicit(dep)
- }
- if filename != "android.jar" && dep.Base() == "android.jar" {
+ } else if depBase == AndroidPlusUpdatableJar && d.properties.Extensions_info_file != nil {
+ // The output api-versions.xml has been requested to include information on SDK
+ // extensions. That means it also needs to include
+ // so
+ // The module-lib and system-server directories should use `android-plus-updatable.jar`
+ // instead of `android.jar`. See AndroidPlusUpdatableJar for more information.
+ cmd.Implicit(dep)
+ } else if filename != "android.jar" && depBase == "android.jar" {
// Metalava implicitly searches these patterns:
// prebuilts/tools/common/api-versions/android-%/android.jar
// prebuilts/sdk/%/public/android.jar
@@ -675,9 +702,25 @@ func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *an
}
})
+ // Generate the list of --android-jar-pattern options. The order matters so the first one which
+ // matches will be the one that is used for a specific api level..
for _, sdkDir := range sdkDirs {
for _, dir := range dirs {
- cmd.FlagWithArg("--android-jar-pattern ", fmt.Sprintf("%s/%%/%s/%s", dir, sdkDir, filename))
+ addPattern := func(jarFilename string) {
+ cmd.FlagWithArg("--android-jar-pattern ", fmt.Sprintf("%s/%%/%s/%s", dir, sdkDir, jarFilename))
+ }
+
+ if sdkDir == "module-lib" || sdkDir == "system-server" {
+ // The module-lib and system-server android.jars do not include the updatable modules (as
+ // doing so in the source would introduce dependency cycles and the prebuilts have to
+ // match the sources). So, instead an additional `android-plus-updatable.jar` will be used
+ // that does include the updatable modules and this pattern will match that. This pattern
+ // is added in addition to the following pattern to decouple this change from the change
+ // to add the `android-plus-updatable.jar`.
+ addPattern(AndroidPlusUpdatableJar)
+ }
+
+ addPattern(filename)
}
}
@@ -1327,7 +1370,7 @@ func (d *Droidstubs) createApiContribution(ctx android.DefaultableHookContext) {
// use a strict naming convention
var (
droidstubsModuleNamingToSdkKind = map[string]android.SdkKind{
- //public is commented out since the core libraries use public in their java_sdk_library names
+ // public is commented out since the core libraries use public in their java_sdk_library names
"intracore": android.SdkIntraCore,
"intra.core": android.SdkIntraCore,
"system_server": android.SdkSystemServer,