Merge changes I907533c3,I8502eb90,I60c82e0f,Id4070113,I31c6d0fa

* changes:
  Switch service-permissions to java_sdk_library
  Make module apis dist their output
  Include annotations in module metalava runs
  Dist module stub libraries for in sdk builds
  Use module_current to build module stubs
diff --git a/apex/Android.bp b/apex/Android.bp
index 79ab3e4..6eaf89c 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -66,9 +66,9 @@
     "--hide-annotation android.annotation.Hide " +
     "--hide InternalClasses " // com.android.* classes are okay in this interface
 
-// Defaults for mainline module provided java_sdk_library instances.
+// Defaults common to all mainline module java_sdk_library instances.
 java_defaults {
-    name: "framework-module-defaults",
+    name: "framework-module-common-defaults",
 
     // Additional annotations used for compiling both the implementation and the
     // stubs libraries.
@@ -95,14 +95,6 @@
         enabled: true,
         sdk_version: "module_current",
     },
-    system: {
-        enabled: true,
-        sdk_version: "module_current",
-    },
-    module_lib: {
-        enabled: true,
-        sdk_version: "module_current",
-    },
 
     // Configure framework module specific metalava options.
     droiddoc_options: [mainline_stubs_args],
@@ -132,11 +124,41 @@
     sdk_version: "module_current",
 }
 
+// Defaults for mainline module provided java_sdk_library instances.
+java_defaults {
+    name: "framework-module-defaults",
+    defaults: ["framework-module-common-defaults"],
+
+    system: {
+        enabled: true,
+        sdk_version: "module_current",
+    },
+    module_lib: {
+        enabled: true,
+        sdk_version: "module_current",
+    },
+}
+
+// Defaults for mainline module system server provided java_sdk_library instances.
+java_defaults {
+    name: "framework-system-server-module-defaults",
+    defaults: ["framework-module-common-defaults"],
+
+    system_server: {
+        enabled: true,
+        sdk_version: "module_current",
+    },
+}
+
 stubs_defaults {
     name: "framework-module-stubs-defaults-publicapi",
     args: mainline_framework_stubs_args,
     installable: false,
-    sdk_version: "current",
+    sdk_version: "module_current",
+    annotations_enabled: true,
+    merge_annotations_dirs: [
+        "metalava-manual",
+    ],
     filter_packages: framework_packages_to_document,
     check_api: {
         current: {
@@ -144,6 +166,10 @@
             removed_api_file: "api/removed.txt",
         },
     },
+    dist: {
+        targets: ["sdk", "win_sdk"],
+        dir: "apistubs/android/public/api",
+    },
 }
 
 stubs_defaults {
@@ -151,7 +177,11 @@
     args: mainline_framework_stubs_args + priv_apps,
     libs: ["framework-annotations-lib"],
     installable: false,
-    sdk_version: "system_current",
+    sdk_version: "module_current",
+    annotations_enabled: true,
+    merge_annotations_dirs: [
+        "metalava-manual",
+    ],
     filter_packages: framework_packages_to_document,
     check_api: {
         current: {
@@ -159,24 +189,43 @@
             removed_api_file: "api/system-removed.txt",
         },
     },
+    dist: {
+        targets: ["sdk", "win_sdk"],
+        dir: "apistubs/android/system/api",
+    },
 }
 
 java_defaults {
     name: "framework-module-stubs-lib-defaults-publicapi",
     installable: false,
     sdk_version: "module_current",
+    libs: [ "stub-annotations" ],
+    dist: {
+        targets: ["sdk", "win_sdk"],
+        dir: "apistubs/android/public",
+    },
 }
 
 java_defaults {
     name: "framework-module-stubs-lib-defaults-systemapi",
     installable: false,
     sdk_version: "module_current",
+    libs: [ "stub-annotations" ],
+    dist: {
+        targets: ["sdk", "win_sdk"],
+        dir: "apistubs/android/system",
+    },
 }
 
 java_defaults {
     name: "framework-module-stubs-lib-defaults-module_libs_api",
     installable: false,
     sdk_version: "module_current",
+    libs: [ "stub-annotations" ],
+    dist: {
+        targets: ["sdk", "win_sdk"],
+        dir: "apistubs/android/module-lib",
+    },
 }
 
 // The defaults for module_libs comes in two parts - defaults for API checks
@@ -190,6 +239,10 @@
     libs: ["framework-annotations-lib"],
     installable: false,
     sdk_version: "module_current",
+    annotations_enabled: true,
+    merge_annotations_dirs: [
+        "metalava-manual",
+    ],
     filter_packages: framework_packages_to_document,
 
     // Do not generate stubs as they are not needed
@@ -201,6 +254,10 @@
             removed_api_file: "api/module-lib-removed.txt",
         },
     },
+    dist: {
+        targets: ["sdk", "win_sdk"],
+        dir: "apistubs/android/module-lib/api",
+    },
 }
 
 stubs_defaults {
@@ -209,6 +266,10 @@
     libs: ["framework-annotations-lib"],
     installable: false,
     sdk_version: "module_current",
+    annotations_enabled: true,
+    merge_annotations_dirs: [
+        "metalava-manual",
+    ],
     filter_packages: framework_packages_to_document,
 }
 
@@ -216,6 +277,10 @@
     name: "service-module-stubs-srcs-defaults",
     args: mainline_service_stubs_args,
     installable: false,
+    annotations_enabled: true,
+    merge_annotations_dirs: [
+        "metalava-manual",
+    ],
     filter_packages: ["com.android."],
     check_api: {
         current: {
@@ -223,10 +288,18 @@
             removed_api_file: "api/removed.txt",
         },
     },
+    dist: {
+        targets: ["sdk", "win_sdk"],
+        dir: "apistubs/android/system-server/api",
+    },
 }
 
 // Empty for now, but a convenient place to add rules for all
 // module java_library system_server stub libs.
 java_defaults {
     name: "service-module-stubs-defaults",
+    dist: {
+        targets: ["sdk", "win_sdk"],
+        dir: "apistubs/android/system-server",
+    },
 }