Revert^2 "Provide explicitly version NNAPI AIDL utils lib -- runtime."

Reason for revert: rollforward fix of this topic

This change is a revert of Iadd823460, which itself is a revert of
I8ae01e3c6.

This CL creates multiple variants of libneuralnetworks_common for
runtime, drivers, and tests to use to avoid linking against multiple
versions of the NNAPI AIDL library.

This CL also introduces an experimental NDK feature level as the runtime
feature level under experimental build
(libneuralnetworks_static_experimental).

Reverted Changes:
I2aefa0023:Revert "Use explicitly versioned NNAPI HAL util li...
Ia7df07ab9:Revert "Add neuralnetworks_utils_hal_aidl_v2 to al...
Iadd823460:Revert "Provide explicitly version NNAPI AIDL util...
I3d3ac4745:Revert "Provide explicitly versioned NNAPI AIDL ut...

Bug: 202405342
Test: NNT_static
Test: CtsNNAPITestCases
Change-Id: If76492efa99987e8208ae976f04c927766f4de96
Merged-In: If76492efa99987e8208ae976f04c927766f4de96
(cherry picked from commit 377b178863def34d9182c6975d0be7e7d59b2ed7)
diff --git a/common/Android.bp b/common/Android.bp
index aa447f8..399ed79 100644
--- a/common/Android.bp
+++ b/common/Android.bp
@@ -95,78 +95,26 @@
     tidy_disabled_srcs: tidy_disabled_common_operations_files,
 }
 
-cc_library_static {
-    name: "libneuralnetworks_utils",
-    defaults: [
-        "neuralnetworks_defaults",
-        "neuralnetworks_operations",
-    ],
-    host_supported: true,
-    vendor_available: true,
-    apex_available: [
-        "//apex_available:platform",
-        "com.android.neuralnetworks",
-        "test_com.android.neuralnetworks",
-    ],
-    export_include_dirs: ["include"],
-    srcs: [
-        "AidlHalUtils.cpp",
-        "ExecutionBurstController.cpp",
-        "ExecutionBurstServer.cpp",
-        "LegacyHalUtils.cpp",
-        "LegacyUtils.cpp",
-        "MemoryUtils.cpp",
-    ],
-    header_libs: [
-        "gemmlowp_headers",
-        "libeigen",
-        "libneuralnetworks_headers",
-        "libruy_headers",
-        "tensorflow_headers",
-    ],
-    shared_libs: [
-        "android.hardware.neuralnetworks-V2-ndk",
-        "[email protected]",
-        "[email protected]",
-        "[email protected]",
-        "[email protected]",
-        "[email protected]",
-        "[email protected]",
-        "libfmq",
-        "libhidlbase",
-        "libhidlmemory",
-    ],
-    whole_static_libs: [
-        "libarect",
-        "neuralnetworks_types",
-        "neuralnetworks_utils_hal_1_0", // TODO(b/160669116): Remove VNDK dependencies.
-        "neuralnetworks_utils_hal_1_1",
-        "neuralnetworks_utils_hal_1_2",
-        "neuralnetworks_utils_hal_1_3",
-        "neuralnetworks_utils_hal_aidl",
-        "neuralnetworks_utils_hal_common",
-    ],
-    target: {
-        android: {
-            shared_libs: [
-                "libnativewindow",
-            ],
-        },
-        host: {
-            cflags: [
-                "-D__ANDROID_API__=10000",
-                "-D__INTRODUCED_IN(n)=",
-                "-D__assert(a,b,c)=",
-            ],
-        },
-    },
-    cflags: [
-        "-DTF_LITE_DISABLE_X86_NEON",
-    ],
-}
-
+// libneuralnetworks_common* provides common utilities for the NNAPI runtime, drivers, and tests to
+// use. Multiple variants of the common library are provided:
+// - libneuralnetworks_common_hidl: the common library without any AIDL dependencies, used by
+//   NNAPI HIDL drivers and tests.
+// - libneuralnetworks_common_aidl(_vx): explicitly versioned common libraries linking against the
+//   corresponding version of the NNAPI sAIDL library, used by NNAPI sAIDL drivers.
+//   We need a variant for every frozen AIDL version because it is not allowed for a build target
+//   to depend on multiple versions of the NNAPI sAIDL library.
+//   libneuralnetworks_common_aidl (without a version listed behind it) is the current version.
+// - libneuralnetworks_common: the common library that links against the latest stable version of
+//   the NNAPI sAIDL library, used by NNAPI runtime and tests.
+// - libneuralnetworks_common_experimental: the common library that links against the "current"
+//   version of the NNAPI sAIDL library with NN_EXPERIMENTAL_FEATURE flag turned on, used by NNAPI
+//   drivers and tests for experimental features.
+//
+// In addition to the AIDL dependencies, all variants of the common library also link against all
+// versions (1.0-3) of the NNAPI HIDL library.
+//
 cc_defaults {
-    name: "libneuralnetworks_common_defaults",
+    name: "libneuralnetworks_common_hidl_defaults",
     defaults: [
         "neuralnetworks_defaults",
         "neuralnetworks_operations",
@@ -184,9 +132,6 @@
         "include",
     ],
     srcs: [
-        "AidlBufferTracker.cpp",
-        "AidlHalUtils.cpp",
-        "AidlValidateHal.cpp",
         "BufferTracker.cpp",
         "CpuExecutor.cpp",
         "ExecutionBurstController.cpp",
@@ -223,7 +168,6 @@
         "operations/Tile.cpp",
     ],
     shared_libs: [
-        "android.hardware.neuralnetworks-V2-ndk",
         "[email protected]",
         "[email protected]",
         "[email protected]",
@@ -266,9 +210,7 @@
         "neuralnetworks_utils_hal_1_1",
         "neuralnetworks_utils_hal_1_2",
         "neuralnetworks_utils_hal_1_3",
-        "neuralnetworks_utils_hal_aidl",
         "neuralnetworks_utils_hal_common",
-        "neuralnetworks_utils_hal_service",
         "philox_random",
     ],
     static_libs: [
@@ -284,14 +226,64 @@
 }
 
 cc_library_static {
+    name: "libneuralnetworks_common_hidl",
+    defaults: [
+        "libneuralnetworks_common_hidl_defaults",
+    ],
+}
+
+cc_defaults {
+    name: "libneuralnetworks_common_aidl_defaults",
+    defaults: [
+        "libneuralnetworks_common_hidl_defaults",
+    ],
+    srcs: [
+        "AidlBufferTracker.cpp",
+        "AidlHalUtils.cpp",
+        "AidlValidateHal.cpp",
+    ],
+}
+
+cc_library_static {
+    name: "libneuralnetworks_common_aidl_v1",
+    defaults: [
+        "libneuralnetworks_common_aidl_defaults",
+    ],
+    shared_libs: [
+        "android.hardware.neuralnetworks-V1-ndk",
+    ],
+    whole_static_libs: [
+        "neuralnetworks_utils_hal_aidl_v1",
+    ],
+}
+
+cc_library_static {
     name: "libneuralnetworks_common",
-    defaults: ["libneuralnetworks_common_defaults"],
+    defaults: [
+        "libneuralnetworks_common_aidl_defaults",
+    ],
+    shared_libs: [
+        "android.hardware.neuralnetworks-V2-ndk",
+    ],
+    whole_static_libs: [
+        "neuralnetworks_utils_hal_aidl",
+    ],
 }
 
 cc_library_static {
     name: "libneuralnetworks_common_experimental",
-    defaults: ["libneuralnetworks_common_defaults"],
-    cflags: ["-DNN_EXPERIMENTAL_FEATURE"],
+    defaults: [
+        "libneuralnetworks_common_aidl_defaults",
+    ],
+    shared_libs: [
+        "android.hardware.neuralnetworks-V2-ndk",
+    ],
+    whole_static_libs: [
+        "neuralnetworks_utils_hal_aidl",
+    ],
+    cflags: [
+        "-DNN_EXPERIMENTAL_FEATURE",
+    ],
 }
 
 cc_defaults {
@@ -497,7 +489,10 @@
 
 cc_defaults {
     name: "NeuralNetworksTest_common",
-    defaults: ["neuralnetworks_float16"],
+    defaults: [
+        "neuralnetworks_float16",
+        "neuralnetworks_use_latest_utils_hal_aidl",
+    ],
     host_supported: true,
     shared_libs: [
         "[email protected]",
@@ -510,7 +505,6 @@
         "libutils",
     ],
     static_libs: [
-        "android.hardware.neuralnetworks-V2-ndk",
         "[email protected]",
         "[email protected]",
         "[email protected]",