Pass public API list to class2greylist tool.

This is necessary to allow it to exclude synthetic bridge methods from the
generated greylist. We need to be able to apply the @UnsupportedAppUsage
annotation to regular (non-bridged) methods, but due to the SDK visibility
rules, the synthetic bridge is part of the SDK.

Don't do this on build that don't include frameworks/base since the
target is not needed and breaks certain builds.

Bug: 110868826
Test: m
Change-Id: I08f06f38d84945f5473618513c641762bc541e24
diff --git a/core/definitions.mk b/core/definitions.mk
index 291441b..fae2459 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2875,12 +2875,15 @@
 
 # Generate a greylist.txt from a classes.jar
 define hiddenapi-generate-greylist-txt
-$(2): $(1) $(CLASS2GREYLIST)
-	$(CLASS2GREYLIST) $(1) > $(2)
+ifneq (,$(wildcard frameworks/base))
+# Only generate this target if we're in a tree with frameworks/base present.
+$(2): $(1) $(CLASS2GREYLIST) $(INTERNAL_PLATFORM_HIDDENAPI_PUBLIC_LIST)
+	$(CLASS2GREYLIST) --public-api-list $(INTERNAL_PLATFORM_HIDDENAPI_PUBLIC_LIST) $(1) > $(2)
 
 $(INTERNAL_PLATFORM_HIDDENAPI_LIGHT_GREYLIST): $(2)
 $(INTERNAL_PLATFORM_HIDDENAPI_LIGHT_GREYLIST): \
     PRIVATE_GREYLIST_INPUTS := $$(PRIVATE_GREYLIST_INPUTS) $(2)
+endif
 endef
 
 # File names for intermediate dex files of `hiddenapi-copy-soong-jar`.