Enable from-text stub generation in non-sdk java_sdk_library

This change allows from-text stubs to be generated for all
java_sdk_library modules, unlike how it is currently limited to the
modules that contribute to the api surfaces (i.e. the SDK).

This change accomplish this by modifying the dependency of the
from-text stubs generation, so that the sdk_library generated from-text
stubs generating java_api_library modules no longer depend on the full
api surface stubs, but generate the stubs in the module level, and
combined later to generate the full api surface stubs.

This change also removes the java_api_library modules defined in
core-libraries/Android.bp, which are passed to generate the system
modules. Given that the from-text vs from-source toggle is done within
the java_sdk_library stubs level, these modules no longer need to exist.

Implementation details:
- Allow sdk_version to be specified in java_api_library modules. For
  java_sdk_library-generated java_api_library modules, they inherit that
  of the sdk_library module. Some java_sdk_library modules that do not
  contribute to the api surface are allowed to set sdk_version to
  something other than "none" or "core".
- Implement java_api_library to implement `SdkContext`. This allows
  java_api_library to collect required deps from sdk_version (classpath,
  bootclasspath, system modules), and pass the collected jars when
  generating the stubs srcjar in metalava and compiling the stubs srcjar
  in javac.
- Remove hardcoded list of sdk_library modules that are allowed to
  genereate stubs from the api signature files, and allow from-text
  stubs generation by default. Modules that are not able to generate
  stubs from the api signature files are specified by setting the newly
  introduced `Build_from_text_stubs` property to `false`.

Test: ENABLE_HIDDENAPI_FLAGS=true m
Bug: 327507877
Change-Id: Ia35d2f3cf9fae48fc8c4bd99a84ae18d7c0e7bee
diff --git a/java/core-libraries/Android.bp b/java/core-libraries/Android.bp
index ab72e8b..cee7a19 100644
--- a/java/core-libraries/Android.bp
+++ b/java/core-libraries/Android.bp
@@ -41,7 +41,7 @@
 }
 
 java_library {
-    name: "core.current.stubs.from-source",
+    name: "core.current.stubs",
     defaults: [
         "core.current.stubs.defaults",
     ],
@@ -52,8 +52,12 @@
     ],
 }
 
+// Used for bootstrapping ART system modules
 java_api_library {
     name: "core.current.stubs.from-text",
+    defaults: [
+        "core.current.stubs.defaults",
+    ],
     api_surface: "core",
     api_contributions: [
         "art.module.public.api.stubs.source.api.contribution",
@@ -68,27 +72,7 @@
 }
 
 java_library {
-    name: "core.current.stubs",
-    defaults: [
-        "core.current.stubs.defaults",
-    ],
-    static_libs: [
-        "core.current.stubs.from-source",
-    ],
-    product_variables: {
-        build_from_text_stub: {
-            static_libs: [
-                "core.current.stubs.from-text",
-            ],
-            exclude_static_libs: [
-                "core.current.stubs.from-source",
-            ],
-        },
-    },
-}
-
-java_library {
-    name: "core.current.stubs.exportable.from-source",
+    name: "core.current.stubs.exportable",
     defaults: [
         "core.current.stubs.defaults",
     ],
@@ -103,16 +87,6 @@
     },
 }
 
-java_library {
-    name: "core.current.stubs.exportable",
-    defaults: [
-        "core.current.stubs.defaults",
-    ],
-    static_libs: [
-        "core.current.stubs.exportable.from-source",
-    ],
-}
-
 // Distributed with the SDK for turning into system modules to compile apps
 // against.
 //
@@ -201,26 +175,6 @@
         "core.module_lib.stubs.defaults",
     ],
     static_libs: [
-        "core.module_lib.stubs.from-source",
-    ],
-    product_variables: {
-        build_from_text_stub: {
-            static_libs: [
-                "core.module_lib.stubs.from-text",
-            ],
-            exclude_static_libs: [
-                "core.module_lib.stubs.from-source",
-            ],
-        },
-    },
-}
-
-java_library {
-    name: "core.module_lib.stubs.from-source",
-    defaults: [
-        "core.module_lib.stubs.defaults",
-    ],
-    static_libs: [
         "art.module.public.api.stubs.module_lib",
 
         // Replace the following with the module-lib correspondence when Conscrypt or i18N module
@@ -231,27 +185,6 @@
     ],
 }
 
-java_api_library {
-    name: "core.module_lib.stubs.from-text",
-    api_surface: "module-lib",
-    api_contributions: [
-        "art.module.public.api.stubs.source.api.contribution",
-        "art.module.public.api.stubs.source.system.api.contribution",
-        "art.module.public.api.stubs.source.module_lib.api.contribution",
-
-        // Add the module-lib correspondence when Conscrypt or i18N module
-        // provides @SystemApi(MODULE_LIBRARIES). Currently, assume that only ART module provides
-        // @SystemApi(MODULE_LIBRARIES).
-        "conscrypt.module.public.api.stubs.source.api.contribution",
-        "i18n.module.public.api.stubs.source.api.contribution",
-    ],
-    libs: [
-        "stub-annotations",
-    ],
-    visibility: ["//visibility:private"],
-    stubs_type: "everything",
-}
-
 // Produces a dist file that is used by the
 // prebuilts/sdk/update_prebuilts.py script to update the prebuilts/sdk
 // directory.
@@ -311,7 +244,7 @@
 // API annotations are available to the dex tools that enable enforcement of runtime
 // accessibility. b/119068555
 java_library {
-    name: "legacy.core.platform.api.stubs.from-source",
+    name: "legacy.core.platform.api.stubs",
     visibility: core_platform_visibility,
     defaults: [
         "core.platform.api.stubs.defaults",
@@ -324,7 +257,7 @@
 }
 
 java_library {
-    name: "legacy.core.platform.api.stubs.exportable.from-source",
+    name: "legacy.core.platform.api.stubs.exportable",
     visibility: core_platform_visibility,
     defaults: [
         "core.platform.api.stubs.defaults",
@@ -348,53 +281,6 @@
     ],
 }
 
-java_api_library {
-    name: "legacy.core.platform.api.stubs.from-text",
-    api_surface: "core_platform",
-    defaults: [
-        "android_core_platform_stubs_current_contributions",
-    ],
-    api_contributions: [
-        "legacy.i18n.module.platform.api.stubs.source.api.contribution",
-    ],
-    libs: [
-        "stub-annotations",
-    ],
-    stubs_type: "everything",
-}
-
-java_library {
-    name: "legacy.core.platform.api.stubs",
-    visibility: core_platform_visibility,
-    defaults: [
-        "core.platform.api.stubs.defaults",
-    ],
-    static_libs: [
-        "legacy.core.platform.api.stubs.from-source",
-    ],
-    product_variables: {
-        build_from_text_stub: {
-            static_libs: [
-                "legacy.core.platform.api.stubs.from-text",
-            ],
-            exclude_static_libs: [
-                "legacy.core.platform.api.stubs.from-source",
-            ],
-        },
-    },
-}
-
-java_library {
-    name: "legacy.core.platform.api.stubs.exportable",
-    visibility: core_platform_visibility,
-    defaults: [
-        "core.platform.api.stubs.defaults",
-    ],
-    static_libs: [
-        "legacy.core.platform.api.stubs.exportable.from-source",
-    ],
-}
-
 java_defaults {
     name: "core.platform.api.stubs.defaults",
     hostdex: true,
@@ -424,7 +310,7 @@
 }
 
 java_library {
-    name: "stable.core.platform.api.stubs.from-source",
+    name: "stable.core.platform.api.stubs",
     visibility: core_platform_visibility,
     defaults: [
         "core.platform.api.stubs.defaults",
@@ -437,42 +323,6 @@
     ],
 }
 
-java_api_library {
-    name: "stable.core.platform.api.stubs.from-text",
-    api_surface: "core_platform",
-    defaults: [
-        "android_core_platform_stubs_current_contributions",
-    ],
-    api_contributions: [
-        "stable.i18n.module.platform.api.stubs.source.api.contribution",
-    ],
-    libs: [
-        "stub-annotations",
-    ],
-    stubs_type: "everything",
-}
-
-java_library {
-    name: "stable.core.platform.api.stubs",
-    visibility: core_platform_visibility,
-    defaults: [
-        "core.platform.api.stubs.defaults",
-    ],
-    static_libs: [
-        "stable.core.platform.api.stubs.from-source",
-    ],
-    product_variables: {
-        build_from_text_stub: {
-            static_libs: [
-                "stable.core.platform.api.stubs.from-text",
-            ],
-            exclude_static_libs: [
-                "stable.core.platform.api.stubs.from-source",
-            ],
-        },
-    },
-}
-
 // Same as stable.core.platform.api.stubs, but android annotations are
 // stripped. This is used by the Java toolchain, while the annotated stub is to
 // be used by Kotlin one.