Build Telecom sources once

Put all the Telecom sources and resources into an android_library
so that they are only built once and can always use a single package
name to refer to the resources once use_resource_processor: true is
enabled.

Bug: 294256649
Test: mmma packages/services/Telecomm
Change-Id: I0b2917e795757fdec0f9b12fb7c19a0a0c95a838
diff --git a/Android.bp b/Android.bp
index f46c206..7e57a3f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -10,19 +10,12 @@
     out: ["com/android/server/telecom/TelecomStatsLog.java"],
 }
 
-filegroup {
-    name: "Telecom-srcs",
+android_library {
+    name: "TelecomLib",
+    manifest: "AndroidManifestLib.xml",
     srcs: [
         "src/**/*.java",
         ":statslog-telecom-java-gen",
-    ],
-}
-
-// Build the Telecom service.
-android_app {
-    name: "Telecom",
-    srcs: [
-        ":Telecom-srcs",
         "proto/**/*.proto",
     ],
     static_libs: [
@@ -30,9 +23,6 @@
         "androidx.core_core",
         "telecom_flags_core_java_lib",
     ],
-    libs: [
-        "services",
-    ],
     resource_dirs: ["res"],
     proto: {
         type: "nano",
@@ -40,6 +30,22 @@
         output_params: ["optional_field_style=accessors"],
     },
     platform_apis: true,
+}
+
+
+// Build the Telecom service.
+android_app {
+    name: "Telecom",
+    srcs: [
+    ],
+    static_libs: [
+        "TelecomLib",
+    ],
+    libs: [
+        "services",
+    ],
+    resource_dirs: [],
+    platform_apis: true,
     certificate: "platform",
     privileged: true,
     optimize: {
@@ -50,6 +56,7 @@
 android_test {
     name: "TelecomUnitTests",
     static_libs: [
+        "TelecomLib",
         "android-ex-camera2",
         "flag-junit",
         "guava",
@@ -58,25 +65,15 @@
         "platform-test-annotations",
         "androidx.legacy_legacy-support-core-ui",
         "androidx.legacy_legacy-support-core-utils",
-        "androidx.core_core",
         "androidx.fragment_fragment",
         "androidx.test.ext.junit",
         "platform-compat-test-rules",
-        "telecom_flags_core_java_lib",
     ],
     srcs: [
         "tests/src/**/*.java",
-        ":Telecom-srcs",
-        "proto/**/*.proto",
     ],
-    proto: {
-        type: "nano",
-        local_include_dirs: ["proto/"],
-        output_params: ["optional_field_style=accessors"],
-    },
     resource_dirs: [
         "tests/res",
-        "res",
     ],
     libs: [
         "android.test.mock",
@@ -89,11 +86,6 @@
         "libstaticjvmtiagent",
     ],
 
-    aaptflags: [
-        "--auto-add-overlay",
-        "--extra-packages",
-        "com.android.server.telecom",
-    ],
     manifest: "tests/AndroidManifest.xml",
     optimize: {
         enabled: false,