Make libstatssocket a shared_lib

Make libstatssocket unable to be linked as a static lib on the platform.

Test: bit libstatssocket_test:*
Test: bit statsd_test:*
Test: atest LibStatsPullTests
Bug: 149340100

Merged-In: I5889dd718536f5f2c693b4c2e7331c9cc2eb2ac9
(cherry picked from commit d78f4dab02b664fb7164763cdbdd52f3fbc226a5)
Change-Id: I5889dd718536f5f2c693b4c2e7331c9cc2eb2ac9
diff --git a/libstats/socket/Android.bp b/libstats/socket/Android.bp
index 6882ab2..6fd9728 100644
--- a/libstats/socket/Android.bp
+++ b/libstats/socket/Android.bp
@@ -17,8 +17,8 @@
 // =========================================================================
 // Native library to write stats log to statsd socket on Android R and later
 // =========================================================================
-cc_library {
-    name: "libstatssocket",
+cc_defaults {
+    name: "libstatssocket_defaults",
     srcs: [
         "stats_buffer_writer.c",
         "stats_event.c",
@@ -27,7 +27,10 @@
         "stats_event_list.c",
         "statsd_writer.c",
     ],
-    host_supported: true,
+    export_include_dirs: ["include"],
+    static_libs: [
+        "libcutils", // does not expose a stable C API
+    ],
     cflags: [
         "-Wall",
         "-Werror",
@@ -35,11 +38,28 @@
         "-DWRITE_TO_STATSD=1",
         "-DWRITE_TO_LOGD=0",
     ],
-    export_include_dirs: ["include"],
-    shared_libs: [
-        "libcutils",
-        "liblog",
+}
+
+
+cc_library {
+    name: "libstatssocket",
+    defaults: [
+        "libstatssocket_defaults",
     ],
+    host_supported: true,
+    target: {
+        // On android, libstatssocket should only be linked as a shared lib
+        android: {
+            static: {
+                enabled: false,
+            },
+        },
+        host: {
+            shared: {
+                enabled: false,
+            },
+        },
+    },
 
     // enumerate stable entry points for APEX use
     stubs: {
@@ -47,7 +67,23 @@
         versions: [
             "1",
         ],
-    }
+    },
+    apex_available: [
+        "com.android.os.statsd",
+        "test_com.android.os.statsd",
+    ],
+}
+
+//TODO (b/149842105): Figure out if there is a better solution for this.
+cc_test_library {
+    name: "libstatssocket_private",
+    defaults: [
+        "libstatssocket_defaults",
+    ],
+    visibility: [
+        "//frameworks/base/apex/statsd/tests/libstatspull",
+        "//frameworks/base/cmds/statsd",
+    ],
 }
 
 cc_library_headers {
@@ -69,7 +105,7 @@
         "-Werror",
     ],
     static_libs: [
-        "libstatssocket",
+        "libstatssocket_private",
     ],
     shared_libs: [
         "libcutils",
@@ -87,7 +123,7 @@
     ],
     static_libs: [
         "libgmock",
-        "libstatssocket",
+        "libstatssocket_private",
     ],
     shared_libs: [
         "libcutils",