Fix OMX dependencies.

Note, filed b/62923763 to cleanup xmlparser includes.

Bug: 37343418
Test: builds with BOARD_VNDK_VERSION=current
Test: (sanity) YouTube on a device
Test: (sanity) Camera on a device
Test: (sanity) watch (part of a) movie on a device
Test: (sanity) YouTube on marlin
Test: (sanity) Camera on marlin
Test: (sanity) watch (part of a) movie on marlin
Test: (sanity) YouTube on angler
Test: (sanity) Camera on angler
Test: (sanity) watch (part of a) movie on angler

Change-Id: I461f999122da56cabb9d4d15b182899ced3b0120
Merged-In: I461f999122da56cabb9d4d15b182899ced3b0120
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 361686c..5e4d81d 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -77,6 +77,7 @@
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/libreverbwrapper.so)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/libbundlewrapper.so)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/libaudiopreprocessing.so)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/libmediacodecservice.so)
 
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
diff --git a/media/libmedia/Android.bp b/media/libmedia/Android.bp
index e9b99b4..750ff2d 100644
--- a/media/libmedia/Android.bp
+++ b/media/libmedia/Android.bp
@@ -19,24 +19,117 @@
     clang: true,
 }
 
-cc_library_shared {
-    name: "libmedia",
+// TODO(b/35449087): merge back with libmedia when OMX implementatoins
+// no longer use aidl wrappers (or remove OMX component form libmedia)
+cc_defaults {
+    name: "libmedia_omx_defaults",
+
+    srcs: [
+        "aidl/android/IGraphicBufferSource.aidl",
+        "aidl/android/IOMXBufferSource.aidl",
+
+        "IMediaCodecList.cpp",
+        "IMediaCodecService.cpp",
+        "IOMX.cpp",
+        "MediaCodecBuffer.cpp",
+        "MediaCodecInfo.cpp",
+        "MediaDefs.cpp",
+        "OMXBuffer.cpp",
+        "omx/1.0/WGraphicBufferSource.cpp",
+        "omx/1.0/WOmx.cpp",
+        "omx/1.0/WOmxBufferSource.cpp",
+        "omx/1.0/WOmxNode.cpp",
+        "omx/1.0/WOmxObserver.cpp",
+    ],
 
     aidl: {
         local_include_dirs: ["aidl"],
         export_aidl_headers: true,
     },
 
-    srcs: [
-        "aidl/android/IGraphicBufferSource.aidl",
-        "aidl/android/IOMXBufferSource.aidl",
+    shared_libs: [
+        "android.hidl.memory@1.0",
+        "android.hidl.token@1.0-utils",
+        "android.hardware.media.omx@1.0",
+        "android.hardware.media@1.0",
+        "libbase",
+        "libbinder",
+        "libcutils",
+        "libgui",
+        "libhidlbase",
+        "libhidlmemory",
+        "libhidltransport",
+        "libhwbinder",
+        "liblog",
+        "libstagefright_foundation",
+        "libui",
+        "libutils",
+    ],
 
+    include_dirs: [
+        "frameworks/av/include", // for media/vndk/xmlparser/1.0/MediaCodecsXmlParser.h
+        "frameworks/av/include/media",
+        "frameworks/native/include", // for media/hardware/MetadataBufferType.h
+        "frameworks/native/include/media/openmax",
+        "frameworks/av/media/libstagefright",
+    ],
+
+    export_shared_lib_headers: [
+        "android.hidl.memory@1.0",
+        "android.hidl.token@1.0-utils",
+        "android.hardware.media.omx@1.0",
+        "android.hardware.media@1.0",
+        "libhidlmemory",
+        "libstagefright_foundation",
+        "libui",
+    ],
+
+    header_libs: [
+        "libmedia_headers",
+    ],
+
+    export_header_lib_headers: [
+        "libmedia_headers",
+    ],
+
+    export_include_dirs: [
+        "aidl",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wno-error=deprecated-declarations",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "unsigned-integer-overflow",
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
+
+cc_library_shared {
+    name: "libmedia_omx",
+    vendor_available: true,
+
+    defaults: ["libmedia_omx_defaults"],
+}
+
+cc_library_shared {
+    name: "libmedia",
+    defaults: ["libmedia_omx_defaults"],
+
+    srcs: [
         "IDataSource.cpp",
         "IHDCP.cpp",
         "BufferingSettings.cpp",
         "mediaplayer.cpp",
-        "IMediaCodecList.cpp",
-        "IMediaCodecService.cpp",
         "IMediaHTTPConnection.cpp",
         "IMediaHTTPService.cpp",
         "IMediaExtractor.cpp",
@@ -52,9 +145,6 @@
         "IResourceManagerClient.cpp",
         "IResourceManagerService.cpp",
         "IStreamSource.cpp",
-        "MediaCodecBuffer.cpp",
-        "MediaCodecInfo.cpp",
-        "MediaDefs.cpp",
         "MediaUtils.cpp",
         "Metadata.cpp",
         "mediarecorder.cpp",
@@ -63,7 +153,6 @@
         "MidiDeviceInfo.cpp",
         "MidiIoWrapper.cpp",
         "JetPlayer.cpp",
-        "IOMX.cpp",
         "MediaScanner.cpp",
         "MediaScannerClient.cpp",
         "CharacterEncodingDetector.cpp",
@@ -71,14 +160,8 @@
         "MediaProfiles.cpp",
         "MediaResource.cpp",
         "MediaResourcePolicy.cpp",
-        "OMXBuffer.cpp",
         "Visualizer.cpp",
         "StringArray.cpp",
-        "omx/1.0/WGraphicBufferSource.cpp",
-        "omx/1.0/WOmx.cpp",
-        "omx/1.0/WOmxBufferSource.cpp",
-        "omx/1.0/WOmxNode.cpp",
-        "omx/1.0/WOmxObserver.cpp",
     ],
 
     shared_libs: [
@@ -106,11 +189,8 @@
         "libhwbinder",
         "libhidlmemory",
         "android.hidl.memory@1.0",
-        "android.hidl.token@1.0-utils",
         "android.hardware.graphics.common@1.0",
         "android.hardware.graphics.bufferqueue@1.0",
-        "android.hardware.media@1.0",
-        "android.hardware.media.omx@1.0",
     ],
 
     export_shared_lib_headers: [
@@ -119,8 +199,6 @@
         "libicui18n",
         "libsonivox",
         "libmediadrm",
-        "android.hidl.token@1.0-utils",
-        "android.hardware.media.omx@1.0",
         "android.hidl.memory@1.0",
     ],
 
@@ -136,7 +214,6 @@
     ],
 
     export_include_dirs: [
-        "aidl",
         "include",
     ],
     cflags: [
diff --git a/media/libstagefright/Android.bp b/media/libstagefright/Android.bp
index 5b8a0d1..ab75c65 100644
--- a/media/libstagefright/Android.bp
+++ b/media/libstagefright/Android.bp
@@ -89,7 +89,6 @@
         "libmediautils",
         "libnetd_client",
         "libsonivox",
-        "libstagefright_omx",
         "libui",
         "libutils",
         "libvorbisidec",
@@ -114,6 +113,7 @@
         "libstagefright_aacenc",
         "libstagefright_matroska",
         "libstagefright_mediafilter",
+        "libstagefright_omx_utils",
         "libstagefright_webm",
         "libstagefright_timedtext",
         "libvpx",
diff --git a/media/libstagefright/omx/Android.bp b/media/libstagefright/omx/Android.bp
index ff5b841..2d921f9 100644
--- a/media/libstagefright/omx/Android.bp
+++ b/media/libstagefright/omx/Android.bp
@@ -1,5 +1,6 @@
 cc_library_shared {
     name: "libstagefright_omx",
+    vendor_available: true,
 
     srcs: [
         "FrameDropper.cpp",
@@ -25,16 +26,19 @@
     ],
 
     include_dirs: [
+        "frameworks/av/include", // for media/vndk/xmlparser/1.0/MediaCodecsXmlParser.h
+        "frameworks/av/include/media/",
         "frameworks/av/media/libstagefright",
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include", // for media/hardware/MetadataBufferType.h
         "frameworks/native/include/media/hardware",
-        // TODO: export this?
         "frameworks/native/include/media/openmax",
     ],
 
     shared_libs: [
         "libbase",
         "libbinder",
-        "libmedia",
+        "libmedia_omx",
         "libutils",
         "liblog",
         "libui",
@@ -45,8 +49,10 @@
         "libhidlbase",
         "libhidlmemory",
         "libhidltransport",
+        "libnativewindow", // TODO(b/62923479): use header library
         "libstagefright_xmlparser@1.0",
         "android.hidl.memory@1.0",
+        "android.hidl.token@1.0-utils",
         "android.hardware.media@1.0",
         "android.hardware.media.omx@1.0",
         "android.hardware.graphics.common@1.0",
@@ -74,6 +80,27 @@
     },
 }
 
+cc_library_static {
+    name: "libstagefright_omx_utils",
+    srcs: ["OMXUtils.cpp"],
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/native/include/media/hardware",
+        "frameworks/native/include/media/openmax",
+    ],
+    shared_libs: ["libmedia"],
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
+
 //###############################################################################
 
 subdirs = ["tests"]
diff --git a/media/vndk/Android.bp b/media/vndk/Android.bp
index a233d6c..e93fd16 100644
--- a/media/vndk/Android.bp
+++ b/media/vndk/Android.bp
@@ -1,4 +1,4 @@
 subdirs = [
-    "*",
+    "xmlparser/1.0",
 ]
 
diff --git a/media/vndk/xmlparser/1.0/Android.bp b/media/vndk/xmlparser/1.0/Android.bp
index c48703c..2f10cb1 100644
--- a/media/vndk/xmlparser/1.0/Android.bp
+++ b/media/vndk/xmlparser/1.0/Android.bp
@@ -1,6 +1,6 @@
 cc_library_shared {
-
     name: "libstagefright_xmlparser@1.0",
+    vendor_available: true,
 
     srcs: [
         "MediaCodecsXmlParser.cpp",
diff --git a/media/vndk/xmlparser/Android.bp b/media/vndk/xmlparser/Android.bp
deleted file mode 100644
index a233d6c..0000000
--- a/media/vndk/xmlparser/Android.bp
+++ /dev/null
@@ -1,4 +0,0 @@
-subdirs = [
-    "*",
-]
-
diff --git a/services/mediacodec/Android.mk b/services/mediacodec/Android.mk
index d3df52c..8ddfb86 100644
--- a/services/mediacodec/Android.mk
+++ b/services/mediacodec/Android.mk
@@ -4,26 +4,29 @@
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := MediaCodecService.cpp
 LOCAL_SHARED_LIBRARIES := \
-    libmedia \
+    libmedia_omx \
     libbinder \
     libgui \
     libutils \
     liblog \
     libstagefright_omx
 LOCAL_C_INCLUDES := \
+    frameworks/av/include \
     frameworks/av/media/libstagefright \
+    frameworks/av/media/libstagefright/include \
+    frameworks/native/include \
     frameworks/native/include/media/openmax
 LOCAL_MODULE:= libmediacodecservice
+LOCAL_VENDOR_MODULE := true
 LOCAL_32_BIT_ONLY := true
 include $(BUILD_SHARED_LIBRARY)
 
-
 # service executable
 include $(CLEAR_VARS)
 LOCAL_REQUIRED_MODULES_arm := mediacodec.policy
 LOCAL_SRC_FILES := main_codecservice.cpp
 LOCAL_SHARED_LIBRARIES := \
-    libmedia \
+    libmedia_omx \
     libmediacodecservice \
     libbinder \
     libutils \
@@ -37,13 +40,16 @@
     libstagefright_omx \
     android.hardware.media.omx@1.0 \
     android.hidl.memory@1.0
+
 LOCAL_C_INCLUDES := \
+    frameworks/av/include \
     frameworks/av/media/libstagefright \
     frameworks/av/media/libstagefright/include \
+    frameworks/native/include \
     frameworks/native/include/media/openmax
 LOCAL_MODULE := android.hardware.media.omx@1.0-service
 LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
+LOCAL_VENDOR_MODULE := true
 LOCAL_32_BIT_ONLY := true
 LOCAL_INIT_RC := android.hardware.media.omx@1.0-service.rc
 include $(BUILD_EXECUTABLE)