Fix monolithic hidden API processing with prebuilts

Prebuilt modules do not provide classesJars containing annotations.
Previously, the monolithic hidden API processing just used classesJars
from all the modules that provided them so when building against
prebuilts would have fewer classesJars than when building against
sources and so would produce different hidden API flags.

This change will generate the monolithic files from both classesJars
and files previously generated from hidden API processing. A fragment
that has performed hidden API processing will contribute its generated
files whereas standalone libraries and fragments which have not
performed hidden API processing will contribute classesJars.

Bug: 177892522
Test: m out/soong/hiddenapi/hiddenapi-flags.csv
      m SOONG_CONFIG_art_module_source_build=false out/soong/hiddenapi/hiddenapi-flags.csv
      - verify that the files are identical whether built from
        source or prebuilts.
Change-Id: I06f3c7df49626bec21a452bc9abf1bb9e7545e5c
diff --git a/java/hiddenapi_monolithic.go b/java/hiddenapi_monolithic.go
index 8a83d10..52f0770 100644
--- a/java/hiddenapi_monolithic.go
+++ b/java/hiddenapi_monolithic.go
@@ -68,6 +68,14 @@
 			if ctx.OtherModuleHasProvider(fragment, HiddenAPIInfoProvider) {
 				info := ctx.OtherModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo)
 				monolithicInfo.append(&info)
+
+				// If the bootclasspath fragment actually perform hidden API processing itself then use the
+				// CSV files it provides and do not bother processing the classesJars files. This ensures
+				// consistent behavior between source and prebuilt as prebuilt modules do not provide
+				// classesJars.
+				if info.AllFlagsPath != nil {
+					continue
+				}
 			}
 
 			classesJars = extractClassesJarsFromModules(e.Contents)