Compose the main stubs jars from module stubs

This adds stub generation for the non-updatable part of the platform,
and changes the full stub jars to be a combination of multiple jars:
the stubs of the updatable modules and the stubs of the remaining part
of the platform.

Composing the stub jars like this allows overriding the individual parts
with prebuilts rather than building everything from source. This makes
the build safer, as we can make sure that the stub of the apex that is
used is also what is used to build the rest of the platform against.

The monolithic droidstubs rules remain for now, as it has other
functions than generating stub sources (api lint, current.txt,
checklast). It remains a goal to get rid of this, but by submitting this
CL first it can be done in steps.

Bug: 144149403
Test: m android{,_system}_{monolith,merged}_stubs_current
Test: m
Change-Id: I255486112c03f237aa342cfb93f3b473a2f50470
Merged-In: I255486112c03f237aa342cfb93f3b473a2f50470
diff --git a/StubLibraries.bp b/StubLibraries.bp
index 83b0eb2..6e6efe5 100644
--- a/StubLibraries.bp
+++ b/StubLibraries.bp
@@ -84,7 +84,7 @@
     // finalized stub library to resolve them. If a new class gets added,
     // this may be need to be revisited to use a manually maintained stub
     // library with empty classes in order to resolve those references.
-    libs: ["sdk_system_29_android"],
+    libs: ["sdk_system_30_android"],
     aidl: {
         local_include_dirs: ["apex/media/aidl/stable"],
     },
@@ -129,6 +129,23 @@
     jdiff_enabled: true,
 }
 
+droidstubs {
+    name: "api-stubs-docs-non-updatable",
+    defaults: ["metalava-non-updatable-api-stubs-default"],
+    arg_files: ["core/res/AndroidManifest.xml"],
+    args: metalava_framework_docs_args,
+    check_api: {
+        current: {
+            api_file: "non-updatable-api/current.txt",
+            removed_api_file: "non-updatable-api/removed.txt",
+        },
+        api_lint: {
+            enabled: true,
+            new_since: ":android-non-updatable.api.public.latest",
+        },
+    },
+}
+
 priv_apps = " " +
     "--show-annotation android.annotation.SystemApi\\(" +
         "client=android.annotation.SystemApi.Client.PRIVILEGED_APPS" +
@@ -172,6 +189,24 @@
 }
 
 droidstubs {
+    name: "system-api-stubs-docs-non-updatable",
+    defaults: ["metalava-non-updatable-api-stubs-default"],
+    arg_files: ["core/res/AndroidManifest.xml"],
+    args: metalava_framework_docs_args + priv_apps,
+    check_api: {
+        current: {
+            api_file: "non-updatable-api/system-current.txt",
+            removed_api_file: "non-updatable-api/system-removed.txt",
+        },
+        api_lint: {
+            enabled: true,
+            new_since: ":android-non-updatable.api.system.latest",
+            baseline_file: "non-updatable-api/system-lint-baseline.txt",
+        },
+    },
+}
+
+droidstubs {
     name: "test-api-stubs-docs",
     defaults: ["metalava-full-api-stubs-default"],
     arg_files: [
@@ -234,6 +269,22 @@
     },
 }
 
+droidstubs {
+    name: "module-lib-api-stubs-docs-non-updatable",
+    defaults: ["metalava-non-updatable-api-stubs-default"],
+    arg_files: ["core/res/AndroidManifest.xml"],
+    args: metalava_framework_docs_args + module_libs,
+    check_api: {
+        current: {
+            api_file: "non-updatable-api/module-lib-current.txt",
+            removed_api_file: "non-updatable-api/module-lib-removed.txt",
+        },
+        api_lint: {
+            enabled: true,
+            new_since: ":android-non-updatable.api.module-lib.latest",
+        },
+    },
+}
 
 // The following droidstub module generates source files for the API stub library for
 // modules. Note that it not only includes its own APIs but also other APIs that have
@@ -267,20 +318,66 @@
 }
 
 java_library_static {
-    name: "android_stubs_current",
+    name: "android_monolith_stubs_current",
     srcs: [ ":api-stubs-docs" ],
     static_libs: [ "private-stub-annotations-jar" ],
     defaults: ["android_defaults_stubs_current"],
 }
 
 java_library_static {
-    name: "android_system_stubs_current",
+    name: "android_merged_stubs_current",
+    srcs: [ ":api-stubs-docs-non-updatable" ],
+    static_libs: [
+        "conscrypt.module.public.api.stubs",
+        "framework-media-stubs-publicapi",
+        "framework-mediaprovider-stubs-publicapi",
+        "framework-permission-stubs-publicapi",
+        "framework-sdkextensions-stubs-publicapi",
+        "framework-statsd-stubs-publicapi",
+        "framework-tethering-stubs-publicapi",
+        "framework-wifi-stubs-publicapi",
+        "private-stub-annotations-jar",
+    ],
+    defaults: ["android_defaults_stubs_current"],
+}
+
+java_library_static {
+    name: "android_stubs_current",
+    static_libs: ["android_merged_stubs_current"],
+    defaults: ["android_defaults_stubs_current"],
+}
+
+java_library_static {
+    name: "android_system_monolith_stubs_current",
     srcs: [ ":system-api-stubs-docs" ],
     static_libs: [ "private-stub-annotations-jar" ],
     defaults: ["android_defaults_stubs_current"],
 }
 
 java_library_static {
+    name: "android_system_merged_stubs_current",
+    srcs: [ ":system-api-stubs-docs-non-updatable" ],
+    static_libs: [
+        "conscrypt.module.public.api.stubs",
+        "framework-media-stubs-systemapi",
+        "framework-mediaprovider-stubs-systemapi",
+        "framework-permission-stubs-systemapi",
+        "framework-sdkextensions-stubs-systemapi",
+        "framework-statsd-stubs-systemapi",
+        "framework-tethering-stubs-systemapi",
+        "framework-wifi-stubs-systemapi",
+        "private-stub-annotations-jar",
+    ],
+    defaults: ["android_defaults_stubs_current"],
+}
+
+java_library_static {
+    name: "android_system_stubs_current",
+    static_libs: ["android_system_merged_stubs_current"],
+    defaults: ["android_defaults_stubs_current"],
+}
+
+java_library_static {
     name: "android_test_stubs_current",
     srcs: [ ":test-api-stubs-docs" ],
     static_libs: [ "private-stub-annotations-jar" ],
@@ -294,6 +391,20 @@
     libs: ["sdk_system_29_android"],
 }
 
+java_library_static {
+    name: "android_non_updatable_stubs_current",
+    srcs: [":api-stubs-docs-non-updatable"],
+    defaults: ["android_defaults_stubs_current"],
+    libs: ["sdk_system_29_android"],
+}
+
+java_library_static {
+    name: "android_system_non_updatable_stubs_current",
+    srcs: [":system-api-stubs-docs-non-updatable"],
+    defaults: ["android_defaults_stubs_current"],
+    libs: ["sdk_system_29_android"],
+}
+
 /////////////////////////////////////////////////////////////////////
 // hwbinder.stubs provides APIs required for building HIDL Java
 // libraries.