Prevent OOB write in soft_avc encoder am: 463452a949 am: 97db64baf6 am: b6bf46944f am: cd35c846f0 am: a43be7d42d am: 3c375611d6 am: 96b4e70f44 am: 9eb9b1b849 am: 91af834b13
am: ebc26bd50e

Change-Id: Iad96d68e8d417bf51a0ecaa8403f37fcd30c9a2c
diff --git a/Android.bp b/Android.bp
index 53f8bec..b207a96 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,20 +1,7 @@
-ndk_headers {
-    name: "libcamera2ndk_headers",
-    from: "include/camera/ndk/",
-    to: "camera",
-    srcs: ["include/camera/ndk/**/*.h"],
-    license: "NOTICE",
-}
-
-ndk_headers {
-    name: "libmediandk_headers",
-    from: "include/ndk/",
-    to: "media",
-    srcs: ["include/ndk/**/*.h"],
-    license: "NOTICE",
-}
-
 subdirs = [
-    "camera/ndk",
+    "camera",
+    "drm/*",
     "media/*",
+    "radio",
+    "soundtrigger",
 ]
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 5c11bfa..1e327a3 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -70,6 +70,12 @@
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/libeffects.so)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib64/libeffects.so)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libeffects_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/libeffectproxy.so)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/libldnhncr.so)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/libdownmix.so)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/libvisualizer.so)
+$(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)
 
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
diff --git a/camera/Android.bp b/camera/Android.bp
new file mode 100644
index 0000000..7ff3e89
--- /dev/null
+++ b/camera/Android.bp
@@ -0,0 +1,78 @@
+// Copyright 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+subdirs = ["ndk"]
+
+cc_library_shared {
+    name: "libcamera_client",
+
+    aidl: {
+        export_aidl_headers: true,
+        local_include_dirs: ["aidl"],
+        include_dirs: [
+            "frameworks/base/core/java",
+            "frameworks/native/aidl/gui",
+        ],
+    },
+
+    srcs: [
+        // AIDL files for camera interfaces
+        // The headers for these interfaces will be available to any modules that
+        // include libcamera_client, at the path "aidl/package/path/BnFoo.h"
+        "aidl/android/hardware/ICameraService.aidl",
+        "aidl/android/hardware/ICameraServiceListener.aidl",
+        "aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl",
+        "aidl/android/hardware/camera2/ICameraDeviceUser.aidl",
+
+        // Source for camera interface parcelables, and manually-written interfaces
+        "Camera.cpp",
+        "CameraMetadata.cpp",
+        "CameraParameters.cpp",
+        "CaptureResult.cpp",
+        "CameraParameters2.cpp",
+        "ICamera.cpp",
+        "ICameraClient.cpp",
+        "ICameraServiceProxy.cpp",
+        "ICameraRecordingProxy.cpp",
+        "ICameraRecordingProxyListener.cpp",
+        "camera2/CaptureRequest.cpp",
+        "camera2/OutputConfiguration.cpp",
+        "camera2/SubmitInfo.cpp",
+        "CameraBase.cpp",
+        "CameraUtils.cpp",
+        "VendorTagDescriptor.cpp",
+    ],
+
+    shared_libs: [
+        "libcutils",
+        "libutils",
+        "liblog",
+        "libbinder",
+        "libgui",
+        "libcamera_metadata",
+    ],
+
+    include_dirs: [
+        "system/media/private/camera/include",
+        "frameworks/native/include/media/openmax",
+    ],
+    export_include_dirs: ["include/camera"],
+    export_shared_lib_headers: ["libcamera_metadata"],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+        "-Wextra",
+    ],
+}
diff --git a/camera/Android.mk b/camera/Android.mk
index 91d87ed..d9068c0 100644
--- a/camera/Android.mk
+++ b/camera/Android.mk
@@ -12,67 +12,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-CAMERA_CLIENT_LOCAL_PATH:= $(call my-dir)
 include $(call all-subdir-makefiles)
-include $(CLEAR_VARS)
-
-LOCAL_PATH := $(CAMERA_CLIENT_LOCAL_PATH)
-
-LOCAL_AIDL_INCLUDES := \
-    frameworks/av/camera/aidl \
-    frameworks/base/core/java \
-    frameworks/native/aidl/gui
-
-# AIDL files for camera interfaces
-# The headers for these interfaces will be available to any modules that
-# include libcamera_client, at the path "aidl/package/path/BnFoo.h"
-
-LOCAL_SRC_FILES := \
-    aidl/android/hardware/ICameraService.aidl \
-    aidl/android/hardware/ICameraServiceListener.aidl \
-    aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl \
-    aidl/android/hardware/camera2/ICameraDeviceUser.aidl
-
-# Source for camera interface parcelables, and manually-written interfaces
-
-LOCAL_SRC_FILES += \
-	Camera.cpp \
-	CameraMetadata.cpp \
-	CameraParameters.cpp \
-	CaptureResult.cpp \
-	CameraParameters2.cpp \
-	ICamera.cpp \
-	ICameraClient.cpp \
-	ICameraServiceProxy.cpp \
-	ICameraRecordingProxy.cpp \
-	ICameraRecordingProxyListener.cpp \
-	camera2/CaptureRequest.cpp \
-	camera2/OutputConfiguration.cpp \
-	camera2/SubmitInfo.cpp \
-	CameraBase.cpp \
-	CameraUtils.cpp \
-	VendorTagDescriptor.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-	libutils \
-	liblog \
-	libbinder \
-	libgui \
-	libcamera_metadata \
-
-LOCAL_C_INCLUDES += \
-	system/media/camera/include \
-	system/media/private/camera/include \
-	frameworks/native/include/media/openmax \
-	$(LOCAL_PATH)/include/camera
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := \
-	system/media/camera/include \
-	$(LOCAL_PATH)/include/camera
-
-LOCAL_CFLAGS += -Werror -Wall -Wextra
-
-LOCAL_MODULE:= libcamera_client
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/camera/cameraserver/Android.mk b/camera/cameraserver/Android.mk
index d32e252..b8c94e6 100644
--- a/camera/cameraserver/Android.mk
+++ b/camera/cameraserver/Android.mk
@@ -30,8 +30,7 @@
 	android.hardware.camera.common@1.0 \
 	android.hardware.camera.provider@2.4 \
 	android.hardware.camera.device@1.0 \
-	android.hardware.camera.device@3.2 \
-	android.hidl.manager@1.0
+	android.hardware.camera.device@3.2
 
 LOCAL_MODULE:= cameraserver
 LOCAL_32_BIT_ONLY := true
diff --git a/camera/ndk/Android.bp b/camera/ndk/Android.bp
index ade0d72..97cf6bf 100644
--- a/camera/ndk/Android.bp
+++ b/camera/ndk/Android.bp
@@ -22,3 +22,11 @@
     first_version: "24",
     unversioned_until: "current",
 }
+
+ndk_headers {
+    name: "libcamera2ndk_headers",
+    from: "include/camera",
+    to: "camera",
+    srcs: ["include/camera/**/*.h"],
+    license: "NOTICE",
+}
diff --git a/camera/ndk/Android.mk b/camera/ndk/Android.mk
index 591dfc2..f5ff69d 100644
--- a/camera/ndk/Android.mk
+++ b/camera/ndk/Android.mk
@@ -33,9 +33,8 @@
 
 LOCAL_MODULE:= libcamera2ndk
 
-LOCAL_C_INCLUDES := \
-    frameworks/av/include/camera/ndk \
-    frameworks/av/include/ndk
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
 
 LOCAL_CFLAGS += -fvisibility=hidden -D EXPORT='__attribute__ ((visibility ("default")))'
 LOCAL_CFLAGS += -Wall -Wextra -Werror
@@ -49,7 +48,8 @@
     libcamera_client \
     libstagefright_foundation \
     libcutils \
-    libcamera_metadata
+    libcamera_metadata \
+    libmediandk
 
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/camera/ndk/NOTICE b/camera/ndk/NOTICE
new file mode 100644
index 0000000..152be20
--- /dev/null
+++ b/camera/ndk/NOTICE
@@ -0,0 +1,324 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Android-specific code.                        ==
+   =========================================================================
+
+Android Code
+Copyright 2005-2008 The Android Open Source Project
+
+This product includes software developed as part of
+The Android Open Source Project (http://source.android.com).
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for Apache Commons code.                              ==
+   =========================================================================
+
+Apache Commons
+Copyright 1999-2006 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for Jakarta Commons Logging.                          ==
+   =========================================================================
+
+Jakarta Commons Logging (JCL)
+Copyright 2005,2006 The Apache Software Foundation.
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Nuance code.                                  ==
+   =========================================================================
+
+These files are Copyright 2007 Nuance Communications, but released under
+the Apache2 License.
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Media Codecs code.                            ==
+   =========================================================================
+
+Media Codecs
+These files are Copyright 1998 - 2009 PacketVideo, but released under
+the Apache2 License.
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the TagSoup code.                                 ==
+   =========================================================================
+
+This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+
+TagSoup is licensed under the Apache License,
+Version 2.0.  You may obtain a copy of this license at
+http://www.apache.org/licenses/LICENSE-2.0 .  You may also have
+additional legal rights not granted by this license.
+
+TagSoup is distributed in the hope that it will be useful, but
+unless required by applicable law or agreed to in writing, TagSoup
+is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+OF ANY KIND, either express or implied; not even the implied warranty
+of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for Additional Codecs code.                           ==
+   =========================================================================
+
+Additional Codecs
+These files are Copyright 2003-2010 VisualOn, but released under
+the Apache2 License.
+
+  =========================================================================
+  ==  NOTICE file corresponding to the section 4 d of                    ==
+  ==  the Apache License, Version 2.0,                                   ==
+  ==  in this case for the Audio Effects code.                           ==
+  =========================================================================
+
+Audio Effects
+These files are Copyright (C) 2004-2010 NXP Software and
+Copyright (C) 2010 The Android Open Source Project, but released under
+the Apache2 License.
+
+
+                               Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+
+
+UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE
+
+Unicode Data Files include all data files under the directories
+http://www.unicode.org/Public/, http://www.unicode.org/reports/,
+and http://www.unicode.org/cldr/data/ . Unicode Software includes any
+source code published in the Unicode Standard or under the directories
+http://www.unicode.org/Public/, http://www.unicode.org/reports/, and
+http://www.unicode.org/cldr/data/.
+
+NOTICE TO USER: Carefully read the following legal agreement. BY
+DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S DATA
+FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"), YOU UNEQUIVOCALLY
+ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE TERMS AND CONDITIONS OF
+THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY,
+DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
+
+COPYRIGHT AND PERMISSION NOTICE
+
+Copyright © 1991-2008 Unicode, Inc. All rights reserved. Distributed
+under the Terms of Use in http://www.unicode.org/copyright.html.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Unicode data files and any associated documentation (the
+"Data Files") or Unicode software and any associated documentation (the
+"Software") to deal in the Data Files or Software without restriction,
+including without limitation the rights to use, copy, modify, merge,
+publish, distribute, and/or sell copies of the Data Files or Software,
+and to permit persons to whom the Data Files or Software are furnished to
+do so, provided that (a) the above copyright notice(s) and this permission
+notice appear with all copies of the Data Files or Software, (b) both the
+above copyright notice(s) and this permission notice appear in associated
+documentation, and (c) there is clear notice in each modified Data File
+or in the Software as well as in the documentation associated with the
+Data File(s) or Software that the data or software has been modified.
+
+THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
+INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
+OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+OR PERFORMANCE OF THE DATA FILES OR SOFTWARE.
+
+Except as contained in this notice, the name of a copyright holder
+shall not be used in advertising or otherwise to promote the sale, use
+or other dealings in these Data Files or Software without prior written
+authorization of the copyright holder.
diff --git a/camera/ndk/NdkCameraCaptureSession.cpp b/camera/ndk/NdkCameraCaptureSession.cpp
index d6eff24..2a6b182 100644
--- a/camera/ndk/NdkCameraCaptureSession.cpp
+++ b/camera/ndk/NdkCameraCaptureSession.cpp
@@ -23,9 +23,9 @@
 #include <utils/StrongPointer.h>
 #include <utils/Trace.h>
 
-#include "NdkCameraDevice.h"
-#include <NdkCaptureRequest.h>
-#include <NdkCameraCaptureSession.h>
+#include <camera/NdkCameraDevice.h>
+#include <camera/NdkCaptureRequest.h>
+#include <camera/NdkCameraCaptureSession.h>
 #include "impl/ACameraCaptureSession.h"
 
 using namespace android;
diff --git a/camera/ndk/NdkCameraDevice.cpp b/camera/ndk/NdkCameraDevice.cpp
index 281d3e7..9f6d1f7 100644
--- a/camera/ndk/NdkCameraDevice.cpp
+++ b/camera/ndk/NdkCameraDevice.cpp
@@ -21,7 +21,7 @@
 #include <utils/Log.h>
 #include <utils/Trace.h>
 
-#include <NdkCameraDevice.h>
+#include <camera/NdkCameraDevice.h>
 #include "impl/ACameraCaptureSession.h"
 
 using namespace android;
diff --git a/camera/ndk/NdkCameraManager.cpp b/camera/ndk/NdkCameraManager.cpp
index ff15263..60b4763 100644
--- a/camera/ndk/NdkCameraManager.cpp
+++ b/camera/ndk/NdkCameraManager.cpp
@@ -21,7 +21,7 @@
 #include <utils/Log.h>
 #include <utils/Trace.h>
 
-#include <NdkCameraManager.h>
+#include <camera/NdkCameraManager.h>
 #include "impl/ACameraManager.h"
 
 using namespace android;
diff --git a/camera/ndk/NdkCameraMetadata.cpp b/camera/ndk/NdkCameraMetadata.cpp
index 85fe75b..65de81f 100644
--- a/camera/ndk/NdkCameraMetadata.cpp
+++ b/camera/ndk/NdkCameraMetadata.cpp
@@ -21,7 +21,7 @@
 #include <utils/Log.h>
 #include <utils/Trace.h>
 
-#include "NdkCameraMetadata.h"
+#include <camera/NdkCameraMetadata.h>
 #include "impl/ACameraMetadata.h"
 
 using namespace android;
diff --git a/camera/ndk/NdkCaptureRequest.cpp b/camera/ndk/NdkCaptureRequest.cpp
index 7c37955..5b4c180 100644
--- a/camera/ndk/NdkCaptureRequest.cpp
+++ b/camera/ndk/NdkCaptureRequest.cpp
@@ -21,7 +21,7 @@
 #include <utils/Log.h>
 #include <utils/Trace.h>
 
-#include "NdkCaptureRequest.h"
+#include <camera/NdkCaptureRequest.h>
 #include "impl/ACameraMetadata.h"
 #include "impl/ACaptureRequest.h"
 
diff --git a/camera/ndk/impl/ACameraCaptureSession.h b/camera/ndk/impl/ACameraCaptureSession.h
index f56219c..339c665 100644
--- a/camera/ndk/impl/ACameraCaptureSession.h
+++ b/camera/ndk/impl/ACameraCaptureSession.h
@@ -18,7 +18,7 @@
 
 #include <set>
 #include <hardware/camera3.h>
-#include <NdkCameraDevice.h>
+#include <camera/NdkCameraDevice.h>
 #include "ACameraDevice.h"
 
 using namespace android;
diff --git a/camera/ndk/impl/ACameraDevice.h b/camera/ndk/impl/ACameraDevice.h
index eb8028b..c566cd2 100644
--- a/camera/ndk/impl/ACameraDevice.h
+++ b/camera/ndk/impl/ACameraDevice.h
@@ -36,7 +36,7 @@
 #include <camera/camera2/OutputConfiguration.h>
 #include <camera/camera2/CaptureRequest.h>
 
-#include <NdkCameraDevice.h>
+#include <camera/NdkCameraDevice.h>
 #include "ACameraMetadata.h"
 
 namespace android {
diff --git a/camera/ndk/impl/ACameraManager.h b/camera/ndk/impl/ACameraManager.h
index 97e4fd9..4a172f3 100644
--- a/camera/ndk/impl/ACameraManager.h
+++ b/camera/ndk/impl/ACameraManager.h
@@ -17,7 +17,7 @@
 #ifndef _ACAMERA_MANAGER_H
 #define _ACAMERA_MANAGER_H
 
-#include "NdkCameraManager.h"
+#include <camera/NdkCameraManager.h>
 
 #include <android/hardware/ICameraService.h>
 #include <android/hardware/BnCameraServiceListener.h>
diff --git a/camera/ndk/impl/ACameraMetadata.cpp b/camera/ndk/impl/ACameraMetadata.cpp
index c0da592..7b33c32 100644
--- a/camera/ndk/impl/ACameraMetadata.cpp
+++ b/camera/ndk/impl/ACameraMetadata.cpp
@@ -20,7 +20,7 @@
 #include "ACameraMetadata.h"
 #include <utils/Vector.h>
 #include <system/graphics.h>
-#include "NdkImage.h"
+#include <media/NdkImage.h>
 
 using namespace android;
 
diff --git a/camera/ndk/impl/ACameraMetadata.h b/camera/ndk/impl/ACameraMetadata.h
index 8d050c4..143efc7 100644
--- a/camera/ndk/impl/ACameraMetadata.h
+++ b/camera/ndk/impl/ACameraMetadata.h
@@ -24,7 +24,7 @@
 #include <utils/Vector.h>
 #include <camera/CameraMetadata.h>
 
-#include "NdkCameraMetadata.h"
+#include <camera/NdkCameraMetadata.h>
 
 using namespace android;
 
diff --git a/camera/ndk/impl/ACaptureRequest.h b/camera/ndk/impl/ACaptureRequest.h
index 3ef6a84..e5b453e 100644
--- a/camera/ndk/impl/ACaptureRequest.h
+++ b/camera/ndk/impl/ACaptureRequest.h
@@ -16,7 +16,7 @@
 #ifndef _ACAPTURE_REQUEST_H
 #define _ACAPTURE_REQUEST_H
 
-#include "NdkCaptureRequest.h"
+#include <camera/NdkCaptureRequest.h>
 #include <set>
 
 using namespace android;
diff --git a/camera/include/camera/ndk/NdkCameraCaptureSession.h b/camera/ndk/include/camera/NdkCameraCaptureSession.h
similarity index 100%
rename from camera/include/camera/ndk/NdkCameraCaptureSession.h
rename to camera/ndk/include/camera/NdkCameraCaptureSession.h
diff --git a/camera/include/camera/ndk/NdkCameraDevice.h b/camera/ndk/include/camera/NdkCameraDevice.h
similarity index 100%
rename from camera/include/camera/ndk/NdkCameraDevice.h
rename to camera/ndk/include/camera/NdkCameraDevice.h
diff --git a/camera/include/camera/ndk/NdkCameraError.h b/camera/ndk/include/camera/NdkCameraError.h
similarity index 100%
rename from camera/include/camera/ndk/NdkCameraError.h
rename to camera/ndk/include/camera/NdkCameraError.h
diff --git a/camera/include/camera/ndk/NdkCameraManager.h b/camera/ndk/include/camera/NdkCameraManager.h
similarity index 100%
rename from camera/include/camera/ndk/NdkCameraManager.h
rename to camera/ndk/include/camera/NdkCameraManager.h
diff --git a/camera/include/camera/ndk/NdkCameraMetadata.h b/camera/ndk/include/camera/NdkCameraMetadata.h
similarity index 100%
rename from camera/include/camera/ndk/NdkCameraMetadata.h
rename to camera/ndk/include/camera/NdkCameraMetadata.h
diff --git a/camera/include/camera/ndk/NdkCameraMetadataTags.h b/camera/ndk/include/camera/NdkCameraMetadataTags.h
similarity index 100%
rename from camera/include/camera/ndk/NdkCameraMetadataTags.h
rename to camera/ndk/include/camera/NdkCameraMetadataTags.h
diff --git a/camera/include/camera/ndk/NdkCaptureRequest.h b/camera/ndk/include/camera/NdkCaptureRequest.h
similarity index 100%
rename from camera/include/camera/ndk/NdkCaptureRequest.h
rename to camera/ndk/include/camera/NdkCaptureRequest.h
diff --git a/cmds/stagefright/Android.mk b/cmds/stagefright/Android.mk
index ff5e5d3..0ea98a4 100644
--- a/cmds/stagefright/Android.mk
+++ b/cmds/stagefright/Android.mk
@@ -185,6 +185,9 @@
 
 LOCAL_MODULE:= mediafilter
 
+LOCAL_SANITIZE := cfi
+LOCAL_SANITIZE_DIAG := cfi
+
 include $(BUILD_EXECUTABLE)
 
 ################################################################################
diff --git a/cmds/stagefright/stagefright.cpp b/cmds/stagefright/stagefright.cpp
index dfd5df7..d7c2e87 100644
--- a/cmds/stagefright/stagefright.cpp
+++ b/cmds/stagefright/stagefright.cpp
@@ -162,7 +162,7 @@
                        1,
                        mbuf->range_length(),
                        out),
-                (ssize_t)mbuf->range_length());
+                mbuf->range_length());
 
         mbuf->release();
         mbuf = NULL;
diff --git a/drm/common/Android.bp b/drm/common/Android.bp
new file mode 100644
index 0000000..0098c89
--- /dev/null
+++ b/drm/common/Android.bp
@@ -0,0 +1,39 @@
+//
+// Copyright (C) 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_static {
+    name: "libdrmframeworkcommon",
+
+    srcs: [
+        "DrmConstraints.cpp",
+        "DrmMetadata.cpp",
+        "DrmConvertedStatus.cpp",
+        "DrmEngineBase.cpp",
+        "DrmInfo.cpp",
+        "DrmInfoRequest.cpp",
+        "DrmInfoStatus.cpp",
+        "DrmRights.cpp",
+        "DrmSupportInfo.cpp",
+        "IDrmManagerService.cpp",
+        "IDrmServiceListener.cpp",
+        "DrmInfoEvent.cpp",
+        "ReadWriteUtils.cpp",
+    ],
+
+    static_libs: ["libbinder"],
+
+    export_include_dirs: ["include"],
+}
diff --git a/drm/common/Android.mk b/drm/common/Android.mk
deleted file mode 100644
index ca3d2cd..0000000
--- a/drm/common/Android.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    DrmConstraints.cpp \
-    DrmMetadata.cpp \
-    DrmConvertedStatus.cpp \
-    DrmEngineBase.cpp \
-    DrmInfo.cpp \
-    DrmInfoRequest.cpp \
-    DrmInfoStatus.cpp \
-    DrmRights.cpp \
-    DrmSupportInfo.cpp \
-    IDrmManagerService.cpp \
-    IDrmServiceListener.cpp \
-    DrmInfoEvent.cpp \
-    ReadWriteUtils.cpp
-
-LOCAL_STATIC_LIBRARIES := libbinder
-
-LOCAL_C_INCLUDES := \
-    $(TOP)/frameworks/av/include \
-    $(TOP)/frameworks/av/drm/libdrmframework/include \
-    $(TOP)/frameworks/av/drm/libdrmframework/plugins/common/include
-
-LOCAL_MODULE:= libdrmframeworkcommon
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/common/include/DrmEngineBase.h
similarity index 100%
rename from drm/libdrmframework/plugins/common/include/DrmEngineBase.h
rename to drm/common/include/DrmEngineBase.h
diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/common/include/IDrmEngine.h
similarity index 100%
rename from drm/libdrmframework/plugins/common/include/IDrmEngine.h
rename to drm/common/include/IDrmEngine.h
diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/common/include/IDrmManagerService.h
similarity index 100%
rename from drm/libdrmframework/include/IDrmManagerService.h
rename to drm/common/include/IDrmManagerService.h
diff --git a/drm/libdrmframework/include/IDrmServiceListener.h b/drm/common/include/IDrmServiceListener.h
similarity index 100%
rename from drm/libdrmframework/include/IDrmServiceListener.h
rename to drm/common/include/IDrmServiceListener.h
diff --git a/drm/libdrmframework/include/ReadWriteUtils.h b/drm/common/include/ReadWriteUtils.h
similarity index 100%
rename from drm/libdrmframework/include/ReadWriteUtils.h
rename to drm/common/include/ReadWriteUtils.h
diff --git a/drm/drmserver/Android.bp b/drm/drmserver/Android.bp
new file mode 100644
index 0000000..c25a0a1
--- /dev/null
+++ b/drm/drmserver/Android.bp
@@ -0,0 +1,46 @@
+//
+// Copyright (C) 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_binary {
+    name: "drmserver",
+
+    srcs: [
+        "main_drmserver.cpp",
+        "DrmManager.cpp",
+        "DrmManagerService.cpp",
+    ],
+
+    shared_libs: [
+        "libmedia",
+        "libutils",
+        "liblog",
+        "libbinder",
+        "libdl",
+        "libselinux",
+    ],
+
+    static_libs: ["libdrmframeworkcommon"],
+
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+
+    compile_multilib: "32",
+
+    init_rc: ["drmserver.rc"],
+}
diff --git a/drm/drmserver/Android.mk b/drm/drmserver/Android.mk
deleted file mode 100644
index 3b8bb04..0000000
--- a/drm/drmserver/Android.mk
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    main_drmserver.cpp \
-    DrmManager.cpp \
-    DrmManagerService.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-    libmedia \
-    libutils \
-    liblog \
-    libbinder \
-    libdl \
-    libselinux
-
-LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon
-
-LOCAL_C_INCLUDES := \
-    $(TOP)/frameworks/av/include \
-    $(TOP)/frameworks/av/drm/libdrmframework/include \
-    $(TOP)/frameworks/av/drm/libdrmframework/plugins/common/include
-
-LOCAL_CFLAGS += -Wall -Wextra -Werror
-
-LOCAL_MODULE:= drmserver
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_32_BIT_ONLY := true
-
-LOCAL_INIT_RC := drmserver.rc
-
-include $(BUILD_EXECUTABLE)
diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/drmserver/DrmManager.h
similarity index 100%
rename from drm/libdrmframework/include/DrmManager.h
rename to drm/drmserver/DrmManager.h
diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/drmserver/DrmManagerService.h
similarity index 100%
rename from drm/libdrmframework/include/DrmManagerService.h
rename to drm/drmserver/DrmManagerService.h
diff --git a/drm/libdrmframework/include/PlugInManager.h b/drm/drmserver/PlugInManager.h
similarity index 100%
rename from drm/libdrmframework/include/PlugInManager.h
rename to drm/drmserver/PlugInManager.h
diff --git a/drm/libdrmframework/Android.bp b/drm/libdrmframework/Android.bp
new file mode 100644
index 0000000..43ba72b
--- /dev/null
+++ b/drm/libdrmframework/Android.bp
@@ -0,0 +1,42 @@
+//
+// Copyright (C) 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_shared {
+    name: "libdrmframework",
+
+    srcs: [
+        "DrmManagerClientImpl.cpp",
+        "DrmManagerClient.cpp",
+        "NoOpDrmManagerClientImpl.cpp",
+    ],
+
+    shared_libs: [
+        "libutils",
+        "libcutils",
+        "liblog",
+        "libbinder",
+        "libdl",
+    ],
+
+    static_libs: ["libdrmframeworkcommon"],
+
+    export_include_dirs: ["include"],
+    export_static_lib_headers: ["libdrmframeworkcommon"],
+
+    cflags: ["-Werror"],
+}
+
+subdirs = ["plugins/*"]
diff --git a/drm/libdrmframework/Android.mk b/drm/libdrmframework/Android.mk
deleted file mode 100644
index cafcb94..0000000
--- a/drm/libdrmframework/Android.mk
+++ /dev/null
@@ -1,48 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    DrmManagerClientImpl.cpp \
-    DrmManagerClient.cpp \
-    NoOpDrmManagerClientImpl.cpp
-
-LOCAL_MODULE:= libdrmframework
-
-LOCAL_SHARED_LIBRARIES := \
-    libutils \
-    libcutils \
-    liblog \
-    libbinder \
-    libdl
-
-LOCAL_STATIC_LIBRARIES := \
-    libdrmframeworkcommon
-
-LOCAL_C_INCLUDES += \
-    $(TOP)/frameworks/av/drm/libdrmframework/include \
-    $(TOP)/frameworks/av/include
-
-LOCAL_CFLAGS += -Werror
-
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/drm/libdrmframework/plugins/Android.mk b/drm/libdrmframework/plugins/Android.mk
deleted file mode 100644
index 9ee7961..0000000
--- a/drm/libdrmframework/plugins/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-include $(call all-subdir-makefiles)
diff --git a/drm/libdrmframework/plugins/common/Android.bp b/drm/libdrmframework/plugins/common/Android.bp
new file mode 100644
index 0000000..213e57f
--- /dev/null
+++ b/drm/libdrmframework/plugins/common/Android.bp
@@ -0,0 +1 @@
+subdirs = ["util"]
diff --git a/drm/libdrmframework/plugins/common/Android.mk b/drm/libdrmframework/plugins/common/Android.mk
deleted file mode 100644
index 9ee7961..0000000
--- a/drm/libdrmframework/plugins/common/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-include $(call all-subdir-makefiles)
diff --git a/drm/libdrmframework/plugins/common/util/Android.bp b/drm/libdrmframework/plugins/common/util/Android.bp
new file mode 100644
index 0000000..0c0b6f2
--- /dev/null
+++ b/drm/libdrmframework/plugins/common/util/Android.bp
@@ -0,0 +1,23 @@
+//
+// Copyright (C) 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_static {
+    name: "libdrmutility",
+
+    srcs: ["src/MimeTypeUtil.cpp"],
+
+    export_include_dirs: ["include"],
+}
diff --git a/drm/libdrmframework/plugins/common/util/Android.mk b/drm/libdrmframework/plugins/common/util/Android.mk
deleted file mode 100644
index 2a7b01f..0000000
--- a/drm/libdrmframework/plugins/common/util/Android.mk
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    src/MimeTypeUtil.cpp
-
-LOCAL_MODULE := libdrmutility
-
-base := frameworks/av
-
-LOCAL_C_INCLUDES += \
-    $(base)/include \
-    $(base)/include/drm \
-    $(base)/include/drm/plugins \
-    $(LOCAL_PATH)/include
-
-
-ifneq ($(TARGET_BUILD_VARIANT),user)
-LOCAL_C_INCLUDES += \
-    $(LOCAL_PATH)/tools
-
-endif
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/drm/libdrmframework/plugins/forward-lock/Android.bp b/drm/libdrmframework/plugins/forward-lock/Android.bp
new file mode 100644
index 0000000..f884c14
--- /dev/null
+++ b/drm/libdrmframework/plugins/forward-lock/Android.bp
@@ -0,0 +1,4 @@
+subdirs = [
+    "FwdLockEngine",
+    "internal-format",
+]
diff --git a/drm/libdrmframework/plugins/forward-lock/Android.mk b/drm/libdrmframework/plugins/forward-lock/Android.mk
deleted file mode 100644
index 9ee7961..0000000
--- a/drm/libdrmframework/plugins/forward-lock/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-include $(call all-subdir-makefiles)
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.bp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.bp
new file mode 100644
index 0000000..3f0f5f7
--- /dev/null
+++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.bp
@@ -0,0 +1,50 @@
+//
+// Copyright (C) 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//2
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_shared {
+    name: "libfwdlockengine",
+
+    cflags: [
+        "-DUSE_64BIT_DRM_API",
+        // The flag below turns on local debug printouts
+        //"-DDRM_OMA_FL_ENGINE_DEBUG",
+    ],
+
+    srcs: ["src/FwdLockEngine.cpp"],
+
+    shared_libs: [
+        "libicui18n",
+        "libicuuc",
+        "libutils",
+        "liblog",
+        "libdl",
+        "libcrypto",
+        "libssl",
+        "libdrmframework",
+    ],
+
+    static_libs: [
+        "libdrmutility",
+        "libdrmframeworkcommon",
+        "libfwdlock-common",
+        "libfwdlock-converter",
+        "libfwdlock-decoder",
+    ],
+
+    local_include_dirs: ["include"],
+
+    relative_install_path: "drm",
+}
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk
deleted file mode 100644
index 933464f..0000000
--- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk
+++ /dev/null
@@ -1,67 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-# The flag below turns on local debug printouts
-#LOCAL_CFLAGS += -DDRM_OMA_FL_ENGINE_DEBUG
-
-base := frameworks/av
-
-# Determine whether the DRM framework uses 64-bit data types for file offsets and do the same.
-ifneq ($(shell grep -c 'off64_t offset' $(base)/drm/libdrmframework/plugins/common/include/IDrmEngine.h), 0)
-LOCAL_CFLAGS += -DUSE_64BIT_DRM_API
-endif
-
-LOCAL_SRC_FILES:= \
-    src/FwdLockEngine.cpp
-
-LOCAL_MODULE := libfwdlockengine
-
-LOCAL_SHARED_LIBRARIES := \
-    libicui18n \
-    libicuuc \
-    libutils \
-    liblog \
-    libdl \
-    libcrypto \
-    libssl \
-    libdrmframework
-
-LOCAL_STATIC_LIBRARIES := \
-    libdrmutility \
-    libdrmframeworkcommon \
-    libfwdlock-common \
-    libfwdlock-converter \
-    libfwdlock-decoder
-
-
-
-LOCAL_C_INCLUDES += \
-    $(base)/include/drm \
-    $(base)/drm/libdrmframework/plugins/common/include \
-    $(base)/drm/libdrmframework/plugins/common/util/include \
-    $(base)/drm/libdrmframework/plugins/forward-lock/internal-format/common \
-    $(base)/drm/libdrmframework/plugins/forward-lock/internal-format/converter \
-    $(base)/drm/libdrmframework/plugins/forward-lock/internal-format/decoder \
-    $(LOCAL_PATH)/include
-
-LOCAL_MODULE_RELATIVE_PATH := drm
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h
index d222703..a571b3a 100644
--- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h
+++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h
@@ -18,14 +18,14 @@
 #define __FWDLOCKENGINE_H__
 
 #include <DrmEngineBase.h>
-#include <DrmConstraints.h>
-#include <DrmRights.h>
-#include <DrmInfo.h>
-#include <DrmInfoStatus.h>
-#include <DrmConvertedStatus.h>
-#include <DrmInfoRequest.h>
-#include <DrmSupportInfo.h>
-#include <DrmInfoEvent.h>
+#include <drm/DrmConstraints.h>
+#include <drm/DrmRights.h>
+#include <drm/DrmInfo.h>
+#include <drm/DrmInfoStatus.h>
+#include <drm/DrmConvertedStatus.h>
+#include <drm/DrmInfoRequest.h>
+#include <drm/DrmSupportInfo.h>
+#include <drm/DrmInfoEvent.h>
 
 #include "SessionMap.h"
 #include "FwdLockConv.h"
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
index a495616..830def9 100644
--- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
+++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
@@ -20,17 +20,17 @@
 #include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
-#include "drm_framework_common.h"
+#include <drm/drm_framework_common.h>
 #include <fcntl.h>
 #include <limits.h>
-#include <DrmRights.h>
-#include <DrmConstraints.h>
-#include <DrmMetadata.h>
-#include <DrmInfo.h>
-#include <DrmInfoStatus.h>
-#include <DrmInfoRequest.h>
-#include <DrmSupportInfo.h>
-#include <DrmConvertedStatus.h>
+#include <drm/DrmRights.h>
+#include <drm/DrmConstraints.h>
+#include <drm/DrmMetadata.h>
+#include <drm/DrmInfo.h>
+#include <drm/DrmInfoStatus.h>
+#include <drm/DrmInfoRequest.h>
+#include <drm/DrmSupportInfo.h>
+#include <drm/DrmConvertedStatus.h>
 #include <utils/String8.h>
 #include "FwdLockConv.h"
 #include "FwdLockFile.h"
diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/Android.bp b/drm/libdrmframework/plugins/forward-lock/internal-format/Android.bp
new file mode 100644
index 0000000..9f58e26
--- /dev/null
+++ b/drm/libdrmframework/plugins/forward-lock/internal-format/Android.bp
@@ -0,0 +1,5 @@
+subdirs = [
+    "common",
+    "converter",
+    "decoder",
+]
diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/Android.mk b/drm/libdrmframework/plugins/forward-lock/internal-format/Android.mk
deleted file mode 100644
index 9ee7961..0000000
--- a/drm/libdrmframework/plugins/forward-lock/internal-format/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-include $(call all-subdir-makefiles)
diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.bp b/drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.bp
new file mode 100644
index 0000000..698f278
--- /dev/null
+++ b/drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.bp
@@ -0,0 +1,25 @@
+//
+// Copyright (C) 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_static {
+    name: "libfwdlock-common",
+
+    srcs: ["FwdLockGlue.c"],
+
+    shared_libs: ["libcrypto"],
+
+    export_include_dirs: ["."],
+}
diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.mk b/drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.mk
deleted file mode 100644
index 3b4c8b4..0000000
--- a/drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    FwdLockGlue.c
-
-LOCAL_SHARED_LIBRARIES := libcrypto
-
-LOCAL_MODULE := libfwdlock-common
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.bp b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.bp
new file mode 100644
index 0000000..33f2fe0
--- /dev/null
+++ b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.bp
@@ -0,0 +1,26 @@
+//
+// Copyright (C) 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_static {
+    name: "libfwdlock-converter",
+
+    srcs: ["FwdLockConv.c"],
+
+    shared_libs: ["libcrypto"],
+    static_libs: ["libfwdlock-common"],
+
+    export_include_dirs: ["."],
+}
diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.mk b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.mk
deleted file mode 100644
index 2f51f0c..0000000
--- a/drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    FwdLockConv.c
-
-LOCAL_C_INCLUDES := \
-    frameworks/av/drm/libdrmframework/plugins/forward-lock/internal-format/common
-
-LOCAL_SHARED_LIBRARIES := libcrypto
-
-LOCAL_MODULE := libfwdlock-converter
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.bp b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.bp
new file mode 100644
index 0000000..b6d7a06
--- /dev/null
+++ b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.bp
@@ -0,0 +1,26 @@
+//
+// Copyright (C) 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_static {
+    name: "libfwdlock-decoder",
+
+    srcs: ["FwdLockFile.c"],
+
+    shared_libs: ["libcrypto"],
+    static_libs: ["libfwdlock-common"],
+
+    export_include_dirs: ["."],
+}
diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.mk b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.mk
deleted file mode 100644
index 3399ae5..0000000
--- a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    FwdLockFile.c
-
-LOCAL_C_INCLUDES := \
-    frameworks/av/drm/libdrmframework/plugins/forward-lock/internal-format/common
-
-LOCAL_SHARED_LIBRARIES := libcrypto
-
-LOCAL_MODULE := libfwdlock-decoder
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/drm/libdrmframework/plugins/passthru/Android.bp b/drm/libdrmframework/plugins/passthru/Android.bp
new file mode 100644
index 0000000..1dcf89c
--- /dev/null
+++ b/drm/libdrmframework/plugins/passthru/Android.bp
@@ -0,0 +1,36 @@
+//
+// Copyright (C) 2010 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_shared {
+    name: "libdrmpassthruplugin",
+
+    srcs: ["src/DrmPassthruPlugIn.cpp"],
+
+    static_libs: ["libdrmframeworkcommon"],
+
+    shared_libs: [
+        "libutils",
+        "liblog",
+        "libdl",
+    ],
+
+    local_include_dirs: ["include"],
+
+    cflags: [
+        // Set the following flag to enable the decryption passthru flow
+        //"-DENABLE_PASSTHRU_DECRYPTION",
+    ],
+}
diff --git a/drm/libdrmframework/plugins/passthru/Android.mk b/drm/libdrmframework/plugins/passthru/Android.mk
deleted file mode 100644
index cb3a2e2..0000000
--- a/drm/libdrmframework/plugins/passthru/Android.mk
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    src/DrmPassthruPlugIn.cpp
-
-LOCAL_MODULE := libdrmpassthruplugin
-
-LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon
-
-LOCAL_SHARED_LIBRARIES := \
-    libutils \
-    liblog \
-    libdl
-
-
-LOCAL_C_INCLUDES += \
-    $(TOP)/frameworks/av/drm/libdrmframework/include \
-    $(TOP)/frameworks/av/drm/libdrmframework/plugins/passthru/include \
-    $(TOP)/frameworks/av/drm/libdrmframework/plugins/common/include \
-    $(TOP)/frameworks/av/include
-
-# Set the following flag to enable the decryption passthru flow
-#LOCAL_CFLAGS += -DENABLE_PASSTHRU_DECRYPTION
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
index 7f5b0ec..d7f2d28 100644
--- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
+++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
@@ -245,6 +245,8 @@
     decryptHandle->status = DRM_NO_ERROR;
     decryptHandle->decryptInfo = NULL;
     return DRM_NO_ERROR;
+#else
+    (void)(decryptHandle); // unused
 #endif
 
     return DRM_ERROR_CANNOT_HANDLE;
diff --git a/drm/libmediadrm/Android.bp b/drm/libmediadrm/Android.bp
new file mode 100644
index 0000000..66f5fc2
--- /dev/null
+++ b/drm/libmediadrm/Android.bp
@@ -0,0 +1,51 @@
+//
+// libmediadrm
+//
+
+cc_library_shared {
+    name: "libmediadrm",
+
+    aidl: {
+        local_include_dirs: ["aidl"],
+        export_aidl_headers: true,
+    },
+
+    srcs: [
+        "aidl/android/media/ICas.aidl",
+        "aidl/android/media/ICasListener.aidl",
+        "aidl/android/media/IDescrambler.aidl",
+        "aidl/android/media/IMediaCasService.aidl",
+
+        "CasImpl.cpp",
+        "DescramblerImpl.cpp",
+        "DrmPluginPath.cpp",
+        "DrmSessionManager.cpp",
+        "ICrypto.cpp",
+        "IDrm.cpp",
+        "IDrmClient.cpp",
+        "IMediaDrmService.cpp",
+        "MediaCasDefs.cpp",
+        "SharedLibrary.cpp",
+        "DrmHal.cpp",
+        "CryptoHal.cpp",
+    ],
+
+    shared_libs: [
+        "libbinder",
+        "libcutils",
+        "libdl",
+        "liblog",
+        "libmediautils",
+        "libstagefright_foundation",
+        "libutils",
+        "android.hardware.drm@1.0",
+        "libhidlbase",
+        "libhidlmemory",
+        "libhidltransport",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+}
diff --git a/drm/libmediadrm/Android.mk b/drm/libmediadrm/Android.mk
deleted file mode 100644
index 5b56501..0000000
--- a/drm/libmediadrm/Android.mk
+++ /dev/null
@@ -1,62 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-#
-# libmediadrm
-#
-
-include $(CLEAR_VARS)
-
-LOCAL_AIDL_INCLUDES := \
-    frameworks/av/drm/libmediadrm/aidl
-
-LOCAL_SRC_FILES := \
-    aidl/android/media/ICas.aidl \
-    aidl/android/media/ICasListener.aidl \
-    aidl/android/media/IDescrambler.aidl \
-    aidl/android/media/IMediaCasService.aidl \
-
-LOCAL_SRC_FILES += \
-    CasImpl.cpp \
-    DescramblerImpl.cpp \
-    DrmPluginPath.cpp \
-    DrmSessionManager.cpp \
-    ICrypto.cpp \
-    IDrm.cpp \
-    IDrmClient.cpp \
-    IMediaDrmService.cpp \
-    MediaCasDefs.cpp \
-    SharedLibrary.cpp
-ifneq ($(DISABLE_TREBLE_DRM), true)
-LOCAL_SRC_FILES += \
-    DrmHal.cpp \
-    CryptoHal.cpp
-else
-LOCAL_SRC_FILES += \
-    Drm.cpp \
-    Crypto.cpp
-endif
-
-LOCAL_SHARED_LIBRARIES := \
-    libbinder \
-    libcutils \
-    libdl \
-    liblog \
-    libmediautils \
-    libstagefright_foundation \
-    libutils
-ifneq ($(DISABLE_TREBLE_DRM), true)
-LOCAL_SHARED_LIBRARIES += \
-    android.hidl.base@1.0 \
-    android.hardware.drm@1.0 \
-    libhidlbase \
-    libhidlmemory \
-    libhidltransport
-endif
-
-LOCAL_CFLAGS += -Werror -Wno-error=deprecated-declarations -Wall
-
-LOCAL_MODULE:= libmediadrm
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/drm/libmediadrm/Crypto.cpp b/drm/libmediadrm/Crypto.cpp
deleted file mode 100644
index a5d7346..0000000
--- a/drm/libmediadrm/Crypto.cpp
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "Crypto"
-#include <utils/Log.h>
-#include <dirent.h>
-#include <dlfcn.h>
-
-#include <binder/IMemory.h>
-#include <media/Crypto.h>
-#include <media/DrmPluginPath.h>
-#include <media/hardware/CryptoAPI.h>
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/foundation/AString.h>
-#include <media/stagefright/foundation/hexdump.h>
-#include <media/stagefright/MediaErrors.h>
-
-namespace android {
-
-KeyedVector<Vector<uint8_t>, String8> Crypto::mUUIDToLibraryPathMap;
-KeyedVector<String8, wp<SharedLibrary> > Crypto::mLibraryPathToOpenLibraryMap;
-Mutex Crypto::mMapLock;
-
-static bool operator<(const Vector<uint8_t> &lhs, const Vector<uint8_t> &rhs) {
-    if (lhs.size() < rhs.size()) {
-        return true;
-    } else if (lhs.size() > rhs.size()) {
-        return false;
-    }
-
-    return memcmp((void *)lhs.array(), (void *)rhs.array(), rhs.size()) < 0;
-}
-
-Crypto::Crypto()
-    : mInitCheck(NO_INIT),
-      mFactory(NULL),
-      mPlugin(NULL) {
-}
-
-Crypto::~Crypto() {
-    delete mPlugin;
-    mPlugin = NULL;
-    closeFactory();
-}
-
-void Crypto::closeFactory() {
-    delete mFactory;
-    mFactory = NULL;
-    mLibrary.clear();
-}
-
-status_t Crypto::initCheck() const {
-    return mInitCheck;
-}
-
-/*
- * Search the plugins directory for a plugin that supports the scheme
- * specified by uuid
- *
- * If found:
- *    mLibrary holds a strong pointer to the dlopen'd library
- *    mFactory is set to the library's factory method
- *    mInitCheck is set to OK
- *
- * If not found:
- *    mLibrary is cleared and mFactory are set to NULL
- *    mInitCheck is set to an error (!OK)
- */
-void Crypto::findFactoryForScheme(const uint8_t uuid[16]) {
-
-    closeFactory();
-
-    // lock static maps
-    Mutex::Autolock autoLock(mMapLock);
-
-    // first check cache
-    Vector<uint8_t> uuidVector;
-    uuidVector.appendArray(uuid, sizeof(uuid[0]) * 16);
-    ssize_t index = mUUIDToLibraryPathMap.indexOfKey(uuidVector);
-    if (index >= 0) {
-        if (loadLibraryForScheme(mUUIDToLibraryPathMap[index], uuid)) {
-            mInitCheck = OK;
-            return;
-        } else {
-            ALOGE("Failed to load from cached library path!");
-            mInitCheck = ERROR_UNSUPPORTED;
-            return;
-        }
-    }
-
-    // no luck, have to search
-    String8 dirPath(getDrmPluginPath());
-    String8 pluginPath;
-
-    DIR* pDir = opendir(dirPath.string());
-    if (pDir) {
-        struct dirent* pEntry;
-        while ((pEntry = readdir(pDir))) {
-
-            pluginPath = dirPath + "/" + pEntry->d_name;
-
-            if (pluginPath.getPathExtension() == ".so") {
-
-                if (loadLibraryForScheme(pluginPath, uuid)) {
-                    mUUIDToLibraryPathMap.add(uuidVector, pluginPath);
-                    mInitCheck = OK;
-                    closedir(pDir);
-                    return;
-                }
-            }
-        }
-
-        closedir(pDir);
-    }
-
-    // try the legacy libdrmdecrypt.so
-    pluginPath = "libdrmdecrypt.so";
-    if (loadLibraryForScheme(pluginPath, uuid)) {
-        mUUIDToLibraryPathMap.add(uuidVector, pluginPath);
-        mInitCheck = OK;
-        return;
-    }
-
-    mInitCheck = ERROR_UNSUPPORTED;
-}
-
-bool Crypto::loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]) {
-
-    // get strong pointer to open shared library
-    ssize_t index = mLibraryPathToOpenLibraryMap.indexOfKey(path);
-    if (index >= 0) {
-        mLibrary = mLibraryPathToOpenLibraryMap[index].promote();
-    } else {
-        index = mLibraryPathToOpenLibraryMap.add(path, NULL);
-    }
-
-    if (!mLibrary.get()) {
-        mLibrary = new SharedLibrary(path);
-        if (!*mLibrary) {
-            ALOGE("loadLibraryForScheme failed:%s", mLibrary->lastError());
-            return false;
-        }
-
-        mLibraryPathToOpenLibraryMap.replaceValueAt(index, mLibrary);
-    }
-
-    typedef CryptoFactory *(*CreateCryptoFactoryFunc)();
-
-    CreateCryptoFactoryFunc createCryptoFactory =
-        (CreateCryptoFactoryFunc)mLibrary->lookup("createCryptoFactory");
-
-    if (createCryptoFactory == NULL ||
-        (mFactory = createCryptoFactory()) == NULL ||
-        !mFactory->isCryptoSchemeSupported(uuid)) {
-        ALOGE("createCryptoFactory failed:%s", mLibrary->lastError());
-        closeFactory();
-        return false;
-    }
-    return true;
-}
-
-bool Crypto::isCryptoSchemeSupported(const uint8_t uuid[16]) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mFactory && mFactory->isCryptoSchemeSupported(uuid)) {
-        return true;
-    }
-
-    findFactoryForScheme(uuid);
-    return (mInitCheck == OK);
-}
-
-status_t Crypto::createPlugin(
-        const uint8_t uuid[16], const void *data, size_t size) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mPlugin != NULL) {
-        return -EINVAL;
-    }
-
-    if (!mFactory || !mFactory->isCryptoSchemeSupported(uuid)) {
-        findFactoryForScheme(uuid);
-    }
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    return mFactory->createPlugin(uuid, data, size, &mPlugin);
-}
-
-status_t Crypto::destroyPlugin() {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    delete mPlugin;
-    mPlugin = NULL;
-
-    return OK;
-}
-
-bool Crypto::requiresSecureDecoderComponent(const char *mime) const {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->requiresSecureDecoderComponent(mime);
-}
-
-ssize_t Crypto::decrypt(const uint8_t key[16], const uint8_t iv[16],
-        CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
-        const sp<IMemory> &source, size_t offset,
-        const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
-        const ICrypto::DestinationBuffer &destination, AString *errorDetailMsg) {
-
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    const void *srcPtr = static_cast<uint8_t *>(source->pointer()) + offset;
-
-    void *destPtr;
-    bool secure = false;
-    if (destination.mType == kDestinationTypeNativeHandle) {
-        destPtr = static_cast<void *>(destination.mHandle);
-        secure = true;
-    } else {
-        destPtr = destination.mSharedMemory->pointer();
-    }
-
-    ssize_t result = mPlugin->decrypt(secure, key, iv, mode, pattern, srcPtr, subSamples,
-            numSubSamples, destPtr, errorDetailMsg);
-
-    return result;
-}
-
-void Crypto::notifyResolution(uint32_t width, uint32_t height) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck == OK && mPlugin != NULL) {
-        mPlugin->notifyResolution(width, height);
-    }
-}
-
-status_t Crypto::setMediaDrmSession(const Vector<uint8_t> &sessionId) {
-    Mutex::Autolock autoLock(mLock);
-
-    status_t result = NO_INIT;
-    if (mInitCheck == OK && mPlugin != NULL) {
-        result = mPlugin->setMediaDrmSession(sessionId);
-    }
-    return result;
-}
-
-}  // namespace android
diff --git a/drm/libmediadrm/Drm.cpp b/drm/libmediadrm/Drm.cpp
deleted file mode 100644
index 1004eb8..0000000
--- a/drm/libmediadrm/Drm.cpp
+++ /dev/null
@@ -1,799 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "Drm"
-#include <utils/Log.h>
-
-#include <dirent.h>
-#include <dlfcn.h>
-
-#include <media/DrmPluginPath.h>
-#include <media/DrmSessionClientInterface.h>
-#include <media/DrmSessionManager.h>
-#include <media/Drm.h>
-#include <media/drm/DrmAPI.h>
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/foundation/AString.h>
-#include <media/stagefright/foundation/hexdump.h>
-#include <media/stagefright/MediaErrors.h>
-#include <binder/IServiceManager.h>
-#include <binder/IPCThreadState.h>
-
-namespace android {
-
-static inline int getCallingPid() {
-    return IPCThreadState::self()->getCallingPid();
-}
-
-static bool checkPermission(const char* permissionString) {
-    if (getpid() == IPCThreadState::self()->getCallingPid()) return true;
-    bool ok = checkCallingPermission(String16(permissionString));
-    if (!ok) ALOGE("Request requires %s", permissionString);
-    return ok;
-}
-
-KeyedVector<Vector<uint8_t>, String8> Drm::mUUIDToLibraryPathMap;
-KeyedVector<String8, wp<SharedLibrary> > Drm::mLibraryPathToOpenLibraryMap;
-Mutex Drm::mMapLock;
-Mutex Drm::mLock;
-
-static bool operator<(const Vector<uint8_t> &lhs, const Vector<uint8_t> &rhs) {
-    if (lhs.size() < rhs.size()) {
-        return true;
-    } else if (lhs.size() > rhs.size()) {
-        return false;
-    }
-
-    return memcmp((void *)lhs.array(), (void *)rhs.array(), rhs.size()) < 0;
-}
-
-struct DrmSessionClient : public DrmSessionClientInterface {
-    explicit DrmSessionClient(Drm* drm) : mDrm(drm) {}
-
-    virtual bool reclaimSession(const Vector<uint8_t>& sessionId) {
-        sp<Drm> drm = mDrm.promote();
-        if (drm == NULL) {
-            return true;
-        }
-        status_t err = drm->closeSession(sessionId);
-        if (err != OK) {
-            return false;
-        }
-        drm->sendEvent(DrmPlugin::kDrmPluginEventSessionReclaimed, 0, &sessionId, NULL);
-        return true;
-    }
-
-protected:
-    virtual ~DrmSessionClient() {}
-
-private:
-    wp<Drm> mDrm;
-
-    DISALLOW_EVIL_CONSTRUCTORS(DrmSessionClient);
-};
-
-Drm::Drm()
-    : mInitCheck(NO_INIT),
-      mDrmSessionClient(new DrmSessionClient(this)),
-      mListener(NULL),
-      mFactory(NULL),
-      mPlugin(NULL) {
-}
-
-Drm::~Drm() {
-    DrmSessionManager::Instance()->removeDrm(mDrmSessionClient);
-    delete mPlugin;
-    mPlugin = NULL;
-    closeFactory();
-}
-
-void Drm::closeFactory() {
-    delete mFactory;
-    mFactory = NULL;
-    mLibrary.clear();
-}
-
-status_t Drm::initCheck() const {
-    return mInitCheck;
-}
-
-status_t Drm::setListener(const sp<IDrmClient>& listener)
-{
-    Mutex::Autolock lock(mEventLock);
-    if (mListener != NULL){
-        IInterface::asBinder(mListener)->unlinkToDeath(this);
-    }
-    if (listener != NULL) {
-        IInterface::asBinder(listener)->linkToDeath(this);
-    }
-    mListener = listener;
-    return NO_ERROR;
-}
-
-void Drm::sendEvent(DrmPlugin::EventType eventType, int extra,
-                    Vector<uint8_t> const *sessionId,
-                    Vector<uint8_t> const *data)
-{
-    mEventLock.lock();
-    sp<IDrmClient> listener = mListener;
-    mEventLock.unlock();
-
-    if (listener != NULL) {
-        Parcel obj;
-        writeByteArray(obj, sessionId);
-        writeByteArray(obj, data);
-
-        Mutex::Autolock lock(mNotifyLock);
-        listener->notify(eventType, extra, &obj);
-    }
-}
-
-void Drm::sendExpirationUpdate(Vector<uint8_t> const *sessionId,
-                               int64_t expiryTimeInMS)
-{
-    mEventLock.lock();
-    sp<IDrmClient> listener = mListener;
-    mEventLock.unlock();
-
-    if (listener != NULL) {
-        Parcel obj;
-        writeByteArray(obj, sessionId);
-        obj.writeInt64(expiryTimeInMS);
-
-        Mutex::Autolock lock(mNotifyLock);
-        listener->notify(DrmPlugin::kDrmPluginEventExpirationUpdate, 0, &obj);
-    }
-}
-
-void Drm::sendKeysChange(Vector<uint8_t> const *sessionId,
-                         Vector<DrmPlugin::KeyStatus> const *keyStatusList,
-                         bool hasNewUsableKey)
-{
-    mEventLock.lock();
-    sp<IDrmClient> listener = mListener;
-    mEventLock.unlock();
-
-    if (listener != NULL) {
-        Parcel obj;
-        writeByteArray(obj, sessionId);
-
-        size_t nkeys = keyStatusList->size();
-        obj.writeInt32(keyStatusList->size());
-        for (size_t i = 0; i < nkeys; ++i) {
-            const DrmPlugin::KeyStatus *keyStatus = &keyStatusList->itemAt(i);
-            writeByteArray(obj, &keyStatus->mKeyId);
-            obj.writeInt32(keyStatus->mType);
-        }
-        obj.writeInt32(hasNewUsableKey);
-
-        Mutex::Autolock lock(mNotifyLock);
-        listener->notify(DrmPlugin::kDrmPluginEventKeysChange, 0, &obj);
-    }
-}
-
-/*
- * Search the plugins directory for a plugin that supports the scheme
- * specified by uuid
- *
- * If found:
- *    mLibrary holds a strong pointer to the dlopen'd library
- *    mFactory is set to the library's factory method
- *    mInitCheck is set to OK
- *
- * If not found:
- *    mLibrary is cleared and mFactory are set to NULL
- *    mInitCheck is set to an error (!OK)
- */
-void Drm::findFactoryForScheme(const uint8_t uuid[16]) {
-
-    closeFactory();
-
-    // lock static maps
-    Mutex::Autolock autoLock(mMapLock);
-
-    // first check cache
-    Vector<uint8_t> uuidVector;
-    uuidVector.appendArray(uuid, sizeof(uuid[0]) * 16);
-    ssize_t index = mUUIDToLibraryPathMap.indexOfKey(uuidVector);
-    if (index >= 0) {
-        if (loadLibraryForScheme(mUUIDToLibraryPathMap[index], uuid)) {
-            mInitCheck = OK;
-            return;
-        } else {
-            ALOGE("Failed to load from cached library path!");
-            mInitCheck = ERROR_UNSUPPORTED;
-            return;
-        }
-    }
-
-    // no luck, have to search
-    String8 dirPath(getDrmPluginPath());
-    DIR* pDir = opendir(dirPath.string());
-
-    if (pDir == NULL) {
-        mInitCheck = ERROR_UNSUPPORTED;
-        ALOGE("Failed to open plugin directory %s", dirPath.string());
-        return;
-    }
-
-
-    struct dirent* pEntry;
-    while ((pEntry = readdir(pDir))) {
-
-        String8 pluginPath = dirPath + "/" + pEntry->d_name;
-
-        if (pluginPath.getPathExtension() == ".so") {
-
-            if (loadLibraryForScheme(pluginPath, uuid)) {
-                mUUIDToLibraryPathMap.add(uuidVector, pluginPath);
-                mInitCheck = OK;
-                closedir(pDir);
-                return;
-            }
-        }
-    }
-
-    closedir(pDir);
-
-    ALOGE("Failed to find drm plugin");
-    mInitCheck = ERROR_UNSUPPORTED;
-}
-
-bool Drm::loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]) {
-
-    // get strong pointer to open shared library
-    ssize_t index = mLibraryPathToOpenLibraryMap.indexOfKey(path);
-    if (index >= 0) {
-        mLibrary = mLibraryPathToOpenLibraryMap[index].promote();
-    } else {
-        index = mLibraryPathToOpenLibraryMap.add(path, NULL);
-    }
-
-    if (!mLibrary.get()) {
-        mLibrary = new SharedLibrary(path);
-        if (!*mLibrary) {
-            return false;
-        }
-
-        mLibraryPathToOpenLibraryMap.replaceValueAt(index, mLibrary);
-    }
-
-    typedef DrmFactory *(*CreateDrmFactoryFunc)();
-
-    CreateDrmFactoryFunc createDrmFactory =
-        (CreateDrmFactoryFunc)mLibrary->lookup("createDrmFactory");
-
-    if (createDrmFactory == NULL ||
-        (mFactory = createDrmFactory()) == NULL ||
-        !mFactory->isCryptoSchemeSupported(uuid)) {
-        closeFactory();
-        return false;
-    }
-    return true;
-}
-
-bool Drm::isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType) {
-
-    Mutex::Autolock autoLock(mLock);
-
-    if (!mFactory || !mFactory->isCryptoSchemeSupported(uuid)) {
-        findFactoryForScheme(uuid);
-        if (mInitCheck != OK) {
-            return false;
-        }
-    }
-
-    if (mimeType != "") {
-        return mFactory->isContentTypeSupported(mimeType);
-    }
-
-    return true;
-}
-
-status_t Drm::createPlugin(const uint8_t uuid[16],
-                           const String8& /* appPackageName */) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mPlugin != NULL) {
-        return -EINVAL;
-    }
-
-    if (!mFactory || !mFactory->isCryptoSchemeSupported(uuid)) {
-        findFactoryForScheme(uuid);
-    }
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    status_t result = mFactory->createDrmPlugin(uuid, &mPlugin);
-    if (mPlugin) {
-        mPlugin->setListener(this);
-    } else {
-        ALOGE("Failed to create plugin");
-        return UNEXPECTED_NULL;
-    }
-    return result;
-}
-
-status_t Drm::destroyPlugin() {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    setListener(NULL);
-    delete mPlugin;
-    mPlugin = NULL;
-
-    return OK;
-}
-
-status_t Drm::openSession(Vector<uint8_t> &sessionId) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    status_t err = mPlugin->openSession(sessionId);
-    if (err == ERROR_DRM_RESOURCE_BUSY) {
-        bool retry = false;
-        mLock.unlock();
-        // reclaimSession may call back to closeSession, since mLock is shared between Drm
-        // instances, we should unlock here to avoid deadlock.
-        retry = DrmSessionManager::Instance()->reclaimSession(getCallingPid());
-        mLock.lock();
-        if (mInitCheck != OK) {
-            return mInitCheck;
-        }
-
-        if (mPlugin == NULL) {
-            return -EINVAL;
-        }
-        if (retry) {
-            err = mPlugin->openSession(sessionId);
-        }
-    }
-    if (err == OK) {
-        DrmSessionManager::Instance()->addSession(getCallingPid(), mDrmSessionClient, sessionId);
-    }
-    return err;
-}
-
-status_t Drm::closeSession(Vector<uint8_t> const &sessionId) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    status_t err = mPlugin->closeSession(sessionId);
-    if (err == OK) {
-        DrmSessionManager::Instance()->removeSession(sessionId);
-    }
-    return err;
-}
-
-status_t Drm::getKeyRequest(Vector<uint8_t> const &sessionId,
-                            Vector<uint8_t> const &initData,
-                            String8 const &mimeType, DrmPlugin::KeyType keyType,
-                            KeyedVector<String8, String8> const &optionalParameters,
-                            Vector<uint8_t> &request, String8 &defaultUrl,
-                            DrmPlugin::KeyRequestType *keyRequestType) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->getKeyRequest(sessionId, initData, mimeType, keyType,
-                                  optionalParameters, request, defaultUrl,
-                                  keyRequestType);
-}
-
-status_t Drm::provideKeyResponse(Vector<uint8_t> const &sessionId,
-                                 Vector<uint8_t> const &response,
-                                 Vector<uint8_t> &keySetId) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->provideKeyResponse(sessionId, response, keySetId);
-}
-
-status_t Drm::removeKeys(Vector<uint8_t> const &keySetId) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->removeKeys(keySetId);
-}
-
-status_t Drm::restoreKeys(Vector<uint8_t> const &sessionId,
-                          Vector<uint8_t> const &keySetId) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->restoreKeys(sessionId, keySetId);
-}
-
-status_t Drm::queryKeyStatus(Vector<uint8_t> const &sessionId,
-                             KeyedVector<String8, String8> &infoMap) const {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->queryKeyStatus(sessionId, infoMap);
-}
-
-status_t Drm::getProvisionRequest(String8 const &certType, String8 const &certAuthority,
-                                  Vector<uint8_t> &request, String8 &defaultUrl) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->getProvisionRequest(certType, certAuthority,
-                                        request, defaultUrl);
-}
-
-status_t Drm::provideProvisionResponse(Vector<uint8_t> const &response,
-                                       Vector<uint8_t> &certificate,
-                                       Vector<uint8_t> &wrappedKey) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->provideProvisionResponse(response, certificate, wrappedKey);
-}
-
-status_t Drm::getSecureStops(List<Vector<uint8_t> > &secureStops) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->getSecureStops(secureStops);
-}
-
-status_t Drm::getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->getSecureStop(ssid, secureStop);
-}
-
-status_t Drm::releaseSecureStops(Vector<uint8_t> const &ssRelease) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->releaseSecureStops(ssRelease);
-}
-
-status_t Drm::releaseAllSecureStops() {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->releaseAllSecureStops();
-}
-
-status_t Drm::getPropertyString(String8 const &name, String8 &value ) const {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->getPropertyString(name, value);
-}
-
-status_t Drm::getPropertyByteArray(String8 const &name, Vector<uint8_t> &value ) const {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->getPropertyByteArray(name, value);
-}
-
-status_t Drm::setPropertyString(String8 const &name, String8 const &value ) const {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->setPropertyString(name, value);
-}
-
-status_t Drm::setPropertyByteArray(String8 const &name,
-                                   Vector<uint8_t> const &value ) const {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    return mPlugin->setPropertyByteArray(name, value);
-}
-
-
-status_t Drm::setCipherAlgorithm(Vector<uint8_t> const &sessionId,
-                                 String8 const &algorithm) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->setCipherAlgorithm(sessionId, algorithm);
-}
-
-status_t Drm::setMacAlgorithm(Vector<uint8_t> const &sessionId,
-                              String8 const &algorithm) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->setMacAlgorithm(sessionId, algorithm);
-}
-
-status_t Drm::encrypt(Vector<uint8_t> const &sessionId,
-                      Vector<uint8_t> const &keyId,
-                      Vector<uint8_t> const &input,
-                      Vector<uint8_t> const &iv,
-                      Vector<uint8_t> &output) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->encrypt(sessionId, keyId, input, iv, output);
-}
-
-status_t Drm::decrypt(Vector<uint8_t> const &sessionId,
-                      Vector<uint8_t> const &keyId,
-                      Vector<uint8_t> const &input,
-                      Vector<uint8_t> const &iv,
-                      Vector<uint8_t> &output) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->decrypt(sessionId, keyId, input, iv, output);
-}
-
-status_t Drm::sign(Vector<uint8_t> const &sessionId,
-                   Vector<uint8_t> const &keyId,
-                   Vector<uint8_t> const &message,
-                   Vector<uint8_t> &signature) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->sign(sessionId, keyId, message, signature);
-}
-
-status_t Drm::verify(Vector<uint8_t> const &sessionId,
-                     Vector<uint8_t> const &keyId,
-                     Vector<uint8_t> const &message,
-                     Vector<uint8_t> const &signature,
-                     bool &match) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->verify(sessionId, keyId, message, signature, match);
-}
-
-status_t Drm::signRSA(Vector<uint8_t> const &sessionId,
-                      String8 const &algorithm,
-                      Vector<uint8_t> const &message,
-                      Vector<uint8_t> const &wrappedKey,
-                      Vector<uint8_t> &signature) {
-    Mutex::Autolock autoLock(mLock);
-
-    if (mInitCheck != OK) {
-        return mInitCheck;
-    }
-
-    if (mPlugin == NULL) {
-        return -EINVAL;
-    }
-
-    if (!checkPermission("android.permission.ACCESS_DRM_CERTIFICATES")) {
-        return -EPERM;
-    }
-
-    DrmSessionManager::Instance()->useSession(sessionId);
-
-    return mPlugin->signRSA(sessionId, algorithm, message, wrappedKey, signature);
-}
-
-void Drm::binderDied(const wp<IBinder> &the_late_who __unused)
-{
-    mEventLock.lock();
-    mListener.clear();
-    mEventLock.unlock();
-
-    Mutex::Autolock autoLock(mLock);
-    delete mPlugin;
-    mPlugin = NULL;
-    closeFactory();
-}
-
-void Drm::writeByteArray(Parcel &obj, Vector<uint8_t> const *array)
-{
-    if (array && array->size()) {
-        obj.writeInt32(array->size());
-        obj.write(array->array(), array->size());
-    } else {
-        obj.writeInt32(0);
-    }
-}
-
-}  // namespace android
diff --git a/drm/mediadrm/Android.bp b/drm/mediadrm/Android.bp
new file mode 100644
index 0000000..b9f07f1
--- /dev/null
+++ b/drm/mediadrm/Android.bp
@@ -0,0 +1 @@
+subdirs = ["plugins/*"]
diff --git a/drm/mediadrm/plugins/clearkey/Android.bp b/drm/mediadrm/plugins/clearkey/Android.bp
new file mode 100644
index 0000000..6af7cd8
--- /dev/null
+++ b/drm/mediadrm/plugins/clearkey/Android.bp
@@ -0,0 +1,54 @@
+//
+// Copyright (C) 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_shared {
+    name: "libdrmclearkeyplugin",
+
+    srcs: [
+        "AesCtrDecryptor.cpp",
+        "ClearKeyUUID.cpp",
+        "CreatePluginFactories.cpp",
+        "CryptoFactory.cpp",
+        "CryptoPlugin.cpp",
+        "DrmFactory.cpp",
+        "DrmPlugin.cpp",
+        "InitDataParser.cpp",
+        "JsonWebKey.cpp",
+        "Session.cpp",
+        "SessionLibrary.cpp",
+        "Utils.cpp",
+    ],
+
+    vendor: true,
+    relative_install_path: "mediadrm",
+
+    shared_libs: [
+        "libcrypto",
+        "liblog",
+        "libstagefright_foundation",
+        "libutils",
+    ],
+
+    static_libs: ["libjsmn"],
+
+    export_include_dirs: ["."],
+    export_static_lib_headers: ["libjsmn"],
+}
+
+//########################################################################
+// Build unit tests
+
+subdirs = ["tests"]
diff --git a/drm/mediadrm/plugins/clearkey/Android.mk b/drm/mediadrm/plugins/clearkey/Android.mk
deleted file mode 100644
index 2efdcf5..0000000
--- a/drm/mediadrm/plugins/clearkey/Android.mk
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    AesCtrDecryptor.cpp \
-    ClearKeyUUID.cpp \
-    CreatePluginFactories.cpp \
-    CryptoFactory.cpp \
-    CryptoPlugin.cpp \
-    DrmFactory.cpp \
-    DrmPlugin.cpp \
-    InitDataParser.cpp \
-    JsonWebKey.cpp \
-    Session.cpp \
-    SessionLibrary.cpp \
-    Utils.cpp \
-
-LOCAL_C_INCLUDES := \
-    external/jsmn \
-    frameworks/av/drm/mediadrm/plugins/clearkey \
-    frameworks/av/include \
-    frameworks/native/include \
-
-LOCAL_MODULE := libdrmclearkeyplugin
-
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_MODULE_RELATIVE_PATH := mediadrm
-
-LOCAL_SHARED_LIBRARIES := \
-    libcrypto \
-    liblog \
-    libstagefright_foundation \
-    libutils \
-
-LOCAL_STATIC_LIBRARIES := \
-    libjsmn \
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-#########################################################################
-# Build unit tests
-
-include $(LOCAL_PATH)/tests/Android.mk
diff --git a/drm/mediadrm/plugins/clearkey/tests/Android.bp b/drm/mediadrm/plugins/clearkey/tests/Android.bp
new file mode 100644
index 0000000..1b208ad
--- /dev/null
+++ b/drm/mediadrm/plugins/clearkey/tests/Android.bp
@@ -0,0 +1,36 @@
+//
+// Copyright (C) 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// ----------------------------------------------------------------
+// Builds ClearKey Drm Tests
+//
+
+cc_test {
+    name: "ClearKeyDrmUnitTest",
+
+    srcs: [
+        "AesCtrDecryptorUnittest.cpp",
+        "InitDataParserUnittest.cpp",
+        "JsonWebKeyUnittest.cpp",
+    ],
+
+    shared_libs: [
+        "libcrypto",
+        "libdrmclearkeyplugin",
+        "liblog",
+        "libstagefright_foundation",
+        "libutils",
+    ],
+}
diff --git a/drm/mediadrm/plugins/clearkey/tests/Android.mk b/drm/mediadrm/plugins/clearkey/tests/Android.mk
deleted file mode 100644
index 392f218..0000000
--- a/drm/mediadrm/plugins/clearkey/tests/Android.mk
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# ----------------------------------------------------------------
-# Builds ClearKey Drm Tests
-#
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := ClearKeyDrmUnitTest
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-    AesCtrDecryptorUnittest.cpp \
-    InitDataParserUnittest.cpp \
-    JsonWebKeyUnittest.cpp \
-
-LOCAL_C_INCLUDES := \
-    external/jsmn \
-    frameworks/av/drm/mediadrm/plugins/clearkey \
-    frameworks/av/include \
-    frameworks/native/include \
-
-LOCAL_SHARED_LIBRARIES := \
-    libcrypto \
-    libdrmclearkeyplugin \
-    liblog \
-    libstagefright_foundation \
-    libutils \
-
-include $(BUILD_NATIVE_TEST)
diff --git a/drm/mediadrm/plugins/clearkey/tests/InitDataParserUnittest.cpp b/drm/mediadrm/plugins/clearkey/tests/InitDataParserUnittest.cpp
index e275108..84ed242 100644
--- a/drm/mediadrm/plugins/clearkey/tests/InitDataParserUnittest.cpp
+++ b/drm/mediadrm/plugins/clearkey/tests/InitDataParserUnittest.cpp
@@ -56,7 +56,7 @@
                               request.size());
         EXPECT_EQ(0, requestString.find(kRequestPrefix));
         EXPECT_EQ(requestString.size() - kRequestSuffix.size(),
-                  requestString.find(kRequestSuffix));
+                  (size_t)requestString.find(kRequestSuffix));
         for (size_t i = 0; i < expectedKeys.size(); ++i) {
             AString encodedIdAString;
             android::encodeBase64(expectedKeys[i], kKeyIdSize,
@@ -71,7 +71,7 @@
                                       const String8& mimeType) {
         Vector<uint8_t> request;
         ASSERT_NE(android::OK, attemptParse(initData, mimeType, &request));
-        EXPECT_EQ(0, request.size());
+        EXPECT_EQ(0u, request.size());
     }
 };
 
diff --git a/drm/mediadrm/plugins/mock/Android.bp b/drm/mediadrm/plugins/mock/Android.bp
new file mode 100644
index 0000000..7f44819
--- /dev/null
+++ b/drm/mediadrm/plugins/mock/Android.bp
@@ -0,0 +1,34 @@
+//
+// Copyright (C) 2013 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_shared {
+    name: "libmockdrmcryptoplugin",
+
+    srcs: ["MockDrmCryptoPlugin.cpp"],
+
+    vendor: true,
+    relative_install_path: "mediadrm",
+
+    shared_libs: [
+        "libutils",
+        "liblog",
+    ],
+
+    cflags: [
+        // Set the following flag to enable the decryption passthru flow
+        //"-DENABLE_PASSTHRU_DECRYPTION",
+    ],
+}
diff --git a/drm/mediadrm/plugins/mock/Android.mk b/drm/mediadrm/plugins/mock/Android.mk
deleted file mode 100644
index 26c245b..0000000
--- a/drm/mediadrm/plugins/mock/Android.mk
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Copyright (C) 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    MockDrmCryptoPlugin.cpp
-
-LOCAL_MODULE := libmockdrmcryptoplugin
-
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_MODULE_RELATIVE_PATH := mediadrm
-
-LOCAL_SHARED_LIBRARIES := \
-    libutils liblog
-
-LOCAL_C_INCLUDES += \
-    $(TOP)/frameworks/av/include \
-    $(TOP)/frameworks/native/include/media
-
-# Set the following flag to enable the decryption passthru flow
-#LOCAL_CFLAGS += -DENABLE_PASSTHRU_DECRYPTION
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp
index c82b9d9..3b4145f 100644
--- a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp
+++ b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp
@@ -19,7 +19,7 @@
 #include <utils/Log.h>
 
 
-#include "drm/DrmAPI.h"
+#include "media/drm/DrmAPI.h"
 #include "MockDrmCryptoPlugin.h"
 #include "media/stagefright/MediaErrors.h"
 
@@ -730,7 +730,7 @@
 
     ssize_t MockDrmPlugin::findSession(Vector<uint8_t> const &sessionId) const
     {
-        ALOGD("findSession: nsessions=%u, size=%u", mSessions.size(), sessionId.size());
+        ALOGD("findSession: nsessions=%zu, size=%zu", mSessions.size(), sessionId.size());
         for (size_t i = 0; i < mSessions.size(); ++i) {
             if (memcmp(mSessions[i].array(), sessionId.array(), sessionId.size()) == 0) {
                 return i;
@@ -741,7 +741,7 @@
 
     ssize_t MockDrmPlugin::findKeySet(Vector<uint8_t> const &keySetId) const
     {
-        ALOGD("findKeySet: nkeySets=%u, size=%u", mKeySets.size(), keySetId.size());
+        ALOGD("findKeySet: nkeySets=%zu, size=%zu", mKeySets.size(), keySetId.size());
         for (size_t i = 0; i < mKeySets.size(); ++i) {
             if (memcmp(mKeySets[i].array(), keySetId.array(), keySetId.size()) == 0) {
                 return i;
@@ -792,8 +792,9 @@
     }
 
     ssize_t
-    MockCryptoPlugin::decrypt(bool secure, const uint8_t key[16], const uint8_t iv[16],
-            Mode mode, const Pattern &pattern, const void *srcPtr,
+    MockCryptoPlugin::decrypt(bool secure, const uint8_t key[DECRYPT_KEY_SIZE],
+            const uint8_t iv[DECRYPT_KEY_SIZE], Mode mode,
+            const Pattern &pattern, const void *srcPtr,
             const SubSample *subSamples, size_t numSubSamples,
             void *dstPtr, AString * /* errorDetailMsg */)
     {
@@ -801,8 +802,8 @@
               "pattern:{encryptBlocks=%d, skipBlocks=%d} src=%p, "
               "subSamples=%s, dst=%p)",
               (int)secure,
-              arrayToString(key, sizeof(key)).string(),
-              arrayToString(iv, sizeof(iv)).string(),
+              arrayToString(key, DECRYPT_KEY_SIZE).string(),
+              arrayToString(iv, DECRYPT_KEY_SIZE).string(),
               (int)mode, pattern.mEncryptBlocks, pattern.mSkipBlocks, srcPtr,
               subSamplesToString(subSamples, numSubSamples).string(),
               dstPtr);
diff --git a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
index 9f8db17..4178c03 100644
--- a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
+++ b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
@@ -16,8 +16,8 @@
 
 #include <utils/Mutex.h>
 
-#include "drm/DrmAPI.h"
-#include "hardware/CryptoAPI.h"
+#include "media/drm/DrmAPI.h"
+#include "media/hardware/CryptoAPI.h"
 
 extern "C" {
       android::DrmFactory *createDrmFactory();
@@ -158,9 +158,12 @@
 
         bool requiresSecureDecoderComponent(const char *mime) const;
 
+        static constexpr size_t DECRYPT_KEY_SIZE = 16;
+
         ssize_t decrypt(bool secure,
-            const uint8_t key[16], const uint8_t iv[16],
-            Mode mode, const Pattern &pattern, const void *srcPtr,
+            const uint8_t key[DECRYPT_KEY_SIZE],
+            const uint8_t iv[DECRYPT_KEY_SIZE], Mode mode,
+            const Pattern &pattern, const void *srcPtr,
             const SubSample *subSamples, size_t numSubSamples,
             void *dstPtr, AString *errorDetailMsg);
     private:
diff --git a/include/media/CasImpl.h b/include/media/CasImpl.h
index 0dd506c..726f1ce 100644
--- a/include/media/CasImpl.h
+++ b/include/media/CasImpl.h
@@ -27,7 +27,7 @@
 using namespace media;
 using namespace MediaCas;
 using binder::Status;
-class CasPlugin;
+struct CasPlugin;
 class SharedLibrary;
 
 class CasImpl : public BnCas {
diff --git a/include/media/DescramblerImpl.h b/include/media/DescramblerImpl.h
index c1c79b3..9f212ac 100644
--- a/include/media/DescramblerImpl.h
+++ b/include/media/DescramblerImpl.h
@@ -24,7 +24,7 @@
 using namespace media;
 using namespace MediaDescrambler;
 using binder::Status;
-class DescramblerPlugin;
+struct DescramblerPlugin;
 class SharedLibrary;
 
 class DescramblerImpl : public BnDescrambler {
diff --git a/include/media/Interpolator.h b/include/media/Interpolator.h
index 45a0585..703cf77 100644
--- a/include/media/Interpolator.h
+++ b/include/media/Interpolator.h
@@ -278,7 +278,7 @@
             if (res != NO_ERROR) {
                 return res;
             }
-            if (i > 0 && !(x > lastx) /* handle nan */
+            if ((i > 0 && !(x > lastx)) /* handle nan */
                     || y != y /* handle nan */) {
                 // This is a std::map object which imposes sorted order
                 // automatically on emplace.
diff --git a/include/media/VolumeShaper.h b/include/media/VolumeShaper.h
index e4c0b5b..302641f 100644
--- a/include/media/VolumeShaper.h
+++ b/include/media/VolumeShaper.h
@@ -32,11 +32,8 @@
 #define LOG_TAG "VolumeShaper"
 
 // turn on VolumeShaper logging
-#if 0
-#define VS_LOG ALOGD
-#else
-#define VS_LOG(...)
-#endif
+#define VS_LOGGING 0
+#define VS_LOG(...) ALOGD_IF(VS_LOGGING, __VA_ARGS__)
 
 namespace android {
 
@@ -128,18 +125,18 @@
             : Interpolator<S, T>()
             , RefBase()
             , mType(TYPE_SCALE)
+            , mId(-1)
             , mOptionFlags(OPTION_FLAG_NONE)
-            , mDurationMs(1000.)
-            , mId(-1) {
+            , mDurationMs(1000.) {
         }
 
         explicit Configuration(const Configuration &configuration)
             : Interpolator<S, T>(*static_cast<const Interpolator<S, T> *>(&configuration))
             , RefBase()
             , mType(configuration.mType)
+            , mId(configuration.mId)
             , mOptionFlags(configuration.mOptionFlags)
-            , mDurationMs(configuration.mDurationMs)
-            , mId(configuration.mId) {
+            , mDurationMs(configuration.mDurationMs) {
         }
 
         Type getType() const {
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
index 7becf57..9da5ef3 100644
--- a/include/private/media/AudioTrackShared.h
+++ b/include/private/media/AudioTrackShared.h
@@ -172,7 +172,7 @@
                 // client write-only, server read-only
                 uint16_t    mSendLevel;      // Fixed point U4.12 so 0x1000 means 1.0
 
-                uint16_t    mPad2;           // unused
+                uint16_t    mPad2 __attribute__((__unused__)); // unused
 
                 // server write-only, client read
                 ExtendedTimestampQueue::Shared mExtendedTimestampQueue;
diff --git a/include/private/media/VideoFrame.h b/include/private/media/VideoFrame.h
index 5193d00..51050cd 100644
--- a/include/private/media/VideoFrame.h
+++ b/include/private/media/VideoFrame.h
@@ -30,8 +30,8 @@
 class VideoFrame
 {
 public:
-    VideoFrame(): mWidth(0), mHeight(0), mDisplayWidth(0), mDisplayHeight(0), mSize(0), mData(0),
-            mRotationAngle(0) {}
+    VideoFrame(): mWidth(0), mHeight(0), mDisplayWidth(0), mDisplayHeight(0), mSize(0),
+            mRotationAngle(0), mData(0) {}
 
     VideoFrame(const VideoFrame& copy) {
         mWidth = copy.mWidth;
diff --git a/include/radio/Radio.h b/include/radio/Radio.h
index a4dfdd1..fb4dd2f 100644
--- a/include/radio/Radio.h
+++ b/include/radio/Radio.h
@@ -79,7 +79,6 @@
 
             Mutex                   mLock;
             sp<IRadio>              mIRadio;
-            const radio_handle_t    mHandle;
             sp<RadioCallback>       mCallback;
 };
 
diff --git a/include/soundtrigger/SoundTrigger.h b/include/soundtrigger/SoundTrigger.h
index 9a05cac..7a29e31 100644
--- a/include/soundtrigger/SoundTrigger.h
+++ b/include/soundtrigger/SoundTrigger.h
@@ -72,7 +72,6 @@
 
             Mutex                               mLock;
             sp<ISoundTrigger>                   mISoundTrigger;
-            const sound_trigger_module_handle_t mModule;
             sp<SoundTriggerCallback>            mCallback;
 };
 
diff --git a/media/img_utils/Android.bp b/media/img_utils/Android.bp
new file mode 100644
index 0000000..64530e1
--- /dev/null
+++ b/media/img_utils/Android.bp
@@ -0,0 +1,60 @@
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_shared {
+    name: "libimg_utils",
+
+    srcs: [
+        "src/EndianUtils.cpp",
+        "src/FileInput.cpp",
+        "src/FileOutput.cpp",
+        "src/SortedEntryVector.cpp",
+        "src/Input.cpp",
+        "src/Output.cpp",
+        "src/Orderable.cpp",
+        "src/TiffIfd.cpp",
+        "src/TiffWritable.cpp",
+        "src/TiffWriter.cpp",
+        "src/TiffEntry.cpp",
+        "src/TiffEntryImpl.cpp",
+        "src/ByteArrayOutput.cpp",
+        "src/DngUtils.cpp",
+        "src/StripSource.cpp",
+    ],
+
+    shared_libs: [
+        "liblog",
+        "libutils",
+        "libcutils",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+        "-fvisibility=hidden",
+    ],
+
+    product_variables: {
+        debuggable: {
+            // Enable assert() in eng builds
+            cflags: [
+                "-UNDEBUG",
+                "-DLOG_NDEBUG=1",
+            ],
+        },
+    },
+
+    export_include_dirs: ["include"],
+}
diff --git a/media/img_utils/Android.mk b/media/img_utils/Android.mk
deleted file mode 100644
index 1cd00bd..0000000
--- a/media/img_utils/Android.mk
+++ /dev/null
@@ -1,15 +0,0 @@
-# Copyright 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(call all-subdir-makefiles)
diff --git a/media/img_utils/src/Android.mk b/media/img_utils/src/Android.mk
deleted file mode 100644
index 4c6fe70..0000000
--- a/media/img_utils/src/Android.mk
+++ /dev/null
@@ -1,60 +0,0 @@
-# Copyright 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-  EndianUtils.cpp \
-  FileInput.cpp \
-  FileOutput.cpp \
-  SortedEntryVector.cpp \
-  Input.cpp \
-  Output.cpp \
-  Orderable.cpp \
-  TiffIfd.cpp \
-  TiffWritable.cpp \
-  TiffWriter.cpp \
-  TiffEntry.cpp \
-  TiffEntryImpl.cpp \
-  ByteArrayOutput.cpp \
-  DngUtils.cpp \
-  StripSource.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-  liblog \
-  libutils \
-  libcutils \
-
-LOCAL_C_INCLUDES += \
-  $(LOCAL_PATH)/../include \
-  system/media/camera/include
-
-LOCAL_CFLAGS += \
-  -Wall \
-  -Wextra \
-  -Werror \
-  -fvisibility=hidden
-
-ifneq ($(filter userdebug eng,$(TARGET_BUILD_VARIANT)),)
-    # Enable assert() in eng builds
-    LOCAL_CFLAGS += -UNDEBUG -DLOG_NDEBUG=1
-endif
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../include
-
-LOCAL_MODULE := libimg_utils
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libaudioclient/Android.bp b/media/libaudioclient/Android.bp
index 166534f..4c24401 100644
--- a/media/libaudioclient/Android.bp
+++ b/media/libaudioclient/Android.bp
@@ -40,7 +40,6 @@
     // for memory heap analysis
     static_libs: [
         "libc_malloc_debug_backtrace",
-        "libc_logging",
     ],
     cflags: [
         "-Wall",
diff --git a/media/libaudioclient/include/media/AudioPolicyHelper.h b/media/libaudioclient/include/media/AudioPolicyHelper.h
index 854057d..73ee0a7 100644
--- a/media/libaudioclient/include/media/AudioPolicyHelper.h
+++ b/media/libaudioclient/include/media/AudioPolicyHelper.h
@@ -18,9 +18,8 @@
 
 #include <system/audio.h>
 
-// TODO: fix this among dependencies
-__attribute__((unused))
-static audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
+static inline
+audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
 {
     // flags to stream type mapping
     if ((attr->flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) == AUDIO_FLAG_AUDIBILITY_ENFORCED) {
@@ -65,9 +64,8 @@
     }
 }
 
-// TODO: fix this among dependencies
-__attribute__((unused))
-static void stream_type_to_audio_attributes(audio_stream_type_t streamType,
+static inline
+void stream_type_to_audio_attributes(audio_stream_type_t streamType,
                                      audio_attributes_t *attr) {
     memset(attr, 0, sizeof(audio_attributes_t));
 
diff --git a/media/libaudioprocessing/AudioMixer.cpp b/media/libaudioprocessing/AudioMixer.cpp
index 05b726a..ae1be09 100644
--- a/media/libaudioprocessing/AudioMixer.cpp
+++ b/media/libaudioprocessing/AudioMixer.cpp
@@ -27,7 +27,6 @@
 #include <utils/Errors.h>
 #include <utils/Log.h>
 
-#include <cutils/bitops.h>
 #include <cutils/compiler.h>
 #include <utils/Debug.h>
 
diff --git a/media/libcpustats/Android.bp b/media/libcpustats/Android.bp
new file mode 100644
index 0000000..3ea96c9
--- /dev/null
+++ b/media/libcpustats/Android.bp
@@ -0,0 +1,13 @@
+cc_library_static {
+    name: "libcpustats",
+
+    srcs: [
+        "CentralTendencyStatistics.cpp",
+        "ThreadCpuUsage.cpp",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+}
diff --git a/media/libcpustats/Android.mk b/media/libcpustats/Android.mk
deleted file mode 100644
index b2d73ee..0000000
--- a/media/libcpustats/Android.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES :=     \
-        CentralTendencyStatistics.cpp \
-        ThreadCpuUsage.cpp
-
-LOCAL_MODULE := libcpustats
-
-LOCAL_CFLAGS := -Werror -Wall
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libeffects/downmix/Android.mk b/media/libeffects/downmix/Android.mk
index 78601d5..09793d1 100644
--- a/media/libeffects/downmix/Android.mk
+++ b/media/libeffects/downmix/Android.mk
@@ -3,6 +3,7 @@
 # Multichannel downmix effect library
 include $(CLEAR_VARS)
 
+LOCAL_VENDOR_MODULE := true
 LOCAL_SRC_FILES:= \
 	EffectDownmix.c
 
diff --git a/media/libeffects/loudness/Android.mk b/media/libeffects/loudness/Android.mk
index 3db4a79..712cbd5 100644
--- a/media/libeffects/loudness/Android.mk
+++ b/media/libeffects/loudness/Android.mk
@@ -3,21 +3,22 @@
 # LoudnessEnhancer library
 include $(CLEAR_VARS)
 
+LOCAL_VENDOR_MODULE := true
 LOCAL_SRC_FILES:= \
-	EffectLoudnessEnhancer.cpp \
-	dsp/core/dynamic_range_compression.cpp
+    EffectLoudnessEnhancer.cpp \
+    dsp/core/dynamic_range_compression.cpp
 
 LOCAL_CFLAGS+= -O2 -fvisibility=hidden
 LOCAL_CFLAGS += -Wall -Werror
 
 LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-	liblog \
+    libcutils \
+    liblog \
 
 LOCAL_MODULE_RELATIVE_PATH := soundfx
 LOCAL_MODULE:= libldnhncr
 
-LOCAL_C_INCLUDES := \
-	$(call include-path-for, audio-effects) \
+LOCAL_HEADER_LIBRARIES := \
+    libaudioeffects
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libeffects/lvm/lib/Android.mk b/media/libeffects/lvm/lib/Android.mk
index afc87bb..83e8288 100644
--- a/media/libeffects/lvm/lib/Android.mk
+++ b/media/libeffects/lvm/lib/Android.mk
@@ -6,6 +6,7 @@
 
 LOCAL_ARM_MODE := arm
 
+LOCAL_VENDOR_MODULE := true
 LOCAL_SRC_FILES:= \
     StereoWidening/src/LVCS_BypassMix.c \
     StereoWidening/src/LVCS_Control.c \
@@ -131,6 +132,7 @@
 
 LOCAL_ARM_MODE := arm
 
+LOCAL_VENDOR_MODULE := true
 LOCAL_SRC_FILES:= \
     Reverb/src/LVREV_ApplyNewSettings.c \
     Reverb/src/LVREV_ClearAudioBuffers.c \
diff --git a/media/libeffects/lvm/wrapper/Android.mk b/media/libeffects/lvm/wrapper/Android.mk
index 9051587..f92fb95 100644
--- a/media/libeffects/lvm/wrapper/Android.mk
+++ b/media/libeffects/lvm/wrapper/Android.mk
@@ -6,6 +6,7 @@
 
 LOCAL_ARM_MODE := arm
 
+LOCAL_VENDOR_MODULE := true
 LOCAL_SRC_FILES:= \
 	Bundle/EffectBundle.cpp
 
@@ -37,6 +38,7 @@
 
 LOCAL_ARM_MODE := arm
 
+LOCAL_VENDOR_MODULE := true
 LOCAL_SRC_FILES:= \
     Reverb/EffectReverb.cpp
 
diff --git a/media/libeffects/proxy/Android.mk b/media/libeffects/proxy/Android.mk
index 0acf1c0..c4de30d 100644
--- a/media/libeffects/proxy/Android.mk
+++ b/media/libeffects/proxy/Android.mk
@@ -18,7 +18,7 @@
 LOCAL_MODULE_RELATIVE_PATH := soundfx
 LOCAL_MODULE_TAGS := optional
 
-
+LOCAL_VENDOR_MODULE := true
 LOCAL_SRC_FILES := \
         EffectProxy.cpp
 
diff --git a/media/libeffects/visualizer/Android.mk b/media/libeffects/visualizer/Android.mk
index ddcc565..8687e1b 100644
--- a/media/libeffects/visualizer/Android.mk
+++ b/media/libeffects/visualizer/Android.mk
@@ -3,6 +3,7 @@
 # Visualizer library
 include $(CLEAR_VARS)
 
+LOCAL_VENDOR_MODULE := true
 LOCAL_SRC_FILES:= \
 	EffectVisualizer.cpp
 
diff --git a/media/libmedia/Android.bp b/media/libmedia/Android.bp
index 11a498d..e9b99b4 100644
--- a/media/libmedia/Android.bp
+++ b/media/libmedia/Android.bp
@@ -18,3 +18,141 @@
     },
     clang: true,
 }
+
+cc_library_shared {
+    name: "libmedia",
+
+    aidl: {
+        local_include_dirs: ["aidl"],
+        export_aidl_headers: true,
+    },
+
+    srcs: [
+        "aidl/android/IGraphicBufferSource.aidl",
+        "aidl/android/IOMXBufferSource.aidl",
+
+        "IDataSource.cpp",
+        "IHDCP.cpp",
+        "BufferingSettings.cpp",
+        "mediaplayer.cpp",
+        "IMediaCodecList.cpp",
+        "IMediaCodecService.cpp",
+        "IMediaHTTPConnection.cpp",
+        "IMediaHTTPService.cpp",
+        "IMediaExtractor.cpp",
+        "IMediaExtractorService.cpp",
+        "IMediaPlayerService.cpp",
+        "IMediaPlayerClient.cpp",
+        "IMediaRecorderClient.cpp",
+        "IMediaPlayer.cpp",
+        "IMediaRecorder.cpp",
+        "IMediaSource.cpp",
+        "IRemoteDisplay.cpp",
+        "IRemoteDisplayClient.cpp",
+        "IResourceManagerClient.cpp",
+        "IResourceManagerService.cpp",
+        "IStreamSource.cpp",
+        "MediaCodecBuffer.cpp",
+        "MediaCodecInfo.cpp",
+        "MediaDefs.cpp",
+        "MediaUtils.cpp",
+        "Metadata.cpp",
+        "mediarecorder.cpp",
+        "IMediaMetadataRetriever.cpp",
+        "mediametadataretriever.cpp",
+        "MidiDeviceInfo.cpp",
+        "MidiIoWrapper.cpp",
+        "JetPlayer.cpp",
+        "IOMX.cpp",
+        "MediaScanner.cpp",
+        "MediaScannerClient.cpp",
+        "CharacterEncodingDetector.cpp",
+        "IMediaDeathNotifier.cpp",
+        "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: [
+        "libui",
+        "liblog",
+        "libcutils",
+        "libutils",
+        "libbinder",
+        "libsonivox",
+        "libicuuc",
+        "libicui18n",
+        "libexpat",
+        "libcamera_client",
+        "libstagefright_foundation",
+        "libgui",
+        "libdl",
+        "libaudioutils",
+        "libaudioclient",
+        "libmedia_helper",
+        "libmediadrm",
+        "libmediametrics",
+        "libbase",
+        "libhidlbase",
+        "libhidltransport",
+        "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: [
+        "libbinder",
+        "libicuuc",
+        "libicui18n",
+        "libsonivox",
+        "libmediadrm",
+        "android.hidl.token@1.0-utils",
+        "android.hardware.media.omx@1.0",
+        "android.hidl.memory@1.0",
+    ],
+
+    // for memory heap analysis
+    static_libs: [
+        "libc_malloc_debug_backtrace",
+    ],
+
+    include_dirs: [
+        "frameworks/native/include/media/openmax",
+        "frameworks/av/include/media/",
+        "frameworks/av/media/libstagefright",
+    ],
+
+    export_include_dirs: [
+        "aidl",
+        "include",
+    ],
+    cflags: [
+        "-Werror",
+        "-Wno-error=deprecated-declarations",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "unsigned-integer-overflow",
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libmedia/Android.mk b/media/libmedia/Android.mk
deleted file mode 100644
index e2d48a2..0000000
--- a/media/libmedia/Android.mk
+++ /dev/null
@@ -1,116 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_AIDL_INCLUDES := \
-    frameworks/av/media/libmedia/aidl
-
-LOCAL_SRC_FILES:= \
-    aidl/android/IGraphicBufferSource.aidl \
-    aidl/android/IOMXBufferSource.aidl
-
-LOCAL_SRC_FILES += \
-    IDataSource.cpp \
-    IHDCP.cpp \
-    BufferingSettings.cpp \
-    mediaplayer.cpp \
-    IMediaCodecList.cpp \
-    IMediaCodecService.cpp \
-    IMediaHTTPConnection.cpp \
-    IMediaHTTPService.cpp \
-    IMediaExtractor.cpp           \
-    IMediaExtractorService.cpp \
-    IMediaPlayerService.cpp \
-    IMediaPlayerClient.cpp \
-    IMediaRecorderClient.cpp \
-    IMediaPlayer.cpp \
-    IMediaRecorder.cpp \
-    IMediaSource.cpp \
-    IRemoteDisplay.cpp \
-    IRemoteDisplayClient.cpp \
-    IResourceManagerClient.cpp \
-    IResourceManagerService.cpp \
-    IStreamSource.cpp \
-    MediaCodecBuffer.cpp \
-    MediaCodecInfo.cpp \
-    MediaDefs.cpp \
-    MediaUtils.cpp \
-    Metadata.cpp \
-    mediarecorder.cpp \
-    IMediaMetadataRetriever.cpp \
-    mediametadataretriever.cpp \
-    MidiDeviceInfo.cpp \
-    MidiIoWrapper.cpp \
-    JetPlayer.cpp \
-    IOMX.cpp \
-    MediaScanner.cpp \
-    MediaScannerClient.cpp \
-    CharacterEncodingDetector.cpp \
-    IMediaDeathNotifier.cpp \
-    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 \
-
-LOCAL_SHARED_LIBRARIES := \
-        libui liblog libcutils libutils libbinder libsonivox libicuuc libicui18n libexpat \
-        libcamera_client libstagefright_foundation \
-        libgui libdl libaudioutils libaudioclient \
-        libmedia_helper libmediadrm \
-        libmediametrics \
-        libbase \
-        libhidlbase \
-        libhidltransport \
-        libhwbinder \
-        libhidlmemory \
-        android.hidl.base@1.0 \
-        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 \
-
-LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := \
-        libbinder \
-        libsonivox \
-        libmediadrm \
-        android.hidl.token@1.0-utils \
-        android.hardware.media.omx@1.0 \
-        android.hidl.memory@1.0 \
-
-LOCAL_HEADER_LIBRARIES := libmedia_headers
-
-# for memory heap analysis
-LOCAL_STATIC_LIBRARIES := libc_malloc_debug_backtrace libc_logging
-
-LOCAL_MODULE:= libmedia
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_C_INCLUDES := \
-    $(TOP)/system/libhidl/base/include \
-    $(TOP)/frameworks/native/include/media/openmax \
-    $(TOP)/frameworks/av/include/media/ \
-    $(TOP)/frameworks/av/media/libmedia/aidl \
-    $(TOP)/frameworks/av/include \
-    $(TOP)/frameworks/native/include \
-    $(call include-path-for, audio-utils)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := \
-    frameworks/av/include/media \
-    frameworks/av/media/libmedia/aidl \
-
-LOCAL_CFLAGS += -Werror -Wno-error=deprecated-declarations -Wall
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_SHARED_LIBRARY)
-
diff --git a/media/libmedia/MediaCodecInfo.cpp b/media/libmedia/MediaCodecInfo.cpp
index 62a7bdf..1f188f3 100644
--- a/media/libmedia/MediaCodecInfo.cpp
+++ b/media/libmedia/MediaCodecInfo.cpp
@@ -85,13 +85,13 @@
 }
 
 status_t MediaCodecInfo::Capabilities::writeToParcel(Parcel *parcel) const {
-    CHECK_LE(mProfileLevels.size(), INT32_MAX);
+    CHECK_LE(mProfileLevels.size(), static_cast<size_t>(INT32_MAX));
     parcel->writeInt32(mProfileLevels.size());
     for (size_t i = 0; i < mProfileLevels.size(); i++) {
         parcel->writeInt32(mProfileLevels.itemAt(i).mProfile);
         parcel->writeInt32(mProfileLevels.itemAt(i).mLevel);
     }
-    CHECK_LE(mColorFormats.size(), INT32_MAX);
+    CHECK_LE(mColorFormats.size(), static_cast<size_t>(INT32_MAX));
     parcel->writeInt32(mColorFormats.size());
     for (size_t i = 0; i < mColorFormats.size(); i++) {
         parcel->writeInt32(mColorFormats.itemAt(i));
diff --git a/media/libmedia/Visualizer.cpp b/media/libmedia/Visualizer.cpp
index 37bf0bd..4984b18 100644
--- a/media/libmedia/Visualizer.cpp
+++ b/media/libmedia/Visualizer.cpp
@@ -24,8 +24,6 @@
 #include <sys/types.h>
 #include <limits.h>
 
-#include <cutils/bitops.h>
-
 #include <media/Visualizer.h>
 #include <audio_utils/fixedfft.h>
 #include <utils/Thread.h>
diff --git a/media/libmedia/include/media/MediaRecorderBase.h b/media/libmedia/include/media/MediaRecorderBase.h
index 0b0f916..40dd9f9 100644
--- a/media/libmedia/include/media/MediaRecorderBase.h
+++ b/media/libmedia/include/media/MediaRecorderBase.h
@@ -45,7 +45,7 @@
                                const sp<ICameraRecordingProxy>& proxy) = 0;
     virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface) = 0;
     virtual status_t setOutputFile(int fd) = 0;
-    virtual status_t setNextOutputFile(int fd) {return INVALID_OPERATION;}
+    virtual status_t setNextOutputFile(int /*fd*/) {return INVALID_OPERATION;}
     virtual status_t setOutputFileAuxiliary(int /*fd*/) {return INVALID_OPERATION;}
     virtual status_t setParameters(const String8& params) = 0;
     virtual status_t setListener(const sp<IMediaRecorderClient>& listener) = 0;
diff --git a/media/libmedia/include/media/TypeConverter.h b/media/libmedia/include/media/TypeConverter.h
index cb8a307..84e22b1 100644
--- a/media/libmedia/include/media/TypeConverter.h
+++ b/media/libmedia/include/media/TypeConverter.h
@@ -203,7 +203,8 @@
     if (mask != 0) {
         bool first_flag = true;
         for (size_t i = 0; mTable[i].literal; i++) {
-            if (mTable[i].value != 0 && (mask & mTable[i].value) == mTable[i].value) {
+            uint32_t value = static_cast<uint32_t>(mTable[i].value);
+            if (mTable[i].value != 0 && ((mask & value) == value)) {
                 if (!first_flag) str += del;
                 first_flag = false;
                 str += mTable[i].literal;
@@ -228,6 +229,20 @@
 typedef TypeConverter<UsageTraits> UsageTypeConverter;
 typedef TypeConverter<SourceTraits> SourceTypeConverter;
 
+template<> const OutputDeviceConverter::Table OutputDeviceConverter::mTable[];
+template<> const InputDeviceConverter::Table InputDeviceConverter::mTable[];
+template<> const OutputFlagConverter::Table OutputFlagConverter::mTable[];
+template<> const InputFlagConverter::Table InputFlagConverter::mTable[];
+template<> const FormatConverter::Table FormatConverter::mTable[];
+template<> const OutputChannelConverter::Table OutputChannelConverter::mTable[];
+template<> const InputChannelConverter::Table InputChannelConverter::mTable[];
+template<> const ChannelIndexConverter::Table ChannelIndexConverter::mTable[];
+template<> const GainModeConverter::Table GainModeConverter::mTable[];
+template<> const StreamTypeConverter::Table StreamTypeConverter::mTable[];
+template<> const AudioModeConverter::Table AudioModeConverter::mTable[];
+template<> const UsageTypeConverter::Table UsageTypeConverter::mTable[];
+template<> const SourceTypeConverter::Table SourceTypeConverter::mTable[];
+
 bool deviceFromString(const std::string& literalDevice, audio_devices_t& device);
 
 bool deviceToString(audio_devices_t device, std::string& literalDevice);
diff --git a/media/libmediametrics/Android.bp b/media/libmediametrics/Android.bp
new file mode 100644
index 0000000..15dac59
--- /dev/null
+++ b/media/libmediametrics/Android.bp
@@ -0,0 +1,36 @@
+cc_library_shared {
+    name: "libmediametrics",
+
+    srcs: [
+        "IMediaAnalyticsService.cpp",
+        "MediaAnalyticsItem.cpp",
+    ],
+
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libutils",
+        "libbinder",
+        "libstagefright_foundation",
+        "libbase",
+    ],
+
+    export_include_dirs: ["include"],
+
+    cflags: [
+        "-Werror",
+        "-Wno-error=deprecated-declarations",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "unsigned-integer-overflow",
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libmediametrics/Android.mk b/media/libmediametrics/Android.mk
deleted file mode 100644
index f8c4bb3..0000000
--- a/media/libmediametrics/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES += \
-    IMediaAnalyticsService.cpp \
-    MediaAnalyticsItem.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-        liblog libcutils libutils libbinder \
-        libstagefright_foundation \
-        libbase \
-
-LOCAL_MODULE:= libmediametrics
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_C_INCLUDES := \
-    $(TOP)/system/libhidl/base/include \
-    $(TOP)/frameworks/native/include/media/openmax \
-    $(TOP)/frameworks/av/include/media/ \
-    $(TOP)/frameworks/av/media/libmedia/aidl \
-    $(TOP)/frameworks/av/include \
-    $(TOP)/frameworks/native/include \
-    $(call include-path-for, audio-utils)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := \
-    frameworks/av/include/media \
-
-LOCAL_CFLAGS += -Werror -Wno-error=deprecated-declarations -Wall
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libmediaplayerservice/Android.mk b/media/libmediaplayerservice/Android.mk
index 7af7031..b5159ed 100644
--- a/media/libmediaplayerservice/Android.mk
+++ b/media/libmediaplayerservice/Android.mk
@@ -65,6 +65,9 @@
 
 LOCAL_32_BIT_ONLY := true
 
+LOCAL_SANITIZE := cfi
+LOCAL_SANITIZE_DIAG := cfi
+
 include $(BUILD_SHARED_LIBRARY)
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libmediaplayerservice/include/MediaPlayerInterface.h b/media/libmediaplayerservice/include/MediaPlayerInterface.h
index a01f7f2..e8d59a7 100644
--- a/media/libmediaplayerservice/include/MediaPlayerInterface.h
+++ b/media/libmediaplayerservice/include/MediaPlayerInterface.h
@@ -286,7 +286,7 @@
     }
 
     // Modular DRM
-    virtual status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t>& drmSessionId) {
+    virtual status_t prepareDrm(const uint8_t /* uuid */[16], const Vector<uint8_t>& /* drmSessionId */) {
         return INVALID_OPERATION;
     }
     virtual status_t releaseDrm() {
diff --git a/media/libmediaplayerservice/nuplayer/Android.mk b/media/libmediaplayerservice/nuplayer/Android.mk
index 08c3cf8..bd893bc 100644
--- a/media/libmediaplayerservice/nuplayer/Android.mk
+++ b/media/libmediaplayerservice/nuplayer/Android.mk
@@ -44,5 +44,7 @@
 
 LOCAL_MODULE_TAGS := eng
 
-include $(BUILD_STATIC_LIBRARY)
+LOCAL_SANITIZE := cfi
+LOCAL_SANITIZE_DIAG := cfi
 
+include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index 0d4c730..0ffe17d 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -762,12 +762,13 @@
             }
 
             mDeferredActions.push_back(
-                    new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */,
+                    new FlushDecoderAction(
+                            (obj != NULL ? FLUSH_CMD_FLUSH : FLUSH_CMD_NONE) /* audio */,
                                            FLUSH_CMD_SHUTDOWN /* video */));
 
             mDeferredActions.push_back(new SetSurfaceAction(surface));
 
-            if (obj != NULL || mAudioDecoder != NULL) {
+            if (obj != NULL) {
                 if (mStarted) {
                     // Issue a seek to refresh the video screen only if started otherwise
                     // the extractor may not yet be started and will assert.
@@ -785,13 +786,13 @@
                 // again if possible.
                 mDeferredActions.push_back(
                         new SimpleAction(&NuPlayer::performScanSources));
-            }
 
-            // After a flush without shutdown, decoder is paused.
-            // Don't resume it until source seek is done, otherwise it could
-            // start pulling stale data too soon.
-            mDeferredActions.push_back(
-                    new ResumeDecoderAction(false /* needNotify */));
+                // After a flush without shutdown, decoder is paused.
+                // Don't resume it until source seek is done, otherwise it could
+                // start pulling stale data too soon.
+                mDeferredActions.push_back(
+                        new ResumeDecoderAction(false /* needNotify */));
+            }
 
             processDeferredActions();
             break;
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
index 5775b43..758db1f 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
@@ -1110,7 +1110,7 @@
             // (Case 1)
             // Must be a multiple of the frame size.  If it is not a multiple of a frame size, it
             // needs to fail, as we should not carry over fractional frames between calls.
-            CHECK_EQ(copy % mAudioSink->frameSize(), 0);
+            CHECK_EQ(copy % mAudioSink->frameSize(), 0u);
 
             // (Case 2, 3, 4)
             // Return early to the caller.
diff --git a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp
index 9264e49..8b3d0dc 100644
--- a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp
@@ -544,7 +544,7 @@
         return;
     }
 
-    CHECK_EQ(msg->what(), (int)kWhatNotify);
+    CHECK_EQ(msg->what(), kWhatNotify);
 
     int32_t what;
     CHECK(msg->findInt32("what", &what));
diff --git a/media/libmediaplayerservice/tests/Android.mk b/media/libmediaplayerservice/tests/Android.mk
index dc761ec..0b9b85f 100644
--- a/media/libmediaplayerservice/tests/Android.mk
+++ b/media/libmediaplayerservice/tests/Android.mk
@@ -14,7 +14,6 @@
 	libmediaplayerservice \
 	libmediadrm \
 	libutils \
-	android.hidl.base@1.0 \
 	android.hardware.drm@1.0 \
 
 LOCAL_C_INCLUDES := \
diff --git a/media/libnbaio/NBLog.cpp b/media/libnbaio/NBLog.cpp
index de38e7f..9cccfc4 100644
--- a/media/libnbaio/NBLog.cpp
+++ b/media/libnbaio/NBLog.cpp
@@ -957,7 +957,6 @@
 // ---------------------------------------------------------------------------
 
 NBLog::Merger::Merger(const void *shared, size_t size):
-      mBuffer(NULL),
       mShared((Shared *) shared),
       mFifo(mShared != NULL ?
         new audio_utils_fifo(size, sizeof(uint8_t),
diff --git a/media/libnbaio/include/NBLog.h b/media/libnbaio/include/NBLog.h
index 59b77bd..bcebe9e 100644
--- a/media/libnbaio/include/NBLog.h
+++ b/media/libnbaio/include/NBLog.h
@@ -72,6 +72,7 @@
     class iterator;
     explicit FormatEntry(const uint8_t *entry);
     explicit FormatEntry(const iterator &it);
+    virtual ~FormatEntry() {}
 
     // entry representation in memory
     struct entry {
@@ -380,7 +381,7 @@
                                          String8 *timestamp,
                                          String8 *body);
     // dummy method for handling absent author entry
-    virtual size_t handleAuthor(const FormatEntry &fmtEntry, String8 *body) { return 0; }
+    virtual size_t handleAuthor(const FormatEntry& /*fmtEntry*/, String8* /*body*/) { return 0; }
 
     // Searches for the last entry of type <type> in the range [front, back)
     // back has to be entry-aligned. Returns nullptr if none enconuntered.
@@ -422,7 +423,6 @@
     // vector of the readers the merger is supposed to merge from.
     // every reader reads from a writer's buffer
     std::vector<NamedReader> mNamedReaders;
-    uint8_t *mBuffer;
     Shared * const mShared;
     std::unique_ptr<audio_utils_fifo> mFifo;
     std::unique_ptr<audio_utils_fifo_writer> mFifoWriter;
diff --git a/media/libstagefright/Android.bp b/media/libstagefright/Android.bp
index 3d9341b..478e306 100644
--- a/media/libstagefright/Android.bp
+++ b/media/libstagefright/Android.bp
@@ -1 +1,168 @@
-subdirs = ["foundation"]
+cc_library_shared {
+    name: "libstagefright",
+
+    srcs: [
+        "ACodec.cpp",
+        "ACodecBufferChannel.cpp",
+        "AACExtractor.cpp",
+        "AACWriter.cpp",
+        "AMRExtractor.cpp",
+        "AMRWriter.cpp",
+        "AudioPlayer.cpp",
+        "AudioSource.cpp",
+        "BufferImpl.cpp",
+        "CallbackDataSource.cpp",
+        "CameraSource.cpp",
+        "CameraSourceTimeLapse.cpp",
+        "DataConverter.cpp",
+        "DataSource.cpp",
+        "DataURISource.cpp",
+        "ESDS.cpp",
+        "FileSource.cpp",
+        "FLACExtractor.cpp",
+        "FrameRenderTracker.cpp",
+        "HTTPBase.cpp",
+        "HevcUtils.cpp",
+        "JPEGSource.cpp",
+        "MP3Extractor.cpp",
+        "MPEG2TSWriter.cpp",
+        "MPEG4Extractor.cpp",
+        "MPEG4Writer.cpp",
+        "MediaAdapter.cpp",
+        "MediaClock.cpp",
+        "MediaCodec.cpp",
+        "MediaCodecList.cpp",
+        "MediaCodecListOverrides.cpp",
+        "MediaCodecSource.cpp",
+        "MediaExtractor.cpp",
+        "MediaSync.cpp",
+        "MidiExtractor.cpp",
+        "http/MediaHTTP.cpp",
+        "MediaMuxer.cpp",
+        "MediaSource.cpp",
+        "NuCachedSource2.cpp",
+        "NuMediaExtractor.cpp",
+        "OMXClient.cpp",
+        "OggExtractor.cpp",
+        "SampleIterator.cpp",
+        "SampleTable.cpp",
+        "SimpleDecodingSource.cpp",
+        "SkipCutBuffer.cpp",
+        "StagefrightMediaScanner.cpp",
+        "StagefrightMetadataRetriever.cpp",
+        "SurfaceMediaSource.cpp",
+        "SurfaceUtils.cpp",
+        "ThrottledSource.cpp",
+        "Utils.cpp",
+        "VBRISeeker.cpp",
+        "VideoFrameScheduler.cpp",
+        "WAVExtractor.cpp",
+        "XINGSeeker.cpp",
+        "avc_utils.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/native/include/media/openmax",
+        "frameworks/native/include/media/hardware",
+    ],
+
+    shared_libs: [
+        "libaudioutils",
+        "libbinder",
+        "libcamera_client",
+        "libcrypto",
+        "libcutils",
+        "libdl",
+        "libdrmframework",
+        "libexpat",
+        "libgui",
+        "liblog",
+        "libmedia",
+        "libaudioclient",
+        "libmediametrics",
+        "libmediautils",
+        "libnetd_client",
+        "libsonivox",
+        "libstagefright_omx",
+        "libui",
+        "libutils",
+        "libvorbisidec",
+        "libmediadrm",
+        "libnativewindow",
+
+        "libmedia_helper",
+        "libstagefright_foundation",
+        "libdl",
+        "libRScpp",
+        "libhidlbase",
+        "libhidlmemory",
+        "android.hidl.allocator@1.0",
+        "android.hidl.memory@1.0",
+        "android.hardware.media.omx@1.0",
+        "libstagefright_xmlparser@1.0",
+    ],
+
+    static_libs: [
+        "libstagefright_color_conversion",
+        "libyuv_static",
+        "libstagefright_aacenc",
+        "libstagefright_matroska",
+        "libstagefright_mediafilter",
+        "libstagefright_webm",
+        "libstagefright_timedtext",
+        "libvpx",
+        "libwebm",
+        "libstagefright_mpeg2ts",
+        "libstagefright_id3",
+        "libFLAC",
+    ],
+
+    export_shared_lib_headers: ["libmedia"],
+    export_include_dirs: [
+        ".",
+        "include",
+    ],
+
+    cflags: [
+        "-Wno-multichar",
+        "-Werror",
+        "-Wno-error=deprecated-declarations",
+        "-Wall",
+    ],
+
+    product_variables: {
+        debuggable: {
+            // enable experiments only in userdebug and eng builds
+            cflags: ["-DENABLE_STAGEFRIGHT_EXPERIMENTS"],
+        },
+    },
+
+    sanitize: {
+        cfi: true,
+        misc_undefined: [
+            "unsigned-integer-overflow",
+            "signed-integer-overflow",
+        ],
+        diag: {
+            cfi: true,
+        },
+    },
+}
+
+subdirs = [
+    "codecs/*",
+    "colorconversion",
+    "filters",
+    "foundation",
+    "http",
+    "httplive",
+    "id3",
+    "matroska",
+    "mpeg2ts",
+    "omx",
+    "rtsp",
+    "tests",
+    "timedtext",
+    "webm",
+    "wifi-display",
+]
diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk
deleted file mode 100644
index 372b11a..0000000
--- a/media/libstagefright/Android.mk
+++ /dev/null
@@ -1,145 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-
-LOCAL_SRC_FILES:=                         \
-        ACodec.cpp                        \
-        ACodecBufferChannel.cpp           \
-        AACExtractor.cpp                  \
-        AACWriter.cpp                     \
-        AMRExtractor.cpp                  \
-        AMRWriter.cpp                     \
-        AudioPlayer.cpp                   \
-        AudioSource.cpp                   \
-        BufferImpl.cpp                    \
-        CallbackDataSource.cpp            \
-        CameraSource.cpp                  \
-        CameraSourceTimeLapse.cpp         \
-        DataConverter.cpp                 \
-        DataSource.cpp                    \
-        DataURISource.cpp                 \
-        ESDS.cpp                          \
-        FileSource.cpp                    \
-        FLACExtractor.cpp                 \
-        FrameRenderTracker.cpp            \
-        HTTPBase.cpp                      \
-        HevcUtils.cpp                     \
-        JPEGSource.cpp                    \
-        MP3Extractor.cpp                  \
-        MPEG2TSWriter.cpp                 \
-        MPEG4Extractor.cpp                \
-        MPEG4Writer.cpp                   \
-        MediaAdapter.cpp                  \
-        MediaClock.cpp                    \
-        MediaCodec.cpp                    \
-        MediaCodecList.cpp                \
-        MediaCodecListOverrides.cpp       \
-        MediaCodecSource.cpp              \
-        MediaExtractor.cpp                \
-        MediaSync.cpp                     \
-        MidiExtractor.cpp                 \
-        http/MediaHTTP.cpp                \
-        MediaMuxer.cpp                    \
-        MediaSource.cpp                   \
-        NuCachedSource2.cpp               \
-        NuMediaExtractor.cpp              \
-        OMXClient.cpp                     \
-        OggExtractor.cpp                  \
-        SampleIterator.cpp                \
-        SampleTable.cpp                   \
-        SimpleDecodingSource.cpp          \
-        SkipCutBuffer.cpp                 \
-        StagefrightMediaScanner.cpp       \
-        StagefrightMetadataRetriever.cpp  \
-        SurfaceMediaSource.cpp            \
-        SurfaceUtils.cpp                  \
-        ThrottledSource.cpp               \
-        Utils.cpp                         \
-        VBRISeeker.cpp                    \
-        VideoFrameScheduler.cpp           \
-        WAVExtractor.cpp                  \
-        XINGSeeker.cpp                    \
-        avc_utils.cpp                     \
-
-LOCAL_C_INCLUDES:= \
-        $(TOP)/frameworks/av/include/media/ \
-        $(TOP)/frameworks/av/include/media/stagefright/timedtext \
-        $(TOP)/frameworks/native/include/media/hardware \
-        $(TOP)/frameworks/native/include/media/openmax \
-        $(TOP)/external/flac/include \
-        $(TOP)/external/tremolo \
-        $(TOP)/external/libvpx/libwebm \
-        $(TOP)/external/icu/icu4c/source/common \
-        $(TOP)/external/icu/icu4c/source/i18n \
-        $(TOP)/system/netd/include \
-        $(call include-path-for, audio-utils)
-
-LOCAL_SHARED_LIBRARIES := \
-        libaudioutils \
-        libbinder \
-        libcamera_client \
-        libcrypto \
-        libcutils \
-        libdl \
-        libdrmframework \
-        libexpat \
-        libgui \
-        liblog \
-        libmedia \
-        libaudioclient \
-        libmediametrics \
-        libmediautils \
-        libnetd_client \
-        libsonivox \
-        libstagefright_omx \
-        libui \
-        libutils \
-        libvorbisidec \
-        libmediadrm \
-        libnativewindow \
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_color_conversion \
-        libyuv_static \
-        libstagefright_aacenc \
-        libstagefright_matroska \
-        libstagefright_mediafilter \
-        libstagefright_webm \
-        libstagefright_timedtext \
-        libvpx \
-        libwebm \
-        libstagefright_mpeg2ts \
-        libstagefright_id3 \
-        libFLAC \
-
-LOCAL_SHARED_LIBRARIES += \
-        libmedia_helper \
-        libstagefright_foundation \
-        libdl \
-        libRScpp \
-        libhidlbase \
-        libhidlmemory \
-        android.hidl.allocator@1.0 \
-        android.hidl.memory@1.0 \
-        android.hardware.media.omx@1.0 \
-        libstagefright_xmlparser@1.0 \
-
-LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libmedia
-
-LOCAL_CFLAGS += -Wno-multichar -Werror -Wno-error=deprecated-declarations -Wall
-
-# enable experiments only in userdebug and eng builds
-ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
-LOCAL_CFLAGS += -DENABLE_STAGEFRIGHT_EXPERIMENTS
-endif
-
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_MODULE:= libstagefright
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/MPEG2TSWriter.cpp b/media/libstagefright/MPEG2TSWriter.cpp
index b83b0a0..03ea959 100644
--- a/media/libstagefright/MPEG2TSWriter.cpp
+++ b/media/libstagefright/MPEG2TSWriter.cpp
@@ -710,7 +710,7 @@
     uint32_t crc = htonl(crc32(&buffer->data()[5], 12));
     memcpy(&buffer->data()[17], &crc, sizeof(crc));
 
-    CHECK_EQ(internalWrite(buffer->data(), buffer->size()), buffer->size());
+    CHECK_EQ(internalWrite(buffer->data(), buffer->size()), (ssize_t)buffer->size());
 }
 
 void MPEG2TSWriter::writeProgramMap() {
@@ -786,7 +786,7 @@
     uint32_t crc = htonl(crc32(&buffer->data()[5], 12+mSources.size()*5));
     memcpy(&buffer->data()[17+mSources.size()*5], &crc, sizeof(crc));
 
-    CHECK_EQ(internalWrite(buffer->data(), buffer->size()), buffer->size());
+    CHECK_EQ(internalWrite(buffer->data(), buffer->size()), (ssize_t)buffer->size());
 }
 
 void MPEG2TSWriter::writeAccessUnit(
@@ -891,7 +891,7 @@
 
     memcpy(ptr, accessUnit->data(), copy);
 
-    CHECK_EQ(internalWrite(buffer->data(), buffer->size()), buffer->size());
+    CHECK_EQ(internalWrite(buffer->data(), buffer->size()), (ssize_t)buffer->size());
 
     size_t offset = copy;
     while (offset < accessUnit->size()) {
@@ -937,7 +937,7 @@
 
         memcpy(ptr, accessUnit->data() + offset, copy);
         CHECK_EQ(internalWrite(buffer->data(), buffer->size()),
-                 buffer->size());
+                 (ssize_t)buffer->size());
 
         offset += copy;
     }
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 4f18a26..b48257f 100755
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -140,7 +140,7 @@
             mTotalNumTableEntries(0),
             mNumValuesInCurrEntry(0),
             mCurrTableEntriesElement(NULL) {
-            CHECK_GT(mElementCapacity, 0);
+            CHECK_GT(mElementCapacity, 0u);
             // Ensure no integer overflow on allocation in add().
             CHECK_LT(ENTRY_SIZE, UINT32_MAX / mElementCapacity);
         }
@@ -168,7 +168,7 @@
                 --iterations;
             }
             CHECK(it != mTableEntryList.end());
-            CHECK_EQ(iterations, 0);
+            CHECK_EQ(iterations, 0u);
 
             (*it)[(pos % (mElementCapacity * ENTRY_SIZE))] = value;
         }
@@ -189,7 +189,7 @@
                 --iterations;
             }
             CHECK(it != mTableEntryList.end());
-            CHECK_EQ(iterations, 0);
+            CHECK_EQ(iterations, 0u);
 
             value = (*it)[(pos % (mElementCapacity * ENTRY_SIZE))];
             return true;
@@ -237,12 +237,12 @@
         // 2. followed by the values in the table enties in order
         // @arg writer the writer to actual write to the storage
         void write(MPEG4Writer *writer) const {
-            CHECK_EQ(mNumValuesInCurrEntry % ENTRY_SIZE, 0);
+            CHECK_EQ(mNumValuesInCurrEntry % ENTRY_SIZE, 0u);
             uint32_t nEntries = mTotalNumTableEntries;
             writer->writeInt32(nEntries);
             for (typename List<TYPE *>::iterator it = mTableEntryList.begin();
                 it != mTableEntryList.end(); ++it) {
-                CHECK_GT(nEntries, 0);
+                CHECK_GT(nEntries, 0u);
                 if (nEntries >= mElementCapacity) {
                     writer->write(*it, sizeof(TYPE) * ENTRY_SIZE, mElementCapacity);
                     nEntries -= mElementCapacity;
@@ -1280,7 +1280,7 @@
 
         mOffset += length + 4;
     } else {
-        CHECK_LT(length, 65536);
+        CHECK_LT(length, 65536u);
 
         uint8_t x = length >> 8;
         ::write(mFd, &x, 1);
@@ -1340,7 +1340,7 @@
 }
 
 void MPEG4Writer::beginBox(const char *fourcc) {
-    CHECK_EQ(strlen(fourcc), 4);
+    CHECK_EQ(strlen(fourcc), 4u);
 
     mBoxes.push_back(mWriteMoovBoxToMemory?
             mMoovBoxBufferOffset: mOffset);
@@ -1391,7 +1391,7 @@
 }
 
 void MPEG4Writer::writeFourcc(const char *s) {
-    CHECK_EQ(strlen(s), 4);
+    CHECK_EQ(strlen(s), 4u);
     write(s, 1, 4);
 }
 
@@ -3363,10 +3363,10 @@
 void MPEG4Writer::Track::writeMp4aEsdsBox() {
     mOwner->beginBox("esds");
     CHECK(mCodecSpecificData);
-    CHECK_GT(mCodecSpecificDataSize, 0);
+    CHECK_GT(mCodecSpecificDataSize, 0u);
 
     // Make sure all sizes encode to a single byte.
-    CHECK_LT(mCodecSpecificDataSize + 23, 128);
+    CHECK_LT(mCodecSpecificDataSize + 23, 128u);
 
     mOwner->writeInt32(0);     // version=0, flags=0
     mOwner->writeInt8(0x03);   // ES_DescrTag
@@ -3405,10 +3405,10 @@
 
 void MPEG4Writer::Track::writeMp4vEsdsBox() {
     CHECK(mCodecSpecificData);
-    CHECK_GT(mCodecSpecificDataSize, 0);
+    CHECK_GT(mCodecSpecificDataSize, 0u);
 
     // Make sure all sizes encode to a single byte.
-    CHECK_LT(23 + mCodecSpecificDataSize, 128);
+    CHECK_LT(23 + mCodecSpecificDataSize, 128u);
 
     mOwner->beginBox("esds");
 
@@ -3600,7 +3600,7 @@
 
 void MPEG4Writer::Track::writeAvccBox() {
     CHECK(mCodecSpecificData);
-    CHECK_GE(mCodecSpecificDataSize, 5);
+    CHECK_GE(mCodecSpecificDataSize, 5u);
 
     // Patch avcc's lengthSize field to match the number
     // of bytes we use to indicate the size of a nal unit.
@@ -3614,7 +3614,7 @@
 
 void MPEG4Writer::Track::writeHvccBox() {
     CHECK(mCodecSpecificData);
-    CHECK_GE(mCodecSpecificDataSize, 5);
+    CHECK_GE(mCodecSpecificDataSize, 5u);
 
     // Patch avcc's lengthSize field to match the number
     // of bytes we use to indicate the size of a nal unit.
diff --git a/media/libstagefright/SampleIterator.cpp b/media/libstagefright/SampleIterator.cpp
index 4134698..4f31c5f 100644
--- a/media/libstagefright/SampleIterator.cpp
+++ b/media/libstagefright/SampleIterator.cpp
@@ -282,7 +282,7 @@
 
         default:
         {
-            CHECK_EQ(mTable->mSampleSizeFieldSize, 4);
+            CHECK_EQ(mTable->mSampleSizeFieldSize, 4u);
 
             uint8_t x;
             if (mTable->mDataSource->readAt(
diff --git a/media/libstagefright/StagefrightMetadataRetriever.cpp b/media/libstagefright/StagefrightMetadataRetriever.cpp
index 883a4dd..03dc9df 100644
--- a/media/libstagefright/StagefrightMetadataRetriever.cpp
+++ b/media/libstagefright/StagefrightMetadataRetriever.cpp
@@ -44,7 +44,7 @@
 #include <media/stagefright/MetaData.h>
 #include <media/stagefright/Utils.h>
 
-#include <CharacterEncodingDetector.h>
+#include <media/CharacterEncodingDetector.h>
 
 namespace android {
 
diff --git a/media/libstagefright/SurfaceMediaSource.cpp b/media/libstagefright/SurfaceMediaSource.cpp
index d0d82b3..d14e86b 100644
--- a/media/libstagefright/SurfaceMediaSource.cpp
+++ b/media/libstagefright/SurfaceMediaSource.cpp
@@ -96,13 +96,13 @@
     mFrameAvailableListener = listener;
 }
 
-void SurfaceMediaSource::dump(String8& result) const
+void SurfaceMediaSource::dumpState(String8& result) const
 {
     char buffer[1024];
-    dump(result, "", buffer, 1024);
+    dumpState(result, "", buffer, 1024);
 }
 
-void SurfaceMediaSource::dump(
+void SurfaceMediaSource::dumpState(
         String8& result,
         const char* /* prefix */,
         char* buffer,
@@ -166,7 +166,7 @@
         mMaxAcquiredBufferCount = bufferCount;
     }
 
-    CHECK_GT(mMaxAcquiredBufferCount, 1);
+    CHECK_GT(mMaxAcquiredBufferCount, 1u);
 
     status_t err =
         mConsumer->setMaxAcquiredBufferCount(mMaxAcquiredBufferCount);
@@ -185,7 +185,7 @@
     ALOGV("setMaxAcquiredBufferCount(%zu)", count);
     Mutex::Autolock lock(mMutex);
 
-    CHECK_GT(count, 1);
+    CHECK_GT(count, 1u);
     mMaxAcquiredBufferCount = count;
 
     return OK;
diff --git a/media/libstagefright/codecs/Android.mk b/media/libstagefright/codecs/Android.mk
deleted file mode 100644
index 2e43120..0000000
--- a/media/libstagefright/codecs/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/codecs/aacdec/Android.bp b/media/libstagefright/codecs/aacdec/Android.bp
new file mode 100644
index 0000000..6e04c1e
--- /dev/null
+++ b/media/libstagefright/codecs/aacdec/Android.bp
@@ -0,0 +1,36 @@
+cc_library_shared {
+    name: "libstagefright_soft_aacdec",
+
+    srcs: [
+        "SoftAAC2.cpp",
+        "DrcPresModeWrap.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    static_libs: ["libFraunhoferAAC"],
+
+    shared_libs: [
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "libcutils",
+        "liblog",
+    ],
+}
diff --git a/media/libstagefright/codecs/aacdec/Android.mk b/media/libstagefright/codecs/aacdec/Android.mk
deleted file mode 100644
index 29c0f33..0000000
--- a/media/libstagefright/codecs/aacdec/Android.mk
+++ /dev/null
@@ -1,33 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-      SoftAAC2.cpp \
-      DrcPresModeWrap.cpp
-
-LOCAL_C_INCLUDES := \
-      frameworks/av/media/libstagefright/include \
-      frameworks/native/include/media/openmax \
-      external/aac/libAACdec/include \
-      external/aac/libPCMutils/include \
-      external/aac/libFDK/include \
-      external/aac/libMpegTPDec/include \
-      external/aac/libSBRdec/include \
-      external/aac/libSYS/include
-
-LOCAL_CFLAGS :=
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_STATIC_LIBRARIES := libFraunhoferAAC
-
-LOCAL_SHARED_LIBRARIES := \
-      libstagefright_omx libstagefright_foundation libutils libcutils liblog
-
-LOCAL_MODULE := libstagefright_soft_aacdec
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/aacenc/AACEncoder.cpp b/media/libstagefright/codecs/aacenc/AACEncoder.cpp
index 9e596ff..5656139 100644
--- a/media/libstagefright/codecs/aacenc/AACEncoder.cpp
+++ b/media/libstagefright/codecs/aacenc/AACEncoder.cpp
@@ -296,7 +296,7 @@
     memset(&inputData, 0, sizeof(inputData));
     inputData.Buffer = (unsigned char*) mInputFrame;
     inputData.Length = nSamples * sizeof(int16_t);
-    CHECK(VO_ERR_NONE == mApiHandle->SetInputData(mEncoderHandle,&inputData));
+    CHECK((VO_U32)VO_ERR_NONE == mApiHandle->SetInputData(mEncoderHandle,&inputData));
 
     VO_CODECBUFFER outputData;
     memset(&outputData, 0, sizeof(outputData));
diff --git a/media/libstagefright/codecs/aacenc/Android.bp b/media/libstagefright/codecs/aacenc/Android.bp
new file mode 100644
index 0000000..1a7ffca
--- /dev/null
+++ b/media/libstagefright/codecs/aacenc/Android.bp
@@ -0,0 +1,176 @@
+cc_library_static {
+    name: "libstagefright_aacenc",
+
+    srcs: [
+        "basic_op/basicop2.c",
+        "basic_op/oper_32b.c",
+
+        "AACEncoder.cpp",
+        "src/aac_rom.c",
+        "src/aacenc.c",
+        "src/aacenc_core.c",
+        "src/adj_thr.c",
+        "src/band_nrg.c",
+        "src/bit_cnt.c",
+        "src/bitbuffer.c",
+        "src/bitenc.c",
+        "src/block_switch.c",
+        "src/channel_map.c",
+        "src/dyn_bits.c",
+        "src/grp_data.c",
+        "src/interface.c",
+        "src/line_pe.c",
+        "src/ms_stereo.c",
+        "src/pre_echo_control.c",
+        "src/psy_configuration.c",
+        "src/psy_main.c",
+        "src/qc_main.c",
+        "src/quantize.c",
+        "src/sf_estim.c",
+        "src/spreading.c",
+        "src/stat_bits.c",
+        "src/tns.c",
+        "src/transform.c",
+        "src/memalign.c",
+    ],
+
+    arch: {
+        arm: {
+            srcs: [
+                "src/asm/ARMV5E/AutoCorrelation_v5.s",
+                "src/asm/ARMV5E/band_nrg_v5.s",
+                "src/asm/ARMV5E/CalcWindowEnergy_v5.s",
+                "src/asm/ARMV5E/PrePostMDCT_v5.s",
+                "src/asm/ARMV5E/R4R8First_v5.s",
+                "src/asm/ARMV5E/Radix4FFT_v5.s",
+            ],
+
+            cflags: [
+                "-DARMV5E",
+                "-DARM_INASM",
+                "-DARMV5_INASM",
+            ],
+
+            local_include_dirs: ["src/asm/ARMV5E"],
+
+            instruction_set: "arm",
+
+            armv7_a_neon: {
+                exclude_srcs: [
+                    "src/asm/ARMV5E/PrePostMDCT_v5.s",
+                    "src/asm/ARMV5E/R4R8First_v5.s",
+                    "src/asm/ARMV5E/Radix4FFT_v5.s",
+                ],
+                srcs: [
+                    "src/asm/ARMV7/PrePostMDCT_v7.s",
+                    "src/asm/ARMV7/R4R8First_v7.s",
+                    "src/asm/ARMV7/Radix4FFT_v7.s",
+                ],
+
+                cflags: [
+                    "-DARMV7Neon",
+                    "-DARMV6_INASM",
+                ],
+
+                local_include_dirs: ["src/asm/ARMV7"],
+            },
+        },
+    },
+
+    // libstagefright links this static library, so it probably isn't appropriate to
+    // link libstagefright.  However, this library includes libstagefright headers,
+    // and needs libbinder to be able to do so correctly.
+    shared_libs: [
+        "libbinder",
+        "libstagefright_enc_common",
+    ],
+
+    include_dirs: [
+        "frameworks/av/include",
+        "frameworks/av/media/libstagefright/include",
+    ],
+
+    local_include_dirs: [
+        "src",
+        "inc",
+        "basic_op",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+    },
+
+}
+
+//###############################################################################
+
+cc_library_shared {
+    name: "libstagefright_soft_aacenc",
+
+    srcs: ["SoftAACEncoder2.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    static_libs: ["libFraunhoferAAC"],
+
+    shared_libs: [
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+}
+
+cc_library_shared {
+    name: "libstagefright_soft_aacenc_visualon",
+
+    srcs: ["SoftAACEncoder.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: [
+        "-DOSCL_IMPORT_REF=",
+        "-Werror",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+    },
+
+    static_libs: ["libstagefright_aacenc"],
+
+    shared_libs: [
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+        "libstagefright_enc_common",
+    ],
+}
diff --git a/media/libstagefright/codecs/aacenc/Android.mk b/media/libstagefright/codecs/aacenc/Android.mk
deleted file mode 100644
index 527687b..0000000
--- a/media/libstagefright/codecs/aacenc/Android.mk
+++ /dev/null
@@ -1,149 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-AAC_LIBRARY = fraunhofer
-
-LOCAL_SRC_FILES := basic_op/basicop2.c basic_op/oper_32b.c
-
-LOCAL_SRC_FILES += \
-	AACEncoder.cpp \
-	src/aac_rom.c \
-	src/aacenc.c \
-	src/aacenc_core.c \
-	src/adj_thr.c \
-	src/band_nrg.c \
-	src/bit_cnt.c \
-	src/bitbuffer.c \
-	src/bitenc.c \
-	src/block_switch.c \
-	src/channel_map.c \
-	src/dyn_bits.c \
-	src/grp_data.c \
-	src/interface.c \
-	src/line_pe.c \
-	src/ms_stereo.c \
-	src/pre_echo_control.c \
-	src/psy_configuration.c \
-	src/psy_main.c \
-	src/qc_main.c \
-	src/quantize.c \
-	src/sf_estim.c \
-	src/spreading.c \
-	src/stat_bits.c \
-	src/tns.c \
-	src/transform.c \
-	src/memalign.c
-
-ifneq ($(ARCH_ARM_HAVE_NEON),true)
-    LOCAL_SRC_FILES_arm := \
-        src/asm/ARMV5E/AutoCorrelation_v5.s \
-        src/asm/ARMV5E/band_nrg_v5.s \
-        src/asm/ARMV5E/CalcWindowEnergy_v5.s \
-        src/asm/ARMV5E/PrePostMDCT_v5.s \
-        src/asm/ARMV5E/R4R8First_v5.s \
-        src/asm/ARMV5E/Radix4FFT_v5.s
-
-    LOCAL_CFLAGS_arm := -DARMV5E -DARM_INASM -DARMV5_INASM
-    LOCAL_C_INCLUDES_arm := $(LOCAL_PATH)/src/asm/ARMV5E
-else
-    LOCAL_SRC_FILES_arm := \
-        src/asm/ARMV5E/AutoCorrelation_v5.s \
-        src/asm/ARMV5E/band_nrg_v5.s \
-        src/asm/ARMV5E/CalcWindowEnergy_v5.s \
-        src/asm/ARMV7/PrePostMDCT_v7.s \
-        src/asm/ARMV7/R4R8First_v7.s \
-        src/asm/ARMV7/Radix4FFT_v7.s
-    LOCAL_CFLAGS_arm := -DARMV5E -DARMV7Neon -DARM_INASM -DARMV5_INASM -DARMV6_INASM
-    LOCAL_C_INCLUDES_arm := $(LOCAL_PATH)/src/asm/ARMV5E
-    LOCAL_C_INCLUDES_arm += $(LOCAL_PATH)/src/asm/ARMV7
-endif
-
-LOCAL_MODULE := libstagefright_aacenc
-
-LOCAL_ARM_MODE := arm
-
-LOCAL_STATIC_LIBRARIES :=
-
-# libstagefright links this static library, so it probably isn't appropriate to
-# link libstagefright.  However, this library includes libstagefright headers,
-# and needs libbinder to be able to do so correctly.
-LOCAL_SHARED_LIBRARIES := libbinder
-
-LOCAL_C_INCLUDES := \
-	frameworks/av/include \
-	frameworks/av/media/libstagefright/include \
-	frameworks/av/media/libstagefright/codecs/common/include \
-	$(LOCAL_PATH)/src \
-	$(LOCAL_PATH)/inc \
-	$(LOCAL_PATH)/basic_op
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-
-ifeq ($(AAC_LIBRARY), fraunhofer)
-
-  include $(CLEAR_VARS)
-
-  LOCAL_SRC_FILES := \
-          SoftAACEncoder2.cpp
-
-  LOCAL_C_INCLUDES := \
-          frameworks/av/media/libstagefright/include \
-          frameworks/native/include/media/openmax \
-          external/aac/libAACenc/include \
-          external/aac/libFDK/include \
-          external/aac/libMpegTPEnc/include \
-          external/aac/libSBRenc/include \
-          external/aac/libSYS/include
-
-  LOCAL_CFLAGS :=
-
-  LOCAL_CFLAGS += -Werror
-  LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-  LOCAL_SANITIZE_DIAG := cfi
-
-  LOCAL_STATIC_LIBRARIES := libFraunhoferAAC
-
-  LOCAL_SHARED_LIBRARIES := \
-          libstagefright_omx libstagefright_foundation libutils liblog
-
-  LOCAL_MODULE := libstagefright_soft_aacenc
-  LOCAL_MODULE_TAGS := optional
-
-  include $(BUILD_SHARED_LIBRARY)
-
-else # visualon
-
-  LOCAL_SRC_FILES := \
-          SoftAACEncoder.cpp
-
-  LOCAL_C_INCLUDES := \
-          frameworks/av/media/libstagefright/include \
-          frameworks/av/media/libstagefright/codecs/common/include \
-          frameworks/native/include/media/openmax
-
-  LOCAL_CFLAGS := -DOSCL_IMPORT_REF=
-
-  LOCAL_CFLAGS += -Werror
-  LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-  LOCAL_SANITIZE_DIAG := cfi
-
-  LOCAL_STATIC_LIBRARIES := \
-          libstagefright_aacenc
-
-  LOCAL_SHARED_LIBRARIES := \
-          libstagefright_omx libstagefright_foundation libutils liblog \
-          libstagefright_enc_common
-
-  LOCAL_MODULE := libstagefright_soft_aacenc
-  LOCAL_MODULE_TAGS := optional
-
-  include $(BUILD_SHARED_LIBRARY)
-
-endif # $(AAC_LIBRARY)
diff --git a/media/libstagefright/codecs/aacenc/SampleCode/Android.bp b/media/libstagefright/codecs/aacenc/SampleCode/Android.bp
new file mode 100644
index 0000000..c6ba4f3
--- /dev/null
+++ b/media/libstagefright/codecs/aacenc/SampleCode/Android.bp
@@ -0,0 +1,18 @@
+cc_binary {
+    name: "AACEncTest",
+
+    srcs: ["AAC_E_SAMPLES.c"],
+
+    arch: {
+        arm: {
+            instruction_set: "arm",
+        },
+    },
+
+    shared_libs: [
+        "libstagefright",
+        "libdl",
+    ],
+
+    static_libs: ["libstagefright_enc_common"],
+}
diff --git a/media/libstagefright/codecs/aacenc/SampleCode/Android.mk b/media/libstagefright/codecs/aacenc/SampleCode/Android.mk
deleted file mode 100644
index d06dcf6..0000000
--- a/media/libstagefright/codecs/aacenc/SampleCode/Android.mk
+++ /dev/null
@@ -1,23 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    AAC_E_SAMPLES.c \
-    ../../common/cmnMemory.c
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_MODULE := AACEncTest
-
-LOCAL_ARM_MODE := arm
-
-LOCAL_SHARED_LIBRARIES := \
-    libstagefright \
-    libdl
-
-LOCAL_C_INCLUDES := \
-    $(LOCAL_PATH)/ \
-    $(LOCAL_PATH)/../../common \
-    $(LOCAL_PATH)/../../common/include \
-
-include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/codecs/aacenc/SoftAACEncoder.cpp b/media/libstagefright/codecs/aacenc/SoftAACEncoder.cpp
index 96bbb85..e16ea33 100644
--- a/media/libstagefright/codecs/aacenc/SoftAACEncoder.cpp
+++ b/media/libstagefright/codecs/aacenc/SoftAACEncoder.cpp
@@ -65,7 +65,7 @@
     onReset();
 
     if (mEncoderHandle) {
-        CHECK_EQ(VO_ERR_NONE, mApiHandle->Uninit(mEncoderHandle));
+        CHECK_EQ((VO_U32)VO_ERR_NONE, mApiHandle->Uninit(mEncoderHandle));
         mEncoderHandle = NULL;
     }
 
@@ -337,7 +337,7 @@
     // We call this whenever sample rate, number of channels or bitrate change
     // in reponse to setParameter calls.
 
-    ALOGV("setAudioParams: %lu Hz, %lu channels, %lu bps",
+    ALOGV("setAudioParams: %u Hz, %u channels, %u bps",
          mSampleRate, mNumChannels, mBitRate);
 
     status_t err = setAudioSpecificConfigData();
@@ -387,12 +387,12 @@
     int32_t index;
     status_t err = getSampleRateTableIndex(mSampleRate, index);
     if (err != OK) {
-        ALOGE("Unsupported sample rate (%lu Hz)", mSampleRate);
+        ALOGE("Unsupported sample rate (%u Hz)", mSampleRate);
         return err;
     }
 
     if (mNumChannels > 2 || mNumChannels <= 0) {
-        ALOGE("Unsupported number of channels(%lu)", mNumChannels);
+        ALOGE("Unsupported number of channels(%u)", mNumChannels);
         return UNKNOWN_ERROR;
     }
 
@@ -403,7 +403,7 @@
     return OK;
 }
 
-void SoftAACEncoder::onQueueFilled(OMX_U32 portIndex) {
+void SoftAACEncoder::onQueueFilled(OMX_U32 /*portIndex*/) {
     if (mSignalledError) {
         return;
     }
@@ -524,7 +524,7 @@
         memset(&inputData, 0, sizeof(inputData));
         inputData.Buffer = (unsigned char *)mInputFrame;
         inputData.Length = numBytesPerInputFrame;
-        CHECK(VO_ERR_NONE ==
+        CHECK((VO_U32)VO_ERR_NONE ==
                 mApiHandle->SetInputData(mEncoderHandle, &inputData));
 
         VO_CODECBUFFER outputData;
diff --git a/media/libstagefright/codecs/aacenc/src/grp_data.c b/media/libstagefright/codecs/aacenc/src/grp_data.c
index 7861e1c..edfb95b 100644
--- a/media/libstagefright/codecs/aacenc/src/grp_data.c
+++ b/media/libstagefright/codecs/aacenc/src/grp_data.c
@@ -88,7 +88,6 @@
     offset += groupLen[grp] * FRAME_LEN_SHORT;
   }
   groupedSfbOffset[i] = FRAME_LEN_LONG;
-  i += 1;
 
   /* calculate minSnr */
   i = 0;
diff --git a/media/libstagefright/codecs/aacenc/src/ms_stereo.c b/media/libstagefright/codecs/aacenc/src/ms_stereo.c
index 1e4b227..ca028dc 100644
--- a/media/libstagefright/codecs/aacenc/src/ms_stereo.c
+++ b/media/libstagefright/codecs/aacenc/src/ms_stereo.c
@@ -94,8 +94,6 @@
 
       pnms = fixmul(nrgL, nrgR);
 
-      temp = (pnlr + 1) / ((pnms >> 8) + 1);
-
       temp = pnms - pnlr;
       if( temp > 0 ){
 
diff --git a/media/libstagefright/codecs/amrnb/Android.bp b/media/libstagefright/codecs/amrnb/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/media/libstagefright/codecs/amrnb/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/media/libstagefright/codecs/amrnb/Android.mk b/media/libstagefright/codecs/amrnb/Android.mk
deleted file mode 100644
index 2e43120..0000000
--- a/media/libstagefright/codecs/amrnb/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/codecs/amrnb/common/Android.bp b/media/libstagefright/codecs/amrnb/common/Android.bp
new file mode 100644
index 0000000..c5ac558
--- /dev/null
+++ b/media/libstagefright/codecs/amrnb/common/Android.bp
@@ -0,0 +1,82 @@
+cc_library_shared {
+    name: "libstagefright_amrnb_common",
+
+    srcs: [
+        "src/add.cpp",
+        "src/az_lsp.cpp",
+        "src/bitno_tab.cpp",
+        "src/bitreorder_tab.cpp",
+        "src/bits2prm.cpp",
+        "src/c2_9pf_tab.cpp",
+        "src/copy.cpp",
+        "src/div_32.cpp",
+        "src/div_s.cpp",
+        "src/extract_h.cpp",
+        "src/extract_l.cpp",
+        "src/gains_tbl.cpp",
+        "src/gc_pred.cpp",
+        "src/gmed_n.cpp",
+        "src/grid_tbl.cpp",
+        "src/gray_tbl.cpp",
+        "src/int_lpc.cpp",
+        "src/inv_sqrt.cpp",
+        "src/inv_sqrt_tbl.cpp",
+        "src/l_abs.cpp",
+        "src/l_deposit_h.cpp",
+        "src/l_deposit_l.cpp",
+        "src/l_shr_r.cpp",
+        "src/log2.cpp",
+        "src/log2_norm.cpp",
+        "src/log2_tbl.cpp",
+        "src/lsfwt.cpp",
+        "src/lsp.cpp",
+        "src/lsp_az.cpp",
+        "src/lsp_lsf.cpp",
+        "src/lsp_lsf_tbl.cpp",
+        "src/lsp_tab.cpp",
+        "src/mult_r.cpp",
+        "src/norm_l.cpp",
+        "src/norm_s.cpp",
+        "src/ph_disp_tab.cpp",
+        "src/pow2.cpp",
+        "src/pow2_tbl.cpp",
+        "src/pred_lt.cpp",
+        "src/q_plsf.cpp",
+        "src/q_plsf_3.cpp",
+        "src/q_plsf_3_tbl.cpp",
+        "src/q_plsf_5.cpp",
+        "src/q_plsf_5_tbl.cpp",
+        "src/qua_gain_tbl.cpp",
+        "src/reorder.cpp",
+        "src/residu.cpp",
+        "src/round.cpp",
+        "src/set_zero.cpp",
+        "src/shr.cpp",
+        "src/shr_r.cpp",
+        "src/sqrt_l.cpp",
+        "src/sqrt_l_tbl.cpp",
+        "src/sub.cpp",
+        "src/syn_filt.cpp",
+        "src/vad1.cpp",
+        "src/weight_a.cpp",
+        "src/window_tab.cpp",
+    ],
+
+    export_include_dirs: ["include"],
+
+    cflags: [
+        "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+        "-DOSCL_IMPORT_REF=",
+        "-DOSCL_EXPORT_REF=",
+
+        "-Werror",
+    ],
+
+    //addressing b/25409744
+    //sanitize: {
+    //    misc_undefined: [
+    //        "signed-integer-overflow",
+    //        "unsigned-integer-overflow",
+    //    ],
+    //},
+}
diff --git a/media/libstagefright/codecs/amrnb/common/Android.mk b/media/libstagefright/codecs/amrnb/common/Android.mk
deleted file mode 100644
index 0bb5724..0000000
--- a/media/libstagefright/codecs/amrnb/common/Android.mk
+++ /dev/null
@@ -1,76 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	src/add.cpp \
- 	src/az_lsp.cpp \
- 	src/bitno_tab.cpp \
- 	src/bitreorder_tab.cpp \
- 	src/bits2prm.cpp \
- 	src/c2_9pf_tab.cpp \
- 	src/copy.cpp \
- 	src/div_32.cpp \
- 	src/div_s.cpp \
- 	src/extract_h.cpp \
- 	src/extract_l.cpp \
- 	src/gains_tbl.cpp \
- 	src/gc_pred.cpp \
- 	src/gmed_n.cpp \
- 	src/grid_tbl.cpp \
- 	src/gray_tbl.cpp \
- 	src/int_lpc.cpp \
- 	src/inv_sqrt.cpp \
- 	src/inv_sqrt_tbl.cpp \
- 	src/l_abs.cpp \
- 	src/l_deposit_h.cpp \
- 	src/l_deposit_l.cpp \
- 	src/l_shr_r.cpp \
- 	src/log2.cpp \
- 	src/log2_norm.cpp \
- 	src/log2_tbl.cpp \
- 	src/lsfwt.cpp \
- 	src/lsp.cpp \
- 	src/lsp_az.cpp \
- 	src/lsp_lsf.cpp \
- 	src/lsp_lsf_tbl.cpp \
- 	src/lsp_tab.cpp \
- 	src/mult_r.cpp \
- 	src/norm_l.cpp \
- 	src/norm_s.cpp \
- 	src/ph_disp_tab.cpp \
- 	src/pow2.cpp \
- 	src/pow2_tbl.cpp \
- 	src/pred_lt.cpp \
- 	src/q_plsf.cpp \
- 	src/q_plsf_3.cpp \
- 	src/q_plsf_3_tbl.cpp \
- 	src/q_plsf_5.cpp \
- 	src/q_plsf_5_tbl.cpp \
- 	src/qua_gain_tbl.cpp \
- 	src/reorder.cpp \
- 	src/residu.cpp \
- 	src/round.cpp \
- 	src/set_zero.cpp \
- 	src/shr.cpp \
- 	src/shr_r.cpp \
- 	src/sqrt_l.cpp \
- 	src/sqrt_l_tbl.cpp \
- 	src/sub.cpp \
- 	src/syn_filt.cpp \
- 	src/vad1.cpp \
- 	src/weight_a.cpp \
- 	src/window_tab.cpp
-
-LOCAL_C_INCLUDES := \
-        $(LOCAL_PATH)/include
-
-LOCAL_CFLAGS := \
-        -D"OSCL_UNUSED_ARG(x)=(void)(x)" -DOSCL_IMPORT_REF= -DOSCL_EXPORT_REF=
-
-LOCAL_CFLAGS += -Werror
-#addressing b/25409744
-#LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow
-
-LOCAL_MODULE := libstagefright_amrnb_common
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/amrnb/dec/Android.bp b/media/libstagefright/codecs/amrnb/dec/Android.bp
new file mode 100644
index 0000000..996183b
--- /dev/null
+++ b/media/libstagefright/codecs/amrnb/dec/Android.bp
@@ -0,0 +1,126 @@
+cc_library_static {
+    name: "libstagefright_amrnbdec",
+
+    srcs: [
+        "src/a_refl.cpp",
+        "src/agc.cpp",
+        "src/amrdecode.cpp",
+        "src/b_cn_cod.cpp",
+        "src/bgnscd.cpp",
+        "src/c_g_aver.cpp",
+        "src/d1035pf.cpp",
+        "src/d2_11pf.cpp",
+        "src/d2_9pf.cpp",
+        "src/d3_14pf.cpp",
+        "src/d4_17pf.cpp",
+        "src/d8_31pf.cpp",
+        "src/d_gain_c.cpp",
+        "src/d_gain_p.cpp",
+        "src/d_plsf.cpp",
+        "src/d_plsf_3.cpp",
+        "src/d_plsf_5.cpp",
+        "src/dec_amr.cpp",
+        "src/dec_gain.cpp",
+        "src/dec_input_format_tab.cpp",
+        "src/dec_lag3.cpp",
+        "src/dec_lag6.cpp",
+        "src/dtx_dec.cpp",
+        "src/ec_gains.cpp",
+        "src/ex_ctrl.cpp",
+        "src/if2_to_ets.cpp",
+        "src/int_lsf.cpp",
+        "src/lsp_avg.cpp",
+        "src/ph_disp.cpp",
+        "src/post_pro.cpp",
+        "src/preemph.cpp",
+        "src/pstfilt.cpp",
+        "src/qgain475_tab.cpp",
+        "src/sp_dec.cpp",
+        "src/wmf_to_ets.cpp",
+    ],
+
+    include_dirs: ["frameworks/av/media/libstagefright/include"],
+    local_include_dirs: ["src"],
+
+    cflags: [
+        "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+        "-DOSCL_IMPORT_REF=",
+
+        "-Werror",
+    ],
+
+    //sanitize: {
+    //    misc_undefined: [
+    //        "signed-integer-overflow",
+    //    ],
+    //},
+
+    shared_libs: ["libstagefright_amrnb_common"],
+}
+
+//###############################################################################
+
+cc_library_shared {
+    name: "libstagefright_soft_amrdec",
+
+    srcs: ["SoftAMR.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/av/media/libstagefright/codecs/amrwb/src",
+        "frameworks/native/include/media/openmax",
+    ],
+    local_include_dirs: ["src"],
+
+    cflags: [
+        "-DOSCL_IMPORT_REF=",
+        "-Werror",
+    ],
+
+    //sanitize: {
+    //    misc_undefined: [
+    //        "signed-integer-overflow",
+    //    ],
+    //},
+    //LOCAL_SANITIZE := signed-integer-overflow
+
+    static_libs: [
+        "libstagefright_amrnbdec",
+        "libstagefright_amrwbdec",
+    ],
+
+    shared_libs: [
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+        "libstagefright_amrnb_common",
+    ],
+}
+
+//###############################################################################
+cc_test {
+    name: "libstagefright_amrnbdec_test",
+    gtest: false,
+
+    srcs: ["test/amrnbdec_test.cpp"],
+
+    local_include_dirs: ["src"],
+
+    static_libs: [
+        "libstagefright_amrnbdec",
+        "libsndfile",
+    ],
+
+    shared_libs: [
+        "libstagefright_amrnb_common",
+        "libaudioutils",
+        "liblog",
+    ],
+
+    //sanitize: {
+    //    misc_undefined: [
+    //        "signed-integer-overflow",
+    //    ],
+    //},
+}
diff --git a/media/libstagefright/codecs/amrnb/dec/Android.mk b/media/libstagefright/codecs/amrnb/dec/Android.mk
deleted file mode 100644
index 3959b80..0000000
--- a/media/libstagefright/codecs/amrnb/dec/Android.mk
+++ /dev/null
@@ -1,110 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
- 	src/a_refl.cpp \
- 	src/agc.cpp \
- 	src/amrdecode.cpp \
- 	src/b_cn_cod.cpp \
- 	src/bgnscd.cpp \
- 	src/c_g_aver.cpp \
- 	src/d1035pf.cpp \
- 	src/d2_11pf.cpp \
- 	src/d2_9pf.cpp \
- 	src/d3_14pf.cpp \
- 	src/d4_17pf.cpp \
- 	src/d8_31pf.cpp \
- 	src/d_gain_c.cpp \
- 	src/d_gain_p.cpp \
- 	src/d_plsf.cpp \
- 	src/d_plsf_3.cpp \
- 	src/d_plsf_5.cpp \
- 	src/dec_amr.cpp \
- 	src/dec_gain.cpp \
- 	src/dec_input_format_tab.cpp \
- 	src/dec_lag3.cpp \
- 	src/dec_lag6.cpp \
- 	src/dtx_dec.cpp \
- 	src/ec_gains.cpp \
- 	src/ex_ctrl.cpp \
- 	src/if2_to_ets.cpp \
- 	src/int_lsf.cpp \
- 	src/lsp_avg.cpp \
- 	src/ph_disp.cpp \
- 	src/post_pro.cpp \
- 	src/preemph.cpp \
- 	src/pstfilt.cpp \
- 	src/qgain475_tab.cpp \
- 	src/sp_dec.cpp \
- 	src/wmf_to_ets.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include \
-        $(LOCAL_PATH)/../common/include
-
-LOCAL_CFLAGS := \
-        -D"OSCL_UNUSED_ARG(x)=(void)(x)" -DOSCL_IMPORT_REF=
-
-LOCAL_CFLAGS += -Werror
-#LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_MODULE := libstagefright_amrnbdec
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftAMR.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        frameworks/av/media/libstagefright/codecs/amrwb/src \
-        frameworks/native/include/media/openmax \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include \
-        $(LOCAL_PATH)/../common/include \
-
-LOCAL_CFLAGS := -DOSCL_IMPORT_REF=
-
-LOCAL_CFLAGS += -Werror
-#LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_amrnbdec libstagefright_amrwbdec
-
-LOCAL_SHARED_LIBRARIES := \
-        libstagefright_omx libstagefright_foundation libutils liblog \
-        libstagefright_amrnb_common
-
-LOCAL_MODULE := libstagefright_soft_amrdec
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-################################################################################
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
-        test/amrnbdec_test.cpp
-
-LOCAL_C_INCLUDES := \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/../common/include \
-        $(call include-path-for, audio-utils)
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_amrnbdec libsndfile
-
-LOCAL_SHARED_LIBRARIES := \
-        libstagefright_amrnb_common libaudioutils liblog
-
-#LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_MODULE := libstagefright_amrnbdec_test
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/codecs/amrnb/enc/Android.bp b/media/libstagefright/codecs/amrnb/enc/Android.bp
new file mode 100644
index 0000000..af0f8c2
--- /dev/null
+++ b/media/libstagefright/codecs/amrnb/enc/Android.bp
@@ -0,0 +1,135 @@
+cc_library_static {
+    name: "libstagefright_amrnbenc",
+
+    srcs: [
+        "src/amrencode.cpp",
+        "src/autocorr.cpp",
+        "src/c1035pf.cpp",
+        "src/c2_11pf.cpp",
+        "src/c2_9pf.cpp",
+        "src/c3_14pf.cpp",
+        "src/c4_17pf.cpp",
+        "src/c8_31pf.cpp",
+        "src/calc_cor.cpp",
+        "src/calc_en.cpp",
+        "src/cbsearch.cpp",
+        "src/cl_ltp.cpp",
+        "src/cod_amr.cpp",
+        "src/convolve.cpp",
+        "src/cor_h.cpp",
+        "src/cor_h_x.cpp",
+        "src/cor_h_x2.cpp",
+        "src/corrwght_tab.cpp",
+        "src/dtx_enc.cpp",
+        "src/enc_lag3.cpp",
+        "src/enc_lag6.cpp",
+        "src/enc_output_format_tab.cpp",
+        "src/ets_to_if2.cpp",
+        "src/ets_to_wmf.cpp",
+        "src/g_adapt.cpp",
+        "src/g_code.cpp",
+        "src/g_pitch.cpp",
+        "src/gain_q.cpp",
+        "src/hp_max.cpp",
+        "src/inter_36.cpp",
+        "src/inter_36_tab.cpp",
+        "src/l_comp.cpp",
+        "src/l_extract.cpp",
+        "src/l_negate.cpp",
+        "src/lag_wind.cpp",
+        "src/lag_wind_tab.cpp",
+        "src/levinson.cpp",
+        "src/lpc.cpp",
+        "src/ol_ltp.cpp",
+        "src/p_ol_wgh.cpp",
+        "src/pitch_fr.cpp",
+        "src/pitch_ol.cpp",
+        "src/pre_big.cpp",
+        "src/pre_proc.cpp",
+        "src/prm2bits.cpp",
+        "src/q_gain_c.cpp",
+        "src/q_gain_p.cpp",
+        "src/qgain475.cpp",
+        "src/qgain795.cpp",
+        "src/qua_gain.cpp",
+        "src/s10_8pf.cpp",
+        "src/set_sign.cpp",
+        "src/sid_sync.cpp",
+        "src/sp_enc.cpp",
+        "src/spreproc.cpp",
+        "src/spstproc.cpp",
+        "src/ton_stab.cpp",
+    ],
+
+    include_dirs: ["frameworks/av/media/libstagefright/include"],
+    local_include_dirs: ["src"],
+
+    cflags: [
+        "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+        "-Werror",
+    ],
+
+    //addressing b/25409744
+    //sanitize: {
+    //    misc_undefined: [
+    //        "signed-integer-overflow",
+    //    ],
+    //},
+
+    shared_libs: ["libstagefright_amrnb_common"],
+}
+
+//###############################################################################
+
+cc_library_shared {
+    name: "libstagefright_soft_amrnbenc",
+
+    srcs: ["SoftAMRNBEncoder.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+    local_include_dirs: ["src"],
+
+    cflags: ["-Werror"],
+
+    //addressing b/25409744
+    //sanitize: {
+    //    misc_undefined: [
+    //        "signed-integer-overflow",
+    //    ],
+    //},
+
+    static_libs: ["libstagefright_amrnbenc"],
+
+    shared_libs: [
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+        "libstagefright_amrnb_common",
+    ],
+}
+
+//###############################################################################
+
+cc_test {
+    name: "libstagefright_amrnbenc_test",
+    gtest: false,
+
+    srcs: ["test/amrnb_enc_test.cpp"],
+
+    local_include_dirs: ["src"],
+
+    static_libs: ["libstagefright_amrnbenc"],
+
+    shared_libs: ["libstagefright_amrnb_common"],
+
+    //addressing b/25409744
+    //sanitize: {
+    //    misc_undefined: [
+    //        "signed-integer-overflow",
+    //    ],
+    //},
+}
diff --git a/media/libstagefright/codecs/amrnb/enc/Android.mk b/media/libstagefright/codecs/amrnb/enc/Android.mk
deleted file mode 100644
index af1efb9..0000000
--- a/media/libstagefright/codecs/amrnb/enc/Android.mk
+++ /dev/null
@@ -1,134 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	src/amrencode.cpp \
- 	src/autocorr.cpp \
- 	src/c1035pf.cpp \
- 	src/c2_11pf.cpp \
- 	src/c2_9pf.cpp \
- 	src/c3_14pf.cpp \
- 	src/c4_17pf.cpp \
- 	src/c8_31pf.cpp \
- 	src/calc_cor.cpp \
- 	src/calc_en.cpp \
- 	src/cbsearch.cpp \
- 	src/cl_ltp.cpp \
- 	src/cod_amr.cpp \
- 	src/convolve.cpp \
- 	src/cor_h.cpp \
- 	src/cor_h_x.cpp \
- 	src/cor_h_x2.cpp \
- 	src/corrwght_tab.cpp \
- 	src/dtx_enc.cpp \
- 	src/enc_lag3.cpp \
- 	src/enc_lag6.cpp \
- 	src/enc_output_format_tab.cpp \
- 	src/ets_to_if2.cpp \
- 	src/ets_to_wmf.cpp \
- 	src/g_adapt.cpp \
- 	src/g_code.cpp \
- 	src/g_pitch.cpp \
- 	src/gain_q.cpp \
- 	src/hp_max.cpp \
- 	src/inter_36.cpp \
- 	src/inter_36_tab.cpp \
- 	src/l_comp.cpp \
- 	src/l_extract.cpp \
- 	src/l_negate.cpp \
- 	src/lag_wind.cpp \
- 	src/lag_wind_tab.cpp \
- 	src/levinson.cpp \
- 	src/lpc.cpp \
- 	src/ol_ltp.cpp \
- 	src/p_ol_wgh.cpp \
- 	src/pitch_fr.cpp \
- 	src/pitch_ol.cpp \
- 	src/pre_big.cpp \
- 	src/pre_proc.cpp \
- 	src/prm2bits.cpp \
- 	src/q_gain_c.cpp \
- 	src/q_gain_p.cpp \
- 	src/qgain475.cpp \
- 	src/qgain795.cpp \
- 	src/qua_gain.cpp \
- 	src/s10_8pf.cpp \
- 	src/set_sign.cpp \
- 	src/sid_sync.cpp \
- 	src/sp_enc.cpp \
- 	src/spreproc.cpp \
- 	src/spstproc.cpp \
- 	src/ton_stab.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include \
-        $(LOCAL_PATH)/../common/include
-
-LOCAL_CFLAGS := \
-        -D"OSCL_UNUSED_ARG(x)=(void)(x)"
-
-LOCAL_CFLAGS += -Werror
-#addressing b/25409744
-#LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_MODULE := libstagefright_amrnbenc
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftAMRNBEncoder.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include \
-        $(LOCAL_PATH)/../common/include \
-        $(LOCAL_PATH)/../common
-
-LOCAL_CFLAGS += -Werror
-#addressing b/25409744
-#LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_amrnbenc
-
-LOCAL_SHARED_LIBRARIES := \
-        libstagefright_omx libstagefright_foundation libutils liblog \
-        libstagefright_amrnb_common
-
-LOCAL_MODULE := libstagefright_soft_amrnbenc
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
-    test/amrnb_enc_test.cpp
-
-LOCAL_C_INCLUDES := \
-    $(LOCAL_PATH)/src \
-    $(LOCAL_PATH)/../common/include
-
-
-LOCAL_STATIC_LIBRARIES := \
-    libstagefright_amrnbenc
-
-LOCAL_SHARED_LIBRARIES := \
-    libstagefright_amrnb_common
-
-#addressing b/25409744
-#LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_MODULE := libstagefright_amrnbenc_test
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/codecs/amrwb/Android.bp b/media/libstagefright/codecs/amrwb/Android.bp
new file mode 100644
index 0000000..e261c04
--- /dev/null
+++ b/media/libstagefright/codecs/amrwb/Android.bp
@@ -0,0 +1,85 @@
+cc_library_static {
+    name: "libstagefright_amrwbdec",
+
+    srcs: [
+        "src/agc2_amr_wb.cpp",
+        "src/band_pass_6k_7k.cpp",
+        "src/dec_acelp_2p_in_64.cpp",
+        "src/dec_acelp_4p_in_64.cpp",
+        "src/dec_alg_codebook.cpp",
+        "src/dec_gain2_amr_wb.cpp",
+        "src/deemphasis_32.cpp",
+        "src/dtx_decoder_amr_wb.cpp",
+        "src/get_amr_wb_bits.cpp",
+        "src/highpass_400hz_at_12k8.cpp",
+        "src/highpass_50hz_at_12k8.cpp",
+        "src/homing_amr_wb_dec.cpp",
+        "src/interpolate_isp.cpp",
+        "src/isf_extrapolation.cpp",
+        "src/isp_az.cpp",
+        "src/isp_isf.cpp",
+        "src/lagconceal.cpp",
+        "src/low_pass_filt_7k.cpp",
+        "src/median5.cpp",
+        "src/mime_io.cpp",
+        "src/noise_gen_amrwb.cpp",
+        "src/normalize_amr_wb.cpp",
+        "src/oversamp_12k8_to_16k.cpp",
+        "src/phase_dispersion.cpp",
+        "src/pit_shrp.cpp",
+        "src/pred_lt4.cpp",
+        "src/preemph_amrwb_dec.cpp",
+        "src/pvamrwb_math_op.cpp",
+        "src/pvamrwbdecoder.cpp",
+        "src/q_gain2_tab.cpp",
+        "src/qisf_ns.cpp",
+        "src/qisf_ns_tab.cpp",
+        "src/qpisf_2s.cpp",
+        "src/qpisf_2s_tab.cpp",
+        "src/scale_signal.cpp",
+        "src/synthesis_amr_wb.cpp",
+        "src/voice_factor.cpp",
+        "src/wb_syn_filt.cpp",
+        "src/weight_amrwb_lpc.cpp",
+    ],
+
+    include_dirs: ["frameworks/av/media/libstagefright/include"],
+    local_include_dirs: ["src"],
+    export_include_dirs: ["include"],
+
+    cflags: [
+        "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+        "-DOSCL_IMPORT_REF=",
+
+        "-Werror",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+    },
+}
+
+//###############################################################################
+cc_test {
+    name: "libstagefright_amrwbdec_test",
+    gtest: false,
+
+    srcs: ["test/amrwbdec_test.cpp"],
+
+    static_libs: [
+        "libstagefright_amrwbdec",
+        "libsndfile",
+    ],
+
+    local_include_dirs: ["src"],
+
+    shared_libs: ["libaudioutils"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+    },
+}
diff --git a/media/libstagefright/codecs/amrwb/Android.mk b/media/libstagefright/codecs/amrwb/Android.mk
deleted file mode 100644
index 73a1751..0000000
--- a/media/libstagefright/codecs/amrwb/Android.mk
+++ /dev/null
@@ -1,81 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	src/agc2_amr_wb.cpp \
- 	src/band_pass_6k_7k.cpp \
- 	src/dec_acelp_2p_in_64.cpp \
- 	src/dec_acelp_4p_in_64.cpp \
- 	src/dec_alg_codebook.cpp \
- 	src/dec_gain2_amr_wb.cpp \
- 	src/deemphasis_32.cpp \
- 	src/dtx_decoder_amr_wb.cpp \
- 	src/get_amr_wb_bits.cpp \
- 	src/highpass_400hz_at_12k8.cpp \
- 	src/highpass_50hz_at_12k8.cpp \
- 	src/homing_amr_wb_dec.cpp \
- 	src/interpolate_isp.cpp \
- 	src/isf_extrapolation.cpp \
- 	src/isp_az.cpp \
- 	src/isp_isf.cpp \
- 	src/lagconceal.cpp \
- 	src/low_pass_filt_7k.cpp \
- 	src/median5.cpp \
- 	src/mime_io.cpp \
- 	src/noise_gen_amrwb.cpp \
- 	src/normalize_amr_wb.cpp \
- 	src/oversamp_12k8_to_16k.cpp \
- 	src/phase_dispersion.cpp \
- 	src/pit_shrp.cpp \
- 	src/pred_lt4.cpp \
- 	src/preemph_amrwb_dec.cpp \
- 	src/pvamrwb_math_op.cpp \
- 	src/pvamrwbdecoder.cpp \
- 	src/q_gain2_tab.cpp \
- 	src/qisf_ns.cpp \
- 	src/qisf_ns_tab.cpp \
- 	src/qpisf_2s.cpp \
- 	src/qpisf_2s_tab.cpp \
- 	src/scale_signal.cpp \
- 	src/synthesis_amr_wb.cpp \
- 	src/voice_factor.cpp \
- 	src/wb_syn_filt.cpp \
- 	src/weight_amrwb_lpc.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include
-
-LOCAL_CFLAGS := \
-        -D"OSCL_UNUSED_ARG(x)=(void)(x)" -DOSCL_IMPORT_REF=
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_MODULE := libstagefright_amrwbdec
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
-        test/amrwbdec_test.cpp
-
-LOCAL_C_INCLUDES := \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include \
-        $(call include-path-for, audio-utils)
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_amrwbdec libsndfile
-
-LOCAL_SHARED_LIBRARIES := \
-        libaudioutils
-
-LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_MODULE := libstagefright_amrwbdec_test
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/codecs/amrwbenc/Android.bp b/media/libstagefright/codecs/amrwbenc/Android.bp
new file mode 100644
index 0000000..5c5a122
--- /dev/null
+++ b/media/libstagefright/codecs/amrwbenc/Android.bp
@@ -0,0 +1,180 @@
+cc_library_static {
+    name: "libstagefright_amrwbenc",
+
+    srcs: [
+        "src/autocorr.c",
+        "src/az_isp.c",
+        "src/bits.c",
+        "src/c2t64fx.c",
+        "src/c4t64fx.c",
+        "src/convolve.c",
+        "src/cor_h_x.c",
+        "src/decim54.c",
+        "src/deemph.c",
+        "src/dtx.c",
+        "src/g_pitch.c",
+        "src/gpclip.c",
+        "src/homing.c",
+        "src/hp400.c",
+        "src/hp50.c",
+        "src/hp6k.c",
+        "src/hp_wsp.c",
+        "src/int_lpc.c",
+        "src/isp_az.c",
+        "src/isp_isf.c",
+        "src/lag_wind.c",
+        "src/levinson.c",
+        "src/log2.c",
+        "src/lp_dec2.c",
+        "src/math_op.c",
+        "src/oper_32b.c",
+        "src/p_med_ol.c",
+        "src/pit_shrp.c",
+        "src/pitch_f4.c",
+        "src/pred_lt4.c",
+        "src/preemph.c",
+        "src/q_gain2.c",
+        "src/q_pulse.c",
+        "src/qisf_ns.c",
+        "src/qpisf_2s.c",
+        "src/random.c",
+        "src/residu.c",
+        "src/scale.c",
+        "src/stream.c",
+        "src/syn_filt.c",
+        "src/updt_tar.c",
+        "src/util.c",
+        "src/voAMRWBEnc.c",
+        "src/voicefac.c",
+        "src/wb_vad.c",
+        "src/weight_a.c",
+        "src/mem_align.c",
+    ],
+
+    arch: {
+        arm: {
+            srcs: [
+                "src/asm/ARMV5E/convolve_opt.s",
+                "src/asm/ARMV5E/cor_h_vec_opt.s",
+                "src/asm/ARMV5E/Deemph_32_opt.s",
+                "src/asm/ARMV5E/Dot_p_opt.s",
+                "src/asm/ARMV5E/Filt_6k_7k_opt.s",
+                "src/asm/ARMV5E/Norm_Corr_opt.s",
+                "src/asm/ARMV5E/pred_lt4_1_opt.s",
+                "src/asm/ARMV5E/residu_asm_opt.s",
+                "src/asm/ARMV5E/scale_sig_opt.s",
+                "src/asm/ARMV5E/Syn_filt_32_opt.s",
+                "src/asm/ARMV5E/syn_filt_opt.s",
+            ],
+
+            cflags: [
+                "-DARM",
+                "-DASM_OPT",
+            ],
+            local_include_dirs: ["src/asm/ARMV5E"],
+
+            instruction_set: "arm",
+
+            armv7_a_neon: {
+                exclude_srcs: [
+                    "src/asm/ARMV5E/convolve_opt.s",
+                    "src/asm/ARMV5E/cor_h_vec_opt.s",
+                    "src/asm/ARMV5E/Deemph_32_opt.s",
+                    "src/asm/ARMV5E/Dot_p_opt.s",
+                    "src/asm/ARMV5E/Filt_6k_7k_opt.s",
+                    "src/asm/ARMV5E/Norm_Corr_opt.s",
+                    "src/asm/ARMV5E/pred_lt4_1_opt.s",
+                    "src/asm/ARMV5E/residu_asm_opt.s",
+                    "src/asm/ARMV5E/scale_sig_opt.s",
+                    "src/asm/ARMV5E/Syn_filt_32_opt.s",
+                    "src/asm/ARMV5E/syn_filt_opt.s",
+                ],
+
+                srcs: [
+                    "src/asm/ARMV7/convolve_neon.s",
+                    "src/asm/ARMV7/cor_h_vec_neon.s",
+                    "src/asm/ARMV7/Deemph_32_neon.s",
+                    "src/asm/ARMV7/Dot_p_neon.s",
+                    "src/asm/ARMV7/Filt_6k_7k_neon.s",
+                    "src/asm/ARMV7/Norm_Corr_neon.s",
+                    "src/asm/ARMV7/pred_lt4_1_neon.s",
+                    "src/asm/ARMV7/residu_asm_neon.s",
+                    "src/asm/ARMV7/scale_sig_neon.s",
+                    "src/asm/ARMV7/Syn_filt_32_neon.s",
+                    "src/asm/ARMV7/syn_filt_neon.s",
+                ],
+
+                // don't actually generate neon instructions, see bug 26932980
+                cflags: [
+                    "-DARMV7",
+                    "-mfpu=vfpv3",
+                ],
+                local_include_dirs: [
+                    "src/asm/ARMV5E",
+                    "src/asm/ARMV7",
+                ],
+            },
+
+        },
+    },
+
+    include_dirs: [
+        "frameworks/av/include",
+        "frameworks/av/media/libstagefright/include",
+    ],
+
+    local_include_dirs: ["src"],
+    export_include_dirs: ["inc"],
+
+    shared_libs: [
+        "libstagefright_enc_common",
+    ],
+
+    cflags: ["-Werror"],
+    sanitize: {
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+}
+
+//###############################################################################
+
+cc_library_shared {
+    name: "libstagefright_soft_amrwbenc",
+
+    srcs: ["SoftAMRWBEncoder.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    static_libs: ["libstagefright_amrwbenc"],
+
+    shared_libs: [
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+        "libstagefright_enc_common",
+    ],
+}
+
+//###############################################################################
+
+subdirs = ["SampleCode"]
diff --git a/media/libstagefright/codecs/amrwbenc/Android.mk b/media/libstagefright/codecs/amrwbenc/Android.mk
deleted file mode 100644
index 262f6c8..0000000
--- a/media/libstagefright/codecs/amrwbenc/Android.mk
+++ /dev/null
@@ -1,138 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	src/autocorr.c \
-	src/az_isp.c \
-	src/bits.c \
-	src/c2t64fx.c \
-	src/c4t64fx.c \
-	src/convolve.c \
-	src/cor_h_x.c \
-	src/decim54.c \
-	src/deemph.c \
-	src/dtx.c \
-	src/g_pitch.c \
-	src/gpclip.c \
-	src/homing.c \
-	src/hp400.c \
-	src/hp50.c \
-	src/hp6k.c \
-	src/hp_wsp.c \
-	src/int_lpc.c \
-	src/isp_az.c \
-	src/isp_isf.c \
-	src/lag_wind.c \
-	src/levinson.c \
-	src/log2.c \
-	src/lp_dec2.c \
-	src/math_op.c \
-	src/oper_32b.c \
-	src/p_med_ol.c \
-	src/pit_shrp.c \
-	src/pitch_f4.c \
-	src/pred_lt4.c \
-	src/preemph.c \
-	src/q_gain2.c \
-	src/q_pulse.c \
-	src/qisf_ns.c \
-	src/qpisf_2s.c \
-	src/random.c \
-	src/residu.c \
-	src/scale.c \
-	src/stream.c \
-	src/syn_filt.c \
-	src/updt_tar.c \
-	src/util.c \
-	src/voAMRWBEnc.c \
-	src/voicefac.c \
-	src/wb_vad.c \
-	src/weight_a.c \
-	src/mem_align.c
-
-ifneq ($(ARCH_ARM_HAVE_NEON),true)
-    LOCAL_SRC_FILES_arm := \
-        src/asm/ARMV5E/convolve_opt.s \
-        src/asm/ARMV5E/cor_h_vec_opt.s \
-        src/asm/ARMV5E/Deemph_32_opt.s \
-        src/asm/ARMV5E/Dot_p_opt.s \
-        src/asm/ARMV5E/Filt_6k_7k_opt.s \
-        src/asm/ARMV5E/Norm_Corr_opt.s \
-        src/asm/ARMV5E/pred_lt4_1_opt.s \
-        src/asm/ARMV5E/residu_asm_opt.s \
-        src/asm/ARMV5E/scale_sig_opt.s \
-        src/asm/ARMV5E/Syn_filt_32_opt.s \
-        src/asm/ARMV5E/syn_filt_opt.s
-
-    LOCAL_CFLAGS_arm := -DARM -DASM_OPT
-    LOCAL_C_INCLUDES_arm = $(LOCAL_PATH)/src/asm/ARMV5E
-else
-    LOCAL_SRC_FILES_arm := \
-        src/asm/ARMV7/convolve_neon.s \
-        src/asm/ARMV7/cor_h_vec_neon.s \
-        src/asm/ARMV7/Deemph_32_neon.s \
-        src/asm/ARMV7/Dot_p_neon.s \
-        src/asm/ARMV7/Filt_6k_7k_neon.s \
-        src/asm/ARMV7/Norm_Corr_neon.s \
-        src/asm/ARMV7/pred_lt4_1_neon.s \
-        src/asm/ARMV7/residu_asm_neon.s \
-        src/asm/ARMV7/scale_sig_neon.s \
-        src/asm/ARMV7/Syn_filt_32_neon.s \
-        src/asm/ARMV7/syn_filt_neon.s
-
-    # don't actually generate neon instructions, see bug 26932980
-    LOCAL_CFLAGS_arm := -DARM -DARMV7 -DASM_OPT -mfpu=vfpv3
-    LOCAL_C_INCLUDES_arm := $(LOCAL_PATH)/src/asm/ARMV5E
-    LOCAL_C_INCLUDES_arm += $(LOCAL_PATH)/src/asm/ARMV7
-endif
-
-LOCAL_MODULE := libstagefright_amrwbenc
-
-LOCAL_ARM_MODE := arm
-
-LOCAL_STATIC_LIBRARIES :=
-
-LOCAL_SHARED_LIBRARIES :=
-
-LOCAL_C_INCLUDES := \
-	frameworks/av/include \
-	frameworks/av/media/libstagefright/include \
-	frameworks/av/media/libstagefright/codecs/common/include \
-	$(LOCAL_PATH)/src \
-	$(LOCAL_PATH)/inc
-
-LOCAL_CFLAGS += -Werror
-#LOCAL_SANITIZE := signed-integer-overflow
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftAMRWBEncoder.cpp
-
-LOCAL_C_INCLUDES := \
-	frameworks/av/media/libstagefright/include \
-	frameworks/av/media/libstagefright/codecs/common/include \
-	frameworks/native/include/media/openmax
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_amrwbenc
-
-LOCAL_SHARED_LIBRARIES := \
-        libstagefright_omx libstagefright_foundation libutils liblog \
-        libstagefright_enc_common
-
-LOCAL_MODULE := libstagefright_soft_amrwbenc
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-################################################################################
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/codecs/amrwbenc/SampleCode/Android.bp b/media/libstagefright/codecs/amrwbenc/SampleCode/Android.bp
new file mode 100644
index 0000000..d52fed3
--- /dev/null
+++ b/media/libstagefright/codecs/amrwbenc/SampleCode/Android.bp
@@ -0,0 +1,28 @@
+cc_test {
+    name: "AMRWBEncTest",
+    gtest: false,
+
+    srcs: ["AMRWB_E_SAMPLE.c"],
+
+    arch: {
+        arm: {
+            instruction_set: "arm",
+        },
+    },
+
+    shared_libs: [
+        "libdl",
+    ],
+
+    static_libs: [
+        "libstagefright_amrwbenc",
+        "libstagefright_enc_common",
+    ],
+
+    sanitize: {
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk b/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk
deleted file mode 100644
index 65d69a2..0000000
--- a/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk
+++ /dev/null
@@ -1,30 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    AMRWB_E_SAMPLE.c \
-    ../../common/cmnMemory.c
-
-LOCAL_MODULE_TAGS := tests
-LOCAL_MODULE := AMRWBEncTest
-
-LOCAL_ARM_MODE := arm
-
-LOCAL_CFLAGS :=
-
-LOCAL_SHARED_LIBRARIES := \
-    libstagefright \
-    libdl
-
-LOCAL_STATIC_LIBRARIES := \
-    libstagefright_amrwbenc
-
-LOCAL_C_INCLUDES := \
-    $(LOCAL_PATH)/ \
-    $(LOCAL_PATH)/../../common \
-    $(LOCAL_PATH)/../../common/include
-
-include $(BUILD_EXECUTABLE)
-
-
-
diff --git a/media/libstagefright/codecs/amrwbenc/SoftAMRWBEncoder.cpp b/media/libstagefright/codecs/amrwbenc/SoftAMRWBEncoder.cpp
index 9d50c4e..c7973d6 100644
--- a/media/libstagefright/codecs/amrwbenc/SoftAMRWBEncoder.cpp
+++ b/media/libstagefright/codecs/amrwbenc/SoftAMRWBEncoder.cpp
@@ -59,7 +59,7 @@
 
 SoftAMRWBEncoder::~SoftAMRWBEncoder() {
     if (mEncoderHandle != NULL) {
-        CHECK_EQ(VO_ERR_NONE, mApiHandle->Uninit(mEncoderHandle));
+        CHECK_EQ((VO_U32)VO_ERR_NONE, mApiHandle->Uninit(mEncoderHandle));
         mEncoderHandle = NULL;
     }
 
@@ -435,7 +435,7 @@
         inputData.Buffer = (unsigned char *) mInputFrame;
         inputData.Length = mInputSize;
 
-        CHECK_EQ(VO_ERR_NONE,
+        CHECK_EQ((VO_U32)VO_ERR_NONE,
                  mApiHandle->SetInputData(mEncoderHandle, &inputData));
 
         VO_CODECBUFFER outputData;
diff --git a/media/libstagefright/codecs/avcdec/Android.bp b/media/libstagefright/codecs/avcdec/Android.bp
new file mode 100644
index 0000000..6b996a7
--- /dev/null
+++ b/media/libstagefright/codecs/avcdec/Android.bp
@@ -0,0 +1,33 @@
+cc_library_shared {
+    name: "libstagefright_soft_avcdec",
+
+    static_libs: ["libavcdec"],
+    srcs: ["SoftAVCDec.cpp"],
+
+    include_dirs: [
+        "external/libavc/decoder",
+        "external/libavc/common",
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    ldflags: ["-Wl,-Bsymbolic"],
+}
diff --git a/media/libstagefright/codecs/avcdec/Android.mk b/media/libstagefright/codecs/avcdec/Android.mk
deleted file mode 100644
index 8c894fd..0000000
--- a/media/libstagefright/codecs/avcdec/Android.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifeq ($(if $(wildcard external/libh264),1,0),1)
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE            := libstagefright_soft_avcdec
-LOCAL_MODULE_TAGS       := optional
-
-LOCAL_STATIC_LIBRARIES  := libavcdec
-LOCAL_SRC_FILES         := SoftAVCDec.cpp
-
-LOCAL_C_INCLUDES := $(TOP)/external/libavc/decoder
-LOCAL_C_INCLUDES += $(TOP)/external/libavc/common
-LOCAL_C_INCLUDES += $(TOP)/frameworks/av/media/libstagefright/include
-LOCAL_C_INCLUDES += $(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_SHARED_LIBRARIES  := libmedia
-LOCAL_SHARED_LIBRARIES  += libstagefright_omx
-LOCAL_SHARED_LIBRARIES  += libstagefright_foundation
-LOCAL_SHARED_LIBRARIES  += libutils
-LOCAL_SHARED_LIBRARIES  += liblog
-
-LOCAL_SANITIZE := signed-integer-overflow cfi
-
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_LDFLAGS := -Wl,-Bsymbolic
-
-include $(BUILD_SHARED_LIBRARY)
-
-#endif
diff --git a/media/libstagefright/codecs/avcenc/Android.bp b/media/libstagefright/codecs/avcenc/Android.bp
new file mode 100644
index 0000000..49021a9
--- /dev/null
+++ b/media/libstagefright/codecs/avcenc/Android.bp
@@ -0,0 +1,33 @@
+cc_library_shared {
+    name: "libstagefright_soft_avcenc",
+
+    static_libs: ["libavcenc"],
+    srcs: ["SoftAVCEnc.cpp"],
+
+    include_dirs: [
+        "external/libavc/encoder",
+        "external/libavc/common",
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/hardware",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libutils",
+        "liblog",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    ldflags: ["-Wl,-Bsymbolic"],
+}
diff --git a/media/libstagefright/codecs/avcenc/Android.mk b/media/libstagefright/codecs/avcenc/Android.mk
deleted file mode 100644
index 23ba208..0000000
--- a/media/libstagefright/codecs/avcenc/Android.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifeq ($(if $(wildcard external/libh264),1,0),1)
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE            := libstagefright_soft_avcenc
-LOCAL_MODULE_TAGS       := optional
-
-LOCAL_STATIC_LIBRARIES  := libavcenc
-LOCAL_SRC_FILES         := SoftAVCEnc.cpp
-
-LOCAL_C_INCLUDES := $(TOP)/external/libavc/encoder
-LOCAL_C_INCLUDES += $(TOP)/external/libavc/common
-LOCAL_C_INCLUDES += $(TOP)/frameworks/av/media/libstagefright/include
-LOCAL_C_INCLUDES += $(TOP)/frameworks/native/include/media/hardware
-LOCAL_C_INCLUDES += $(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_SHARED_LIBRARIES  := libmedia
-LOCAL_SHARED_LIBRARIES  += libstagefright_omx
-LOCAL_SHARED_LIBRARIES  += libutils
-LOCAL_SHARED_LIBRARIES  += liblog
-
-LOCAL_SANITIZE := signed-integer-overflow cfi
-
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_LDFLAGS := -Wl,-Bsymbolic
-
-include $(BUILD_SHARED_LIBRARY)
-
-#endif
diff --git a/media/libstagefright/codecs/common/Android.bp b/media/libstagefright/codecs/common/Android.bp
new file mode 100644
index 0000000..021e6af
--- /dev/null
+++ b/media/libstagefright/codecs/common/Android.bp
@@ -0,0 +1,15 @@
+cc_library {
+    name: "libstagefright_enc_common",
+
+    srcs: ["cmnMemory.c"],
+
+    arch: {
+        arm: {
+            instruction_set: "arm",
+        },
+    },
+
+    export_include_dirs: ["include"],
+
+    cflags: ["-Werror"],
+}
diff --git a/media/libstagefright/codecs/common/Android.mk b/media/libstagefright/codecs/common/Android.mk
deleted file mode 100644
index b0010ff..0000000
--- a/media/libstagefright/codecs/common/Android.mk
+++ /dev/null
@@ -1,22 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-
-
-LOCAL_SRC_FILES := cmnMemory.c
-
-LOCAL_MODULE := libstagefright_enc_common
-
-LOCAL_ARM_MODE := arm
-
-LOCAL_STATIC_LIBRARIES :=
-
-LOCAL_C_INCLUDES := \
-	$(LOCAL_PATH)/include
-
-LOCAL_CFLAGS += -Werror
-
-include $(BUILD_SHARED_LIBRARY)
-
-
-
diff --git a/media/libstagefright/codecs/flac/Android.bp b/media/libstagefright/codecs/flac/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/media/libstagefright/codecs/flac/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/media/libstagefright/codecs/flac/Android.mk b/media/libstagefright/codecs/flac/Android.mk
deleted file mode 100644
index 2e43120..0000000
--- a/media/libstagefright/codecs/flac/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/codecs/flac/enc/Android.bp b/media/libstagefright/codecs/flac/enc/Android.bp
new file mode 100644
index 0000000..d1413f6
--- /dev/null
+++ b/media/libstagefright/codecs/flac/enc/Android.bp
@@ -0,0 +1,36 @@
+cc_library_shared {
+
+    srcs: ["SoftFlacEncoder.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+        "external/flac/include",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+
+    static_libs: ["libFLAC"],
+
+    name: "libstagefright_soft_flacenc",
+
+}
diff --git a/media/libstagefright/codecs/flac/enc/Android.mk b/media/libstagefright/codecs/flac/enc/Android.mk
deleted file mode 100644
index 8031bf6..0000000
--- a/media/libstagefright/codecs/flac/enc/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftFlacEncoder.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax \
-        external/flac/include
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES := \
-        libmedia libstagefright_omx libstagefright_foundation libutils liblog
-
-LOCAL_STATIC_LIBRARIES := \
-        libFLAC \
-
-LOCAL_MODULE := libstagefright_soft_flacenc
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/flac/enc/SoftFlacEncoder.h b/media/libstagefright/codecs/flac/enc/SoftFlacEncoder.h
index 97361fa..6027f76 100644
--- a/media/libstagefright/codecs/flac/enc/SoftFlacEncoder.h
+++ b/media/libstagefright/codecs/flac/enc/SoftFlacEncoder.h
@@ -48,13 +48,10 @@
     virtual void onQueueFilled(OMX_U32 portIndex);
 
 private:
-
-    enum {
-        kNumBuffers = 2,
-        kMaxNumSamplesPerFrame = 1152,
-        kMaxInputBufferSize = kMaxNumSamplesPerFrame * sizeof(int16_t) * 2,
-        kMaxOutputBufferSize = 65536,    //TODO check if this can be reduced
-    };
+    const unsigned int kNumBuffers = 2;
+    const unsigned int kMaxNumSamplesPerFrame = 1152;
+    const unsigned int kMaxInputBufferSize = kMaxNumSamplesPerFrame * sizeof(int16_t) * 2;
+    const unsigned int kMaxOutputBufferSize = 65536;    //TODO check if this can be reduced
 
     bool mSignalledError;
 
diff --git a/media/libstagefright/codecs/g711/Android.bp b/media/libstagefright/codecs/g711/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/media/libstagefright/codecs/g711/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/media/libstagefright/codecs/g711/Android.mk b/media/libstagefright/codecs/g711/Android.mk
deleted file mode 100644
index 2e43120..0000000
--- a/media/libstagefright/codecs/g711/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/codecs/g711/dec/Android.bp b/media/libstagefright/codecs/g711/dec/Android.bp
new file mode 100644
index 0000000..b78b689
--- /dev/null
+++ b/media/libstagefright/codecs/g711/dec/Android.bp
@@ -0,0 +1,30 @@
+cc_library_shared {
+    name: "libstagefright_soft_g711dec",
+
+    srcs: ["SoftG711.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libutils",
+        "liblog",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/codecs/g711/dec/Android.mk b/media/libstagefright/codecs/g711/dec/Android.mk
deleted file mode 100644
index b9a1f8c..0000000
--- a/media/libstagefright/codecs/g711/dec/Android.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftG711.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax
-
-LOCAL_SHARED_LIBRARIES := \
-        libmedia libstagefright_omx libutils liblog
-
-LOCAL_MODULE := libstagefright_soft_g711dec
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/gsm/Android.bp b/media/libstagefright/codecs/gsm/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/media/libstagefright/codecs/gsm/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/media/libstagefright/codecs/gsm/Android.mk b/media/libstagefright/codecs/gsm/Android.mk
deleted file mode 100644
index 2e43120..0000000
--- a/media/libstagefright/codecs/gsm/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/codecs/gsm/dec/Android.bp b/media/libstagefright/codecs/gsm/dec/Android.bp
new file mode 100644
index 0000000..8e86ad6
--- /dev/null
+++ b/media/libstagefright/codecs/gsm/dec/Android.bp
@@ -0,0 +1,33 @@
+cc_library_shared {
+    name: "libstagefright_soft_gsmdec",
+
+    srcs: ["SoftGSM.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+        "external/libgsm/inc",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libutils",
+        "liblog",
+    ],
+
+    static_libs: ["libgsm"],
+}
diff --git a/media/libstagefright/codecs/gsm/dec/Android.mk b/media/libstagefright/codecs/gsm/dec/Android.mk
deleted file mode 100644
index 401b56c..0000000
--- a/media/libstagefright/codecs/gsm/dec/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftGSM.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax \
-        external/libgsm/inc
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES := \
-        libmedia libstagefright_omx libutils liblog
-
-LOCAL_STATIC_LIBRARIES := \
-        libgsm
-
-LOCAL_MODULE := libstagefright_soft_gsmdec
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/hevcdec/Android.bp b/media/libstagefright/codecs/hevcdec/Android.bp
new file mode 100644
index 0000000..cd75c97
--- /dev/null
+++ b/media/libstagefright/codecs/hevcdec/Android.bp
@@ -0,0 +1,36 @@
+cc_library_shared {
+    name: "libstagefright_soft_hevcdec",
+
+    static_libs: ["libhevcdec"],
+    srcs: ["SoftHEVC.cpp"],
+
+    include_dirs: [
+        "external/libhevc/decoder",
+        "external/libhevc/common",
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+
+    // We need this because the current asm generates the following link error:
+    // requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC
+    // Bug: 16853291
+    ldflags: ["-Wl,-Bsymbolic"],
+}
diff --git a/media/libstagefright/codecs/hevcdec/Android.mk b/media/libstagefright/codecs/hevcdec/Android.mk
deleted file mode 100644
index 11c1b89..0000000
--- a/media/libstagefright/codecs/hevcdec/Android.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-ifeq ($(if $(wildcard external/libhevc),1,0),1)
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE            := libstagefright_soft_hevcdec
-LOCAL_MODULE_TAGS       := optional
-
-LOCAL_STATIC_LIBRARIES  := libhevcdec
-LOCAL_SRC_FILES         := SoftHEVC.cpp
-
-LOCAL_C_INCLUDES := $(TOP)/external/libhevc/decoder
-LOCAL_C_INCLUDES += $(TOP)/external/libhevc/common
-LOCAL_C_INCLUDES += $(TOP)/frameworks/av/media/libstagefright/include
-LOCAL_C_INCLUDES += $(TOP)/frameworks/native/include/media/openmax
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES  := libmedia
-LOCAL_SHARED_LIBRARIES  += libstagefright_omx
-LOCAL_SHARED_LIBRARIES  += libstagefright_foundation
-LOCAL_SHARED_LIBRARIES  += libutils
-LOCAL_SHARED_LIBRARIES  += liblog
-
-# We need this because the current asm generates the following link error:
-# requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC
-# Bug: 16853291
-LOCAL_LDFLAGS := -Wl,-Bsymbolic
-
-include $(BUILD_SHARED_LIBRARY)
-
-endif
diff --git a/media/libstagefright/codecs/m4v_h263/Android.bp b/media/libstagefright/codecs/m4v_h263/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/media/libstagefright/codecs/m4v_h263/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/media/libstagefright/codecs/m4v_h263/Android.mk b/media/libstagefright/codecs/m4v_h263/Android.mk
deleted file mode 100644
index 2e43120..0000000
--- a/media/libstagefright/codecs/m4v_h263/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/codecs/m4v_h263/dec/Android.bp b/media/libstagefright/codecs/m4v_h263/dec/Android.bp
new file mode 100644
index 0000000..04ea075
--- /dev/null
+++ b/media/libstagefright/codecs/m4v_h263/dec/Android.bp
@@ -0,0 +1,106 @@
+cc_library_static {
+    name: "libstagefright_m4vh263dec",
+
+    srcs: [
+        "src/adaptive_smooth_no_mmx.cpp",
+        "src/bitstream.cpp",
+        "src/block_idct.cpp",
+        "src/cal_dc_scaler.cpp",
+        "src/chvr_filter.cpp",
+        "src/chv_filter.cpp",
+        "src/combined_decode.cpp",
+        "src/conceal.cpp",
+        "src/datapart_decode.cpp",
+        "src/dcac_prediction.cpp",
+        "src/dec_pred_intra_dc.cpp",
+        "src/deringing_chroma.cpp",
+        "src/deringing_luma.cpp",
+        "src/find_min_max.cpp",
+        "src/get_pred_adv_b_add.cpp",
+        "src/get_pred_outside.cpp",
+        "src/idct.cpp",
+        "src/idct_vca.cpp",
+        "src/mb_motion_comp.cpp",
+        "src/mb_utils.cpp",
+        "src/packet_util.cpp",
+        "src/post_filter.cpp",
+        "src/post_proc_semaphore.cpp",
+        "src/pp_semaphore_chroma_inter.cpp",
+        "src/pp_semaphore_luma.cpp",
+        "src/pvdec_api.cpp",
+        "src/scaling_tab.cpp",
+        "src/vlc_decode.cpp",
+        "src/vlc_dequant.cpp",
+        "src/vlc_tab.cpp",
+        "src/vop.cpp",
+        "src/zigzag_tab.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    local_include_dirs: ["src"],
+    export_include_dirs: ["include"],
+
+    cflags: [
+        "-DOSCL_EXPORT_REF=",
+        "-DOSCL_IMPORT_REF=",
+
+        "-Werror",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
+
+//###############################################################################
+
+cc_library_shared {
+    name: "libstagefright_soft_mpeg4dec",
+
+    srcs: ["SoftMPEG4.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    local_include_dirs: ["src"],
+    export_include_dirs: ["include"],
+
+    cflags: [
+        "-DOSCL_EXPORT_REF=",
+        "-DOSCL_IMPORT_REF=",
+
+        "-Werror",
+    ],
+
+    static_libs: ["libstagefright_m4vh263dec"],
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/codecs/m4v_h263/dec/Android.mk b/media/libstagefright/codecs/m4v_h263/dec/Android.mk
deleted file mode 100644
index c20dc4d..0000000
--- a/media/libstagefright/codecs/m4v_h263/dec/Android.mk
+++ /dev/null
@@ -1,82 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
- 	src/adaptive_smooth_no_mmx.cpp \
- 	src/bitstream.cpp \
- 	src/block_idct.cpp \
- 	src/cal_dc_scaler.cpp \
- 	src/chvr_filter.cpp \
- 	src/chv_filter.cpp \
- 	src/combined_decode.cpp \
- 	src/conceal.cpp \
- 	src/datapart_decode.cpp \
- 	src/dcac_prediction.cpp \
- 	src/dec_pred_intra_dc.cpp \
- 	src/deringing_chroma.cpp \
- 	src/deringing_luma.cpp \
- 	src/find_min_max.cpp \
- 	src/get_pred_adv_b_add.cpp \
- 	src/get_pred_outside.cpp \
- 	src/idct.cpp \
- 	src/idct_vca.cpp \
- 	src/mb_motion_comp.cpp \
- 	src/mb_utils.cpp \
- 	src/packet_util.cpp \
- 	src/post_filter.cpp \
- 	src/post_proc_semaphore.cpp \
- 	src/pp_semaphore_chroma_inter.cpp \
- 	src/pp_semaphore_luma.cpp \
- 	src/pvdec_api.cpp \
- 	src/scaling_tab.cpp \
- 	src/vlc_decode.cpp \
- 	src/vlc_dequant.cpp \
- 	src/vlc_tab.cpp \
- 	src/vop.cpp \
- 	src/zigzag_tab.cpp
-
-
-LOCAL_MODULE := libstagefright_m4vh263dec
-
-LOCAL_C_INCLUDES := \
-	$(LOCAL_PATH)/src \
-	$(LOCAL_PATH)/include \
-	$(TOP)/frameworks/av/media/libstagefright/include \
-	$(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_CFLAGS := -DOSCL_EXPORT_REF= -DOSCL_IMPORT_REF=
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftMPEG4.cpp
-
-LOCAL_C_INCLUDES := \
-	$(LOCAL_PATH)/src \
-	$(LOCAL_PATH)/include \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax
-
-LOCAL_CFLAGS := -DOSCL_EXPORT_REF= -DOSCL_IMPORT_REF=
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_m4vh263dec
-
-LOCAL_SHARED_LIBRARIES := \
-        libmedia libstagefright_omx libstagefright_foundation libutils liblog
-
-LOCAL_MODULE := libstagefright_soft_mpeg4dec
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/m4v_h263/enc/Android.bp b/media/libstagefright/codecs/m4v_h263/enc/Android.bp
new file mode 100644
index 0000000..da5b162
--- /dev/null
+++ b/media/libstagefright/codecs/m4v_h263/enc/Android.bp
@@ -0,0 +1,122 @@
+cc_library_static {
+    name: "libstagefright_m4vh263enc",
+
+    srcs: [
+        "src/bitstream_io.cpp",
+        "src/combined_encode.cpp",
+        "src/datapart_encode.cpp",
+        "src/dct.cpp",
+        "src/findhalfpel.cpp",
+        "src/fastcodemb.cpp",
+        "src/fastidct.cpp",
+        "src/fastquant.cpp",
+        "src/me_utils.cpp",
+        "src/mp4enc_api.cpp",
+        "src/rate_control.cpp",
+        "src/motion_est.cpp",
+        "src/motion_comp.cpp",
+        "src/sad.cpp",
+        "src/sad_halfpel.cpp",
+        "src/vlc_encode.cpp",
+        "src/vop.cpp",
+    ],
+
+    cflags: [
+        "-DBX_RC",
+        "-DOSCL_IMPORT_REF=",
+        "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+        "-DOSCL_EXPORT_REF=",
+
+        "-Werror",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+    local_include_dirs: ["src"],
+    export_include_dirs: ["include"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
+
+//###############################################################################
+
+cc_library_shared {
+    name: "libstagefright_soft_mpeg4enc",
+
+    srcs: ["SoftMPEG4Encoder.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+        "frameworks/native/include/media/hardware",
+    ],
+    local_include_dirs: ["src"],
+    export_include_dirs: ["include"],
+
+    cflags: [
+        "-DBX_RC",
+        "-DOSCL_IMPORT_REF=",
+        "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+        "-DOSCL_EXPORT_REF=",
+
+        "-Werror",
+    ],
+
+    static_libs: ["libstagefright_m4vh263enc"],
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libutils",
+        "liblog",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
+
+//###############################################################################
+
+cc_test {
+    name: "libstagefright_m4vh263enc_test",
+    gtest: false,
+
+    srcs: ["test/m4v_h263_enc_test.cpp"],
+
+    local_include_dirs: ["src"],
+
+    cflags: [
+        "-DOSCL_EXPORT_REF=",
+        "-DOSCL_IMPORT_REF=",
+        "-DBX_RC",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    static_libs: ["libstagefright_m4vh263enc"],
+}
diff --git a/media/libstagefright/codecs/m4v_h263/enc/Android.mk b/media/libstagefright/codecs/m4v_h263/enc/Android.mk
deleted file mode 100644
index f950052..0000000
--- a/media/libstagefright/codecs/m4v_h263/enc/Android.mk
+++ /dev/null
@@ -1,99 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    src/bitstream_io.cpp \
-    src/combined_encode.cpp \
-    src/datapart_encode.cpp \
-    src/dct.cpp \
-    src/findhalfpel.cpp \
-    src/fastcodemb.cpp \
-    src/fastidct.cpp \
-    src/fastquant.cpp \
-    src/me_utils.cpp \
-    src/mp4enc_api.cpp \
-    src/rate_control.cpp \
-    src/motion_est.cpp \
-    src/motion_comp.cpp \
-    src/sad.cpp \
-    src/sad_halfpel.cpp \
-    src/vlc_encode.cpp \
-    src/vop.cpp
-
-
-LOCAL_MODULE := libstagefright_m4vh263enc
-
-LOCAL_CFLAGS := \
-    -DBX_RC \
-    -DOSCL_IMPORT_REF= -D"OSCL_UNUSED_ARG(x)=(void)(x)" -DOSCL_EXPORT_REF=
-
-LOCAL_C_INCLUDES := \
-    $(LOCAL_PATH)/src \
-    $(LOCAL_PATH)/include \
-    $(TOP)/frameworks/av/media/libstagefright/include \
-    $(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftMPEG4Encoder.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax \
-        frameworks/native/include/media/hardware \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include \
-        $(LOCAL_PATH)/../common/include \
-        $(LOCAL_PATH)/../common
-
-LOCAL_CFLAGS := \
-    -DBX_RC \
-    -DOSCL_IMPORT_REF= -D"OSCL_UNUSED_ARG(x)=(void)(x)" -DOSCL_EXPORT_REF=
-
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_m4vh263enc
-
-LOCAL_SHARED_LIBRARIES := \
-        libmedia \
-        libstagefright_omx \
-        libutils \
-        liblog \
-
-LOCAL_MODULE := libstagefright_soft_mpeg4enc
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_SHARED_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
-        test/m4v_h263_enc_test.cpp
-
-LOCAL_C_INCLUDES := \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include
-
-LOCAL_CFLAGS := -DOSCL_EXPORT_REF= -DOSCL_IMPORT_REF= -DBX_RC
-LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_m4vh263enc
-
-LOCAL_MODULE := libstagefright_m4vh263enc_test
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/codecs/mp3dec/Android.bp b/media/libstagefright/codecs/mp3dec/Android.bp
new file mode 100644
index 0000000..0d0a2c6
--- /dev/null
+++ b/media/libstagefright/codecs/mp3dec/Android.bp
@@ -0,0 +1,146 @@
+cc_library_static {
+    name: "libstagefright_mp3dec",
+
+    srcs: [
+        "src/pvmp3_normalize.cpp",
+        "src/pvmp3_alias_reduction.cpp",
+        "src/pvmp3_crc.cpp",
+        "src/pvmp3_decode_header.cpp",
+        "src/pvmp3_decode_huff_cw.cpp",
+        "src/pvmp3_getbits.cpp",
+        "src/pvmp3_dequantize_sample.cpp",
+        "src/pvmp3_framedecoder.cpp",
+        "src/pvmp3_get_main_data_size.cpp",
+        "src/pvmp3_get_side_info.cpp",
+        "src/pvmp3_get_scale_factors.cpp",
+        "src/pvmp3_mpeg2_get_scale_data.cpp",
+        "src/pvmp3_mpeg2_get_scale_factors.cpp",
+        "src/pvmp3_mpeg2_stereo_proc.cpp",
+        "src/pvmp3_huffman_decoding.cpp",
+        "src/pvmp3_huffman_parsing.cpp",
+        "src/pvmp3_tables.cpp",
+        "src/pvmp3_imdct_synth.cpp",
+        "src/pvmp3_mdct_6.cpp",
+        "src/pvmp3_dct_6.cpp",
+        "src/pvmp3_poly_phase_synthesis.cpp",
+        "src/pvmp3_equalizer.cpp",
+        "src/pvmp3_seek_synch.cpp",
+        "src/pvmp3_stereo_proc.cpp",
+        "src/pvmp3_reorder.cpp",
+
+        "src/pvmp3_polyphase_filter_window.cpp",
+        "src/pvmp3_mdct_18.cpp",
+        "src/pvmp3_dct_9.cpp",
+        "src/pvmp3_dct_16.cpp",
+    ],
+
+    arch: {
+        arm: {
+            exclude_srcs: [
+                "src/pvmp3_polyphase_filter_window.cpp",
+                "src/pvmp3_mdct_18.cpp",
+                "src/pvmp3_dct_9.cpp",
+                "src/pvmp3_dct_16.cpp",
+            ],
+            srcs: [
+                "src/asm/pvmp3_polyphase_filter_window_gcc.s",
+                "src/asm/pvmp3_mdct_18_gcc.s",
+                "src/asm/pvmp3_dct_9_gcc.s",
+                "src/asm/pvmp3_dct_16_gcc.s",
+            ],
+
+            instruction_set: "arm",
+        },
+    },
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    include_dirs: ["frameworks/av/media/libstagefright/include"],
+    local_include_dirs: ["src"],
+    export_include_dirs: ["include"],
+
+    cflags: [
+        "-DOSCL_UNUSED_ARG(x)=(void)(x)",
+        "-Werror",
+    ],
+}
+
+//###############################################################################
+
+cc_library_shared {
+    name: "libstagefright_soft_mp3dec",
+
+    srcs: ["SoftMP3.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+    local_include_dirs: [
+        "src",
+        "include",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+
+    static_libs: ["libstagefright_mp3dec"],
+}
+
+//###############################################################################
+cc_test {
+    name: "libstagefright_mp3dec_test",
+    gtest: false,
+
+    srcs: [
+        "test/mp3dec_test.cpp",
+        "test/mp3reader.cpp",
+    ],
+
+    local_include_dirs: [
+        "src",
+        "include",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    static_libs: [
+        "libstagefright_mp3dec",
+        "libsndfile",
+    ],
+
+    shared_libs: ["libaudioutils"],
+}
diff --git a/media/libstagefright/codecs/mp3dec/Android.mk b/media/libstagefright/codecs/mp3dec/Android.mk
deleted file mode 100644
index 5d153d1..0000000
--- a/media/libstagefright/codecs/mp3dec/Android.mk
+++ /dev/null
@@ -1,114 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	src/pvmp3_normalize.cpp \
- 	src/pvmp3_alias_reduction.cpp \
- 	src/pvmp3_crc.cpp \
- 	src/pvmp3_decode_header.cpp \
- 	src/pvmp3_decode_huff_cw.cpp \
- 	src/pvmp3_getbits.cpp \
- 	src/pvmp3_dequantize_sample.cpp \
- 	src/pvmp3_framedecoder.cpp \
- 	src/pvmp3_get_main_data_size.cpp \
- 	src/pvmp3_get_side_info.cpp \
- 	src/pvmp3_get_scale_factors.cpp \
- 	src/pvmp3_mpeg2_get_scale_data.cpp \
- 	src/pvmp3_mpeg2_get_scale_factors.cpp \
- 	src/pvmp3_mpeg2_stereo_proc.cpp \
- 	src/pvmp3_huffman_decoding.cpp \
- 	src/pvmp3_huffman_parsing.cpp \
- 	src/pvmp3_tables.cpp \
- 	src/pvmp3_imdct_synth.cpp \
- 	src/pvmp3_mdct_6.cpp \
- 	src/pvmp3_dct_6.cpp \
- 	src/pvmp3_poly_phase_synthesis.cpp \
- 	src/pvmp3_equalizer.cpp \
- 	src/pvmp3_seek_synch.cpp \
- 	src/pvmp3_stereo_proc.cpp \
- 	src/pvmp3_reorder.cpp \
-
-LOCAL_SRC_FILES_arm += \
-	src/asm/pvmp3_polyphase_filter_window_gcc.s \
- 	src/asm/pvmp3_mdct_18_gcc.s \
- 	src/asm/pvmp3_dct_9_gcc.s \
-	src/asm/pvmp3_dct_16_gcc.s
-LOCAL_SRC_FILES_other_archs := \
- 	src/pvmp3_polyphase_filter_window.cpp \
- 	src/pvmp3_mdct_18.cpp \
- 	src/pvmp3_dct_9.cpp \
- 	src/pvmp3_dct_16.cpp
-
-LOCAL_SRC_FILES_arm64  := $(LOCAL_SRC_FILES_other_archs)
-LOCAL_SRC_FILES_mips   := $(LOCAL_SRC_FILES_other_archs)
-LOCAL_SRC_FILES_mips64 := $(LOCAL_SRC_FILES_other_archs)
-LOCAL_SRC_FILES_x86    := $(LOCAL_SRC_FILES_other_archs)
-LOCAL_SRC_FILES_x86_64 := $(LOCAL_SRC_FILES_other_archs)
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include
-
-LOCAL_CFLAGS := \
-        -D"OSCL_UNUSED_ARG(x)=(void)(x)"
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_MODULE := libstagefright_mp3dec
-
-LOCAL_ARM_MODE := arm
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftMP3.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES := \
-        libmedia libstagefright_omx libstagefright_foundation libutils liblog
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_mp3dec
-
-LOCAL_MODULE := libstagefright_soft_mp3dec
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-################################################################################
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
-        test/mp3dec_test.cpp  \
-        test/mp3reader.cpp
-
-LOCAL_C_INCLUDES := \
-        $(LOCAL_PATH)/src \
-        $(LOCAL_PATH)/include \
-        $(LOCAL_PATH)/test/include \
-        $(call include-path-for, audio-utils)
-
-LOCAL_SANITIZE := signed-integer-overflow
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_mp3dec libsndfile
-
-LOCAL_SHARED_LIBRARIES := libaudioutils
-
-LOCAL_MODULE := libstagefright_mp3dec_test
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/codecs/mp3dec/SoftMP3.cpp b/media/libstagefright/codecs/mp3dec/SoftMP3.cpp
index 0822c34..3def1f0 100644
--- a/media/libstagefright/codecs/mp3dec/SoftMP3.cpp
+++ b/media/libstagefright/codecs/mp3dec/SoftMP3.cpp
@@ -274,7 +274,7 @@
         mConfig->inputBufferUsedLength = 0;
 
         mConfig->outputFrameSize = kOutputBufferSize / sizeof(int16_t);
-        if ((int32)outHeader->nAllocLen < mConfig->outputFrameSize) {
+        if ((int32_t)outHeader->nAllocLen < mConfig->outputFrameSize) {
             ALOGE("input buffer too small: got %u, expected %u",
                 outHeader->nAllocLen, mConfig->outputFrameSize);
             android_errorWriteLog(0x534e4554, "27793371");
@@ -363,7 +363,7 @@
             mAnchorTimeUs + (mNumFramesOutput * 1000000ll) / mSamplingRate;
 
         if (inHeader) {
-            CHECK_GE(inHeader->nFilledLen, mConfig->inputBufferUsedLength);
+            CHECK_GE((int32_t)inHeader->nFilledLen, mConfig->inputBufferUsedLength);
 
             inHeader->nOffset += mConfig->inputBufferUsedLength;
             inHeader->nFilledLen -= mConfig->inputBufferUsedLength;
diff --git a/media/libstagefright/codecs/mpeg2dec/Android.bp b/media/libstagefright/codecs/mpeg2dec/Android.bp
new file mode 100644
index 0000000..0144581
--- /dev/null
+++ b/media/libstagefright/codecs/mpeg2dec/Android.bp
@@ -0,0 +1,33 @@
+cc_library_shared {
+    name: "libstagefright_soft_mpeg2dec",
+
+    static_libs: ["libmpeg2dec"],
+    srcs: ["SoftMPEG2.cpp"],
+
+    include_dirs: [
+        "external/libmpeg2/decoder",
+        "external/libmpeg2/common",
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+
+    ldflags: ["-Wl,-Bsymbolic"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/codecs/mpeg2dec/Android.mk b/media/libstagefright/codecs/mpeg2dec/Android.mk
deleted file mode 100644
index 0afc180..0000000
--- a/media/libstagefright/codecs/mpeg2dec/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-ifeq ($(if $(wildcard external/libmpeg2),1,0),1)
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE            := libstagefright_soft_mpeg2dec
-LOCAL_MODULE_TAGS       := optional
-
-LOCAL_STATIC_LIBRARIES  := libmpeg2dec
-LOCAL_SRC_FILES         := SoftMPEG2.cpp
-
-LOCAL_C_INCLUDES := $(TOP)/external/libmpeg2/decoder
-LOCAL_C_INCLUDES += $(TOP)/external/libmpeg2/common
-LOCAL_C_INCLUDES += $(TOP)/frameworks/av/media/libstagefright/include
-LOCAL_C_INCLUDES += $(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_SHARED_LIBRARIES  := libmedia
-LOCAL_SHARED_LIBRARIES  += libstagefright_omx
-LOCAL_SHARED_LIBRARIES  += libstagefright_foundation
-LOCAL_SHARED_LIBRARIES  += libutils
-LOCAL_SHARED_LIBRARIES  += liblog
-
-LOCAL_LDFLAGS := -Wl,-Bsymbolic
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_SHARED_LIBRARY)
-
-endif
diff --git a/media/libstagefright/codecs/on2/Android.bp b/media/libstagefright/codecs/on2/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/media/libstagefright/codecs/on2/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/media/libstagefright/codecs/on2/Android.mk b/media/libstagefright/codecs/on2/Android.mk
deleted file mode 100644
index 2e43120..0000000
--- a/media/libstagefright/codecs/on2/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/codecs/on2/dec/Android.bp b/media/libstagefright/codecs/on2/dec/Android.bp
new file mode 100644
index 0000000..c4242c2
--- /dev/null
+++ b/media/libstagefright/codecs/on2/dec/Android.bp
@@ -0,0 +1,33 @@
+cc_library_shared {
+    name: "libstagefright_soft_vpxdec",
+
+    srcs: ["SoftVPX.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    static_libs: ["libvpx"],
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/codecs/on2/dec/Android.mk b/media/libstagefright/codecs/on2/dec/Android.mk
deleted file mode 100644
index 8bc7dbc..0000000
--- a/media/libstagefright/codecs/on2/dec/Android.mk
+++ /dev/null
@@ -1,27 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftVPX.cpp
-
-LOCAL_C_INCLUDES := \
-        $(TOP)/external/libvpx/libvpx \
-        $(TOP)/external/libvpx/libvpx/vpx_codec \
-        $(TOP)/external/libvpx/libvpx/vpx_ports \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax \
-
-LOCAL_STATIC_LIBRARIES := \
-        libvpx
-
-LOCAL_SHARED_LIBRARIES := \
-        libmedia libstagefright_omx libstagefright_foundation libutils liblog
-
-LOCAL_MODULE := libstagefright_soft_vpxdec
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/on2/enc/Android.bp b/media/libstagefright/codecs/on2/enc/Android.bp
new file mode 100644
index 0000000..114c1be
--- /dev/null
+++ b/media/libstagefright/codecs/on2/enc/Android.bp
@@ -0,0 +1,35 @@
+cc_library_shared {
+    name: "libstagefright_soft_vpxenc",
+
+    srcs: [
+        "SoftVPXEncoder.cpp",
+        "SoftVP8Encoder.cpp",
+        "SoftVP9Encoder.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    static_libs: ["libvpx"],
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+}
diff --git a/media/libstagefright/codecs/on2/enc/Android.mk b/media/libstagefright/codecs/on2/enc/Android.mk
deleted file mode 100644
index 747aae0..0000000
--- a/media/libstagefright/codecs/on2/enc/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftVPXEncoder.cpp \
-        SoftVP8Encoder.cpp \
-        SoftVP9Encoder.cpp
-
-LOCAL_C_INCLUDES := \
-        $(TOP)/external/libvpx/libvpx \
-        $(TOP)/external/libvpx/libvpx/vpx_codec \
-        $(TOP)/external/libvpx/libvpx/vpx_ports \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax \
-
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_STATIC_LIBRARIES := \
-        libvpx
-
-LOCAL_SHARED_LIBRARIES := \
-        libmedia libstagefright_omx libstagefright_foundation libutils liblog \
-
-LOCAL_MODULE := libstagefright_soft_vpxenc
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/on2/h264dec/Android.bp b/media/libstagefright/codecs/on2/h264dec/Android.bp
new file mode 100644
index 0000000..95c2075
--- /dev/null
+++ b/media/libstagefright/codecs/on2/h264dec/Android.bp
@@ -0,0 +1,137 @@
+cc_library_shared {
+    name: "libstagefright_soft_h264dec",
+
+    srcs: [
+        "source/h264bsd_transform.c",
+        "source/h264bsd_util.c",
+        "source/h264bsd_byte_stream.c",
+        "source/h264bsd_seq_param_set.c",
+        "source/h264bsd_pic_param_set.c",
+        "source/h264bsd_slice_header.c",
+        "source/h264bsd_slice_data.c",
+        "source/h264bsd_macroblock_layer.c",
+        "source/h264bsd_stream.c",
+        "source/h264bsd_vlc.c",
+        "source/h264bsd_cavlc.c",
+        "source/h264bsd_nal_unit.c",
+        "source/h264bsd_neighbour.c",
+        "source/h264bsd_storage.c",
+        "source/h264bsd_slice_group_map.c",
+        "source/h264bsd_intra_prediction.c",
+        "source/h264bsd_inter_prediction.c",
+        "source/h264bsd_reconstruct.c",
+        "source/h264bsd_dpb.c",
+        "source/h264bsd_image.c",
+        "source/h264bsd_deblocking.c",
+        "source/h264bsd_conceal.c",
+        "source/h264bsd_vui.c",
+        "source/h264bsd_pic_order_cnt.c",
+        "source/h264bsd_decoder.c",
+        "source/H264SwDecApi.c",
+        "SoftAVC.cpp",
+    ],
+
+    arch: {
+        arm: {
+            instruction_set: "arm",
+
+            armv7_a_neon: {
+                cflags: [
+                    "-DH264DEC_NEON",
+                    "-DH264DEC_OMXDL",
+                ],
+                srcs: [
+                    "source/arm_neon_asm_gcc/h264bsdWriteMacroblock.S",
+                    "source/arm_neon_asm_gcc/h264bsdClearMbLayer.S",
+                    "source/arm_neon_asm_gcc/h264bsdFillRow7.S",
+                    "source/arm_neon_asm_gcc/h264bsdCountLeadingZeros.S",
+                    "source/arm_neon_asm_gcc/h264bsdFlushBits.S",
+
+                    "omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c",
+                    "omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c",
+                    "omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c",
+                    "omxdl/arm_neon/vc/m4p10/src/armVCM4P10_CAVLCTables.c",
+                    "omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c",
+                    "omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c",
+                    "omxdl/arm_neon/src/armCOMM_Bitstream.c",
+                    "omxdl/arm_neon/src/armCOMM.c",
+
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingChroma_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingLuma_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Align_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Copy_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_InterpolateLuma_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Average_4x_Align_unsafe_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DequantTables_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_QuantTables_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_TransformResidual4x4_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_UnpackBlock4x4_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S",
+                    "omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S",
+                ],
+
+                local_include_dirs: [
+                    "source/arm_neon_asm_gcc",
+
+                    "omxdl/arm_neon/api",
+                    "omxdl/arm_neon/vc/api",
+                    "omxdl/arm_neon/vc/m4p10/api",
+                ],
+            },
+        },
+    },
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    export_include_dirs: ["inc"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+}
+
+//####################################################################
+// test utility: decoder
+//####################################################################
+//#
+//# Test application
+//#
+cc_binary {
+    name: "decoder",
+
+    srcs: ["source/DecTestBench.c"],
+
+    shared_libs: ["libstagefright_soft_h264dec"],
+}
diff --git a/media/libstagefright/codecs/on2/h264dec/Android.mk b/media/libstagefright/codecs/on2/h264dec/Android.mk
deleted file mode 100644
index 10147ec..0000000
--- a/media/libstagefright/codecs/on2/h264dec/Android.mk
+++ /dev/null
@@ -1,129 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_ARM_MODE := arm
-
-LOCAL_SRC_FILES := \
-	./source/h264bsd_transform.c \
-	./source/h264bsd_util.c \
-	./source/h264bsd_byte_stream.c \
-	./source/h264bsd_seq_param_set.c \
-	./source/h264bsd_pic_param_set.c \
-	./source/h264bsd_slice_header.c \
-	./source/h264bsd_slice_data.c \
-	./source/h264bsd_macroblock_layer.c \
-	./source/h264bsd_stream.c \
-	./source/h264bsd_vlc.c \
-	./source/h264bsd_cavlc.c \
-	./source/h264bsd_nal_unit.c \
-	./source/h264bsd_neighbour.c \
-	./source/h264bsd_storage.c \
-	./source/h264bsd_slice_group_map.c \
-	./source/h264bsd_intra_prediction.c \
-	./source/h264bsd_inter_prediction.c \
-	./source/h264bsd_reconstruct.c \
-	./source/h264bsd_dpb.c \
-	./source/h264bsd_image.c \
-	./source/h264bsd_deblocking.c \
-	./source/h264bsd_conceal.c \
-	./source/h264bsd_vui.c \
-	./source/h264bsd_pic_order_cnt.c \
-	./source/h264bsd_decoder.c \
-	./source/H264SwDecApi.c \
-	SoftAVC.cpp \
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/./inc \
-	frameworks/av/media/libstagefright/include \
-	frameworks/native/include/media/openmax \
-
-MY_ASM := \
-	./source/arm_neon_asm_gcc/h264bsdWriteMacroblock.S \
-	./source/arm_neon_asm_gcc/h264bsdClearMbLayer.S \
-	./source/arm_neon_asm_gcc/h264bsdFillRow7.S \
-	./source/arm_neon_asm_gcc/h264bsdCountLeadingZeros.S \
-	./source/arm_neon_asm_gcc/h264bsdFlushBits.S
-
-
-MY_OMXDL_C_SRC := \
-	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c \
-	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c \
-	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c \
-	./omxdl/arm_neon/vc/m4p10/src/armVCM4P10_CAVLCTables.c \
-	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c \
-	./omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c \
-	./omxdl/arm_neon/src/armCOMM_Bitstream.c \
-	./omxdl/arm_neon/src/armCOMM.c
-
-MY_OMXDL_ASM_SRC := \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingChroma_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DeblockingLuma_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Align_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_Copy_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_DiagCopy_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagHorVer4x4_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfDiagVerHor4x4_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfHor4x4_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_InterpolateLuma_HalfVer4x4_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_HorEdge_I_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingChroma_VerEdge_I_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_HorEdge_I_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_FilterDeblockingLuma_VerEdge_I_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_InterpolateLuma_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Average_4x_Align_unsafe_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DequantTables_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_QuantTables_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_TransformResidual4x4_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_UnpackBlock4x4_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S \
-	./omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S \
-
-
-ifeq ($(ARCH_ARM_HAVE_NEON),true)
-    LOCAL_ARM_NEON   := true
-    LOCAL_CFLAGS_arm     := -DH264DEC_NEON -DH264DEC_OMXDL
-    LOCAL_SRC_FILES_arm  := $(MY_ASM) $(MY_OMXDL_C_SRC) $(MY_OMXDL_ASM_SRC)
-    LOCAL_C_INCLUDES_arm := $(LOCAL_PATH)/./source/arm_neon_asm_gcc
-    LOCAL_C_INCLUDES_arm += $(LOCAL_PATH)/./omxdl/arm_neon/api \
-                        $(LOCAL_PATH)/./omxdl/arm_neon/vc/api \
-                        $(LOCAL_PATH)/./omxdl/arm_neon/vc/m4p10/api
-endif
-
-LOCAL_SANITIZE := signed-integer-overflow cfi
-
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES := \
-	libmedia libstagefright_omx libstagefright_foundation libutils liblog \
-
-LOCAL_MODULE := libstagefright_soft_h264dec
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-#####################################################################
-# test utility: decoder
-#####################################################################
-##
-## Test application
-##
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := ./source/DecTestBench.c
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc
-
-LOCAL_SHARED_LIBRARIES := libstagefright_soft_h264dec
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_MODULE := decoder
-
-include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/codecs/opus/Android.bp b/media/libstagefright/codecs/opus/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/media/libstagefright/codecs/opus/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/media/libstagefright/codecs/opus/Android.mk b/media/libstagefright/codecs/opus/Android.mk
deleted file mode 100644
index 365b179..0000000
--- a/media/libstagefright/codecs/opus/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
\ No newline at end of file
diff --git a/media/libstagefright/codecs/opus/dec/Android.bp b/media/libstagefright/codecs/opus/dec/Android.bp
new file mode 100644
index 0000000..5d9c4c8
--- /dev/null
+++ b/media/libstagefright/codecs/opus/dec/Android.bp
@@ -0,0 +1,30 @@
+cc_library_shared {
+    name: "libstagefright_soft_opusdec",
+
+    srcs: ["SoftOpus.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    shared_libs: [
+        "libopus",
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/codecs/opus/dec/Android.mk b/media/libstagefright/codecs/opus/dec/Android.mk
deleted file mode 100644
index 5b887b3..0000000
--- a/media/libstagefright/codecs/opus/dec/Android.mk
+++ /dev/null
@@ -1,23 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftOpus.cpp
-
-LOCAL_C_INCLUDES := \
-        external/libopus/include \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax \
-
-LOCAL_SHARED_LIBRARIES := \
-        libopus libmedia libstagefright_omx \
-        libstagefright_foundation libutils liblog
-
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_MODULE := libstagefright_soft_opusdec
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/raw/Android.bp b/media/libstagefright/codecs/raw/Android.bp
new file mode 100644
index 0000000..c64027b
--- /dev/null
+++ b/media/libstagefright/codecs/raw/Android.bp
@@ -0,0 +1,30 @@
+cc_library_shared {
+    name: "libstagefright_soft_rawdec",
+
+    srcs: ["SoftRaw.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: [
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+}
diff --git a/media/libstagefright/codecs/raw/Android.mk b/media/libstagefright/codecs/raw/Android.mk
deleted file mode 100644
index 5fe260b..0000000
--- a/media/libstagefright/codecs/raw/Android.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftRaw.cpp
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES := \
-        libstagefright_omx libstagefright_foundation libutils liblog
-
-LOCAL_MODULE := libstagefright_soft_rawdec
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/codecs/vorbis/Android.bp b/media/libstagefright/codecs/vorbis/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/media/libstagefright/codecs/vorbis/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/media/libstagefright/codecs/vorbis/Android.mk b/media/libstagefright/codecs/vorbis/Android.mk
deleted file mode 100644
index 2e43120..0000000
--- a/media/libstagefright/codecs/vorbis/Android.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/codecs/vorbis/dec/Android.bp b/media/libstagefright/codecs/vorbis/dec/Android.bp
new file mode 100644
index 0000000..1a4de60
--- /dev/null
+++ b/media/libstagefright/codecs/vorbis/dec/Android.bp
@@ -0,0 +1,28 @@
+cc_library_shared {
+    name: "libstagefright_soft_vorbisdec",
+
+    srcs: ["SoftVorbis.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    shared_libs: [
+        "libvorbisidec",
+        "libmedia",
+        "libstagefright_omx",
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+    },
+}
diff --git a/media/libstagefright/codecs/vorbis/dec/Android.mk b/media/libstagefright/codecs/vorbis/dec/Android.mk
deleted file mode 100644
index 3d72d3a..0000000
--- a/media/libstagefright/codecs/vorbis/dec/Android.mk
+++ /dev/null
@@ -1,22 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        SoftVorbis.cpp
-
-LOCAL_C_INCLUDES := \
-        external/tremolo \
-        frameworks/av/media/libstagefright/include \
-        frameworks/native/include/media/openmax \
-
-LOCAL_SHARED_LIBRARIES := \
-        libvorbisidec libmedia libstagefright_omx \
-        libstagefright_foundation libutils liblog
-
-LOCAL_MODULE := libstagefright_soft_vorbisdec
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/colorconversion/Android.bp b/media/libstagefright/colorconversion/Android.bp
new file mode 100644
index 0000000..11fe5eb
--- /dev/null
+++ b/media/libstagefright/colorconversion/Android.bp
@@ -0,0 +1,28 @@
+cc_library_static {
+    name: "libstagefright_color_conversion",
+
+    srcs: [
+        "ColorConverter.cpp",
+        "SoftwareRenderer.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/native/include/media/openmax",
+    ],
+
+    shared_libs: ["libui"],
+
+    static_libs: ["libyuv_static"],
+
+    cflags: ["-Werror"],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/colorconversion/Android.mk b/media/libstagefright/colorconversion/Android.mk
deleted file mode 100644
index 1e7a4cc..0000000
--- a/media/libstagefright/colorconversion/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=                     \
-        ColorConverter.cpp            \
-        SoftwareRenderer.cpp
-
-LOCAL_C_INCLUDES := \
-        $(TOP)/frameworks/native/include/media/openmax \
-        $(TOP)/hardware/msm7k \
-        $(TOP)/external/libyuv/files/include
-
-LOCAL_SHARED_LIBRARIES := \
-        libui \
-
-LOCAL_STATIC_LIBRARIES := \
-        libyuv_static \
-
-LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_MODULE:= libstagefright_color_conversion
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/filters/Android.bp b/media/libstagefright/filters/Android.bp
new file mode 100644
index 0000000..e944224
--- /dev/null
+++ b/media/libstagefright/filters/Android.bp
@@ -0,0 +1,38 @@
+cc_library_static {
+    name: "libstagefright_mediafilter",
+
+    srcs: [
+        "ColorConvert.cpp",
+        "GraphicBufferListener.cpp",
+        "IntrinsicBlurFilter.cpp",
+        "MediaFilter.cpp",
+        "RSFilter.cpp",
+        "SaturationFilter.cpp",
+        "saturationARGB.rs",
+        "SimpleFilter.cpp",
+        "ZeroFilter.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: [
+        "-Wno-multichar",
+        "-Werror",
+        "-Wall",
+    ],
+
+    shared_libs: [
+        "libgui",
+        "libmedia",
+        "libhidlmemory",
+    ],
+
+    sanitize: {
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/filters/Android.mk b/media/libstagefright/filters/Android.mk
deleted file mode 100644
index d4ecfcc..0000000
--- a/media/libstagefright/filters/Android.mk
+++ /dev/null
@@ -1,35 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        ColorConvert.cpp          \
-        GraphicBufferListener.cpp \
-        IntrinsicBlurFilter.cpp   \
-        MediaFilter.cpp           \
-        RSFilter.cpp              \
-        SaturationFilter.cpp      \
-        saturationARGB.rs         \
-        SimpleFilter.cpp          \
-        ZeroFilter.cpp
-
-LOCAL_C_INCLUDES := \
-        $(TOP)/frameworks/native/include/media/openmax \
-        $(TOP)/frameworks/rs/cpp \
-        $(TOP)/frameworks/rs \
-
-intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
-LOCAL_C_INCLUDES += $(intermediates)
-
-LOCAL_CFLAGS += -Wno-multichar -Werror -Wall
-
-LOCAL_SHARED_LIBRARIES := \
-        libgui \
-        libmedia \
-        libhidlmemory \
-
-LOCAL_MODULE:= libstagefright_mediafilter
-
-LOCAL_SANITIZE := cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/foundation/Android.bp b/media/libstagefright/foundation/Android.bp
index 9b2e7fa..2f6c054 100644
--- a/media/libstagefright/foundation/Android.bp
+++ b/media/libstagefright/foundation/Android.bp
@@ -37,7 +37,10 @@
         "libpowermanager",
     ],
 
-    export_shared_lib_headers: ["libbinder", "libui"],
+    export_shared_lib_headers: [
+        "libbinder",
+        "libui",
+    ],
 
     cflags: [
         "-Wno-multichar",
@@ -52,7 +55,7 @@
         ],
         cfi: true,
         diag: {
-          cfi: true,
+            cfi: true,
         },
     },
 }
diff --git a/media/libstagefright/http/Android.bp b/media/libstagefright/http/Android.bp
new file mode 100644
index 0000000..5d90b0a
--- /dev/null
+++ b/media/libstagefright/http/Android.bp
@@ -0,0 +1,43 @@
+cc_library_shared {
+    name: "libstagefright_http_support",
+
+    srcs: ["HTTPHelper.cpp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/native/include/media/openmax",
+        "frameworks/base/core/jni",
+    ],
+
+    shared_libs: [
+        "liblog",
+        "libutils",
+        "libbinder",
+        "libandroid_runtime",
+        "libmedia",
+    ],
+
+    export_include_dirs: ["."],
+
+    cflags: [
+        "-Wno-multichar",
+        "-Werror",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    product_variables: {
+        pdk: {
+            enabled: false,
+        },
+    },
+}
diff --git a/media/libstagefright/http/Android.mk b/media/libstagefright/http/Android.mk
deleted file mode 100644
index 9c16f40..0000000
--- a/media/libstagefright/http/Android.mk
+++ /dev/null
@@ -1,30 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-ifneq ($(TARGET_BUILD_PDK), true)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=       \
-        HTTPHelper.cpp          \
-
-LOCAL_C_INCLUDES:= \
-	$(TOP)/frameworks/av/media/libstagefright \
-	$(TOP)/frameworks/native/include/media/openmax \
-	$(TOP)/frameworks/base/core/jni \
-
-LOCAL_SHARED_LIBRARIES := \
-    liblog libutils libbinder \
-    libandroid_runtime \
-    libmedia
-
-LOCAL_MODULE:= libstagefright_http_support
-
-LOCAL_CFLAGS += -Wno-multichar
-
-LOCAL_CFLAGS += -Werror -Wall
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_SHARED_LIBRARY)
-
-endif
diff --git a/media/libstagefright/httplive/Android.bp b/media/libstagefright/httplive/Android.bp
new file mode 100644
index 0000000..e415334
--- /dev/null
+++ b/media/libstagefright/httplive/Android.bp
@@ -0,0 +1,43 @@
+cc_library_shared {
+    name: "libstagefright_httplive",
+
+    srcs: [
+        "HTTPDownloader.cpp",
+        "LiveDataSource.cpp",
+        "LiveSession.cpp",
+        "M3UParser.cpp",
+        "PlaylistFetcher.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: [
+        "liblog",
+        "libbinder",
+        "libcrypto",
+        "libcutils",
+        "libmedia",
+        "libstagefright",
+        "libstagefright_foundation",
+        "libutils",
+    ],
+}
diff --git a/media/libstagefright/httplive/Android.mk b/media/libstagefright/httplive/Android.mk
deleted file mode 100644
index 1903d10..0000000
--- a/media/libstagefright/httplive/Android.mk
+++ /dev/null
@@ -1,36 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=               \
-        HTTPDownloader.cpp      \
-        LiveDataSource.cpp      \
-        LiveSession.cpp         \
-        M3UParser.cpp           \
-        PlaylistFetcher.cpp     \
-
-LOCAL_C_INCLUDES:= \
-	$(TOP)/frameworks/av/media/libstagefright \
-	$(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_CFLAGS += -Werror -Wall
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES := \
-        liblog \
-        libbinder \
-        libcrypto \
-        libcutils \
-        libmedia \
-        libstagefright \
-        libstagefright_foundation \
-        libutils \
-
-LOCAL_MODULE:= libstagefright_httplive
-
-ifeq ($(TARGET_ARCH),arm)
-    LOCAL_CFLAGS += -Wno-psabi
-endif
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp
index e144942..143fd59 100644
--- a/media/libstagefright/httplive/LiveSession.cpp
+++ b/media/libstagefright/httplive/LiveSession.cpp
@@ -699,7 +699,7 @@
                     }
 
                     if (mContinuation != NULL) {
-                        CHECK_GT(mContinuationCounter, 0);
+                        CHECK_GT(mContinuationCounter, 0u);
                         if (--mContinuationCounter == 0) {
                             mContinuation->post();
                         }
@@ -1550,7 +1550,7 @@
                     mOrigBandwidthIndex, mCurBandwidthIndex);
         }
     }
-    CHECK_LT(mCurBandwidthIndex, mBandwidthItems.size());
+    CHECK_LT((size_t)mCurBandwidthIndex, mBandwidthItems.size());
     const BandwidthItem &item = mBandwidthItems.itemAt(mCurBandwidthIndex);
 
     uint32_t streamMask = 0; // streams that should be fetched by the new fetcher
diff --git a/media/libstagefright/id3/Android.bp b/media/libstagefright/id3/Android.bp
new file mode 100644
index 0000000..30008d9
--- /dev/null
+++ b/media/libstagefright/id3/Android.bp
@@ -0,0 +1,53 @@
+cc_library_static {
+    name: "libstagefright_id3",
+
+    srcs: ["ID3.cpp"],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: ["libmedia"],
+}
+
+//###############################################################################
+
+cc_test {
+    name: "testid3",
+    gtest: false,
+
+    srcs: ["testid3.cpp"],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+
+    shared_libs: [
+        "libstagefright",
+        "libutils",
+        "liblog",
+        "libbinder",
+        "libstagefright_foundation",
+    ],
+
+    static_libs: ["libstagefright_id3"],
+
+    sanitize: {
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+}
diff --git a/media/libstagefright/id3/Android.mk b/media/libstagefright/id3/Android.mk
deleted file mode 100644
index 827703e..0000000
--- a/media/libstagefright/id3/Android.mk
+++ /dev/null
@@ -1,36 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	ID3.cpp
-
-LOCAL_CFLAGS += -Werror -Wall
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES := libmedia
-
-LOCAL_MODULE := libstagefright_id3
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	testid3.cpp
-
-LOCAL_CFLAGS += -Werror -Wall
-
-LOCAL_SHARED_LIBRARIES := \
-	libstagefright libutils liblog libbinder libstagefright_foundation
-
-LOCAL_STATIC_LIBRARIES := \
-        libstagefright_id3
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_MODULE := testid3
-
-include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/include/CodecBase.h b/media/libstagefright/include/CodecBase.h
index 845146d..0dd77ba 100644
--- a/media/libstagefright/include/CodecBase.h
+++ b/media/libstagefright/include/CodecBase.h
@@ -40,7 +40,7 @@
 namespace android {
 using namespace media;
 class BufferChannelBase;
-class BufferProducerWrapper;
+struct BufferProducerWrapper;
 class MediaCodecBuffer;
 struct PersistentSurface;
 struct RenderedFrameInfo;
diff --git a/media/libstagefright/include/DataSource.h b/media/libstagefright/include/DataSource.h
index 8f2c7eb..63eccea 100644
--- a/media/libstagefright/include/DataSource.h
+++ b/media/libstagefright/include/DataSource.h
@@ -156,7 +156,7 @@
         if (numBytesRead == -1) { // If readAt() returns -1, there is an error.
             return false;
         }
-        if (numBytesRead < numBytesPerChunk) {
+        if (static_cast<size_t>(numBytesRead) < numBytesPerChunk) {
             // This case is triggered when the stream ends before the whole
             // chunk is read.
             x->appendArray(tmp, (size_t)numBytesRead / sizeof(T));
diff --git a/media/libstagefright/include/MPEG4Writer.h b/media/libstagefright/include/MPEG4Writer.h
index 39e7d01..1c4827f 100644
--- a/media/libstagefright/include/MPEG4Writer.h
+++ b/media/libstagefright/include/MPEG4Writer.h
@@ -29,7 +29,7 @@
 
 namespace android {
 
-class AMessage;
+struct AMessage;
 class MediaBuffer;
 class MetaData;
 
diff --git a/media/libstagefright/include/MediaBuffer.h b/media/libstagefright/include/MediaBuffer.h
index 2c0ebe7..e74410d 100644
--- a/media/libstagefright/include/MediaBuffer.h
+++ b/media/libstagefright/include/MediaBuffer.h
@@ -223,7 +223,7 @@
         // Caution: atomic_int_fast32_t is 64 bits on LP64.
         std::atomic_int_least32_t mFlags;
         std::atomic_int_least32_t mRemoteRefcount;
-        int32_t unused[6]; // additional buffer space
+        int32_t unused[6] __attribute__((__unused__)); // additional buffer space
     };
 
     inline SharedControl *getSharedControl() const {
diff --git a/media/libstagefright/include/MediaCodecSource.h b/media/libstagefright/include/MediaCodecSource.h
index 5e99b78..02ba227 100644
--- a/media/libstagefright/include/MediaCodecSource.h
+++ b/media/libstagefright/include/MediaCodecSource.h
@@ -54,7 +54,8 @@
     // MediaSource
     virtual status_t start(MetaData *params = NULL);
     virtual status_t stop();
-    virtual status_t pause(MetaData *params = NULL);
+    virtual status_t pause() { return pause(NULL); }
+    virtual status_t pause(MetaData *params);
     virtual sp<MetaData> getFormat();
     virtual status_t read(
             MediaBuffer **buffer,
diff --git a/media/libstagefright/include/MediaExtractor.h b/media/libstagefright/include/MediaExtractor.h
index 073391f..a856b2b 100644
--- a/media/libstagefright/include/MediaExtractor.h
+++ b/media/libstagefright/include/MediaExtractor.h
@@ -70,7 +70,7 @@
     }
     virtual void setUID(uid_t /*uid*/) {
     }
-    virtual status_t setMediaCas(const sp<ICas> &cas) override {
+    virtual status_t setMediaCas(const sp<ICas>& /*cas*/) override {
         return INVALID_OPERATION;
     }
 
diff --git a/media/libstagefright/include/MediaWriter.h b/media/libstagefright/include/MediaWriter.h
index 9c30ffa..cd4af4d 100644
--- a/media/libstagefright/include/MediaWriter.h
+++ b/media/libstagefright/include/MediaWriter.h
@@ -50,7 +50,7 @@
 
     virtual void setStartTimeOffsetMs(int /*ms*/) {}
     virtual int32_t getStartTimeOffsetMs() const { return 0; }
-    virtual status_t setNextFd(int fd) { return INVALID_OPERATION; }
+    virtual status_t setNextFd(int /*fd*/) { return INVALID_OPERATION; }
 
 protected:
     virtual ~MediaWriter() {}
diff --git a/media/libstagefright/include/SurfaceMediaSource.h b/media/libstagefright/include/SurfaceMediaSource.h
index ae19a75..d38c337 100644
--- a/media/libstagefright/include/SurfaceMediaSource.h
+++ b/media/libstagefright/include/SurfaceMediaSource.h
@@ -106,8 +106,8 @@
     void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
 
     // dump our state in a String
-    void dump(String8& result) const;
-    void dump(String8& result, const char* prefix, char* buffer,
+    void dumpState(String8& result) const;
+    void dumpState(String8& result, const char* prefix, char* buffer,
                                                     size_t SIZE) const;
 
     // metaDataStoredInVideoBuffers tells the encoder what kind of metadata
diff --git a/media/libstagefright/include/foundation/ADebug.h b/media/libstagefright/include/foundation/ADebug.h
index 9ad45f3..b498c91 100644
--- a/media/libstagefright/include/foundation/ADebug.h
+++ b/media/libstagefright/include/foundation/ADebug.h
@@ -53,6 +53,9 @@
 #define LITERAL_TO_STRING_INTERNAL(x)    #x
 #define LITERAL_TO_STRING(x) LITERAL_TO_STRING_INTERNAL(x)
 
+#ifdef CHECK
+#undef CHECK
+#endif
 #define CHECK(condition)                                \
     LOG_ALWAYS_FATAL_IF(                                \
             !(condition),                               \
@@ -92,6 +95,15 @@
         }                                                               \
     } while (false)
 
+#ifdef CHECK_EQ
+#undef CHECK_EQ
+#undef CHECK_NE
+#undef CHECK_LE
+#undef CHECK_LT
+#undef CHECK_GE
+#undef CHECK_GT
+#endif
+
 #define CHECK_EQ(x,y)   CHECK_OP(x,y,EQ,==)
 #define CHECK_NE(x,y)   CHECK_OP(x,y,NE,!=)
 #define CHECK_LE(x,y)   CHECK_OP(x,y,LE,<=)
diff --git a/media/libstagefright/matroska/Android.bp b/media/libstagefright/matroska/Android.bp
new file mode 100644
index 0000000..a5891c3
--- /dev/null
+++ b/media/libstagefright/matroska/Android.bp
@@ -0,0 +1,30 @@
+cc_library_static {
+    name: "libstagefright_matroska",
+
+    srcs: ["MatroskaExtractor.cpp"],
+
+    include_dirs: [
+        "external/libvpx/libwebm",
+        "frameworks/native/include/media/openmax",
+        "frameworks/av/media/libstagefright/include",
+    ],
+
+    cflags: [
+        "-Wno-multichar",
+        "-Werror",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: ["libmedia"],
+}
diff --git a/media/libstagefright/matroska/Android.mk b/media/libstagefright/matroska/Android.mk
deleted file mode 100644
index 7de5dbe..0000000
--- a/media/libstagefright/matroska/Android.mk
+++ /dev/null
@@ -1,20 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=                 \
-        MatroskaExtractor.cpp
-
-LOCAL_C_INCLUDES:= \
-        $(TOP)/external/libvpx/libwebm \
-        $(TOP)/frameworks/native/include/media/openmax \
-        $(TOP)/frameworks/av/media/libstagefright/include \
-
-LOCAL_CFLAGS += -Wno-multichar -Werror -Wall
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES := libmedia
-
-LOCAL_MODULE:= libstagefright_matroska
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/mpeg2ts/Android.bp b/media/libstagefright/mpeg2ts/Android.bp
new file mode 100644
index 0000000..96eb5bf
--- /dev/null
+++ b/media/libstagefright/mpeg2ts/Android.bp
@@ -0,0 +1,39 @@
+cc_library_static {
+    name: "libstagefright_mpeg2ts",
+
+    srcs: [
+        "AnotherPacketSource.cpp",
+        "ATSParser.cpp",
+        "CasManager.cpp",
+        "ESQueue.cpp",
+        "HlsSampleDecryptor.cpp",
+        "MPEG2PSExtractor.cpp",
+        "MPEG2TSExtractor.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "unsigned-integer-overflow",
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    shared_libs: [
+        "libcrypto",
+        "libmedia",
+    ],
+}
diff --git a/media/libstagefright/mpeg2ts/Android.mk b/media/libstagefright/mpeg2ts/Android.mk
deleted file mode 100644
index 20acfe7..0000000
--- a/media/libstagefright/mpeg2ts/Android.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=                 \
-        AnotherPacketSource.cpp   \
-        ATSParser.cpp             \
-        CasManager.cpp            \
-        ESQueue.cpp               \
-        HlsSampleDecryptor.cpp    \
-        MPEG2PSExtractor.cpp      \
-        MPEG2TSExtractor.cpp      \
-
-LOCAL_C_INCLUDES:= \
-	$(TOP)/frameworks/av/media/libstagefright \
-	$(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_CFLAGS += -Werror -Wall
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SHARED_LIBRARIES := \
-        libcrypto \
-        libmedia \
-
-LOCAL_MODULE:= libstagefright_mpeg2ts
-
-ifeq ($(TARGET_ARCH),arm)
-    LOCAL_CFLAGS += -Wno-psabi
-endif
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/omx/Android.bp b/media/libstagefright/omx/Android.bp
new file mode 100644
index 0000000..ff5b841
--- /dev/null
+++ b/media/libstagefright/omx/Android.bp
@@ -0,0 +1,79 @@
+cc_library_shared {
+    name: "libstagefright_omx",
+
+    srcs: [
+        "FrameDropper.cpp",
+        "GraphicBufferSource.cpp",
+        "BWGraphicBufferSource.cpp",
+        "OMX.cpp",
+        "OMXMaster.cpp",
+        "OMXNodeInstance.cpp",
+        "OMXUtils.cpp",
+        "SimpleSoftOMXComponent.cpp",
+        "SoftOMXComponent.cpp",
+        "SoftOMXPlugin.cpp",
+        "SoftVideoDecoderOMXComponent.cpp",
+        "SoftVideoEncoderOMXComponent.cpp",
+        "1.0/Omx.cpp",
+        "1.0/OmxStore.cpp",
+        "1.0/WGraphicBufferProducer.cpp",
+        "1.0/WProducerListener.cpp",
+        "1.0/WGraphicBufferSource.cpp",
+        "1.0/WOmxNode.cpp",
+        "1.0/WOmxObserver.cpp",
+        "1.0/WOmxBufferSource.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/native/include/media/hardware",
+        // TODO: export this?
+        "frameworks/native/include/media/openmax",
+    ],
+
+    shared_libs: [
+        "libbase",
+        "libbinder",
+        "libmedia",
+        "libutils",
+        "liblog",
+        "libui",
+        "libgui",
+        "libcutils",
+        "libstagefright_foundation",
+        "libdl",
+        "libhidlbase",
+        "libhidlmemory",
+        "libhidltransport",
+        "libstagefright_xmlparser@1.0",
+        "android.hidl.memory@1.0",
+        "android.hardware.media@1.0",
+        "android.hardware.media.omx@1.0",
+        "android.hardware.graphics.common@1.0",
+        "android.hardware.graphics.bufferqueue@1.0",
+    ],
+
+    export_shared_lib_headers: ["android.hidl.memory@1.0"],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+        "-Wno-unused-parameter",
+        "-Wno-documentation",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
+
+//###############################################################################
+
+subdirs = ["tests"]
diff --git a/media/libstagefright/omx/Android.mk b/media/libstagefright/omx/Android.mk
deleted file mode 100644
index 29e2ccc..0000000
--- a/media/libstagefright/omx/Android.mk
+++ /dev/null
@@ -1,69 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=                          \
-        FrameDropper.cpp                   \
-        GraphicBufferSource.cpp            \
-        BWGraphicBufferSource.cpp          \
-        OMX.cpp                            \
-        OMXMaster.cpp                      \
-        OMXNodeInstance.cpp                \
-        OMXUtils.cpp                       \
-        SimpleSoftOMXComponent.cpp         \
-        SoftOMXComponent.cpp               \
-        SoftOMXPlugin.cpp                  \
-        SoftVideoDecoderOMXComponent.cpp   \
-        SoftVideoEncoderOMXComponent.cpp   \
-        1.0/Omx.cpp                        \
-        1.0/OmxStore.cpp                   \
-        1.0/WGraphicBufferProducer.cpp     \
-        1.0/WProducerListener.cpp          \
-        1.0/WGraphicBufferSource.cpp       \
-        1.0/WOmxNode.cpp                   \
-        1.0/WOmxObserver.cpp               \
-        1.0/WOmxBufferSource.cpp           \
-
-LOCAL_C_INCLUDES += \
-        $(TOP)/frameworks/av/media/libstagefright \
-        $(TOP)/frameworks/native/include/media/hardware \
-        $(TOP)/frameworks/native/include/media/openmax \
-        $(TOP)/system/libhidl/base/include \
-
-LOCAL_SHARED_LIBRARIES :=                         \
-        libbase                                   \
-        libbinder                                 \
-        libmedia                                  \
-        libutils                                  \
-        liblog                                    \
-        libui                                     \
-        libgui                                    \
-        libcutils                                 \
-        libstagefright_foundation                 \
-        libdl                                     \
-        libhidlbase                               \
-        libhidlmemory                             \
-        libstagefright_xmlparser@1.0              \
-        android.hidl.base@1.0                     \
-        android.hidl.memory@1.0                   \
-        android.hardware.media@1.0                \
-        android.hardware.media.omx@1.0            \
-        android.hardware.graphics.common@1.0      \
-        android.hardware.graphics.bufferqueue@1.0 \
-
-LOCAL_EXPORT_C_INCLUDES := \
-        $(TOP)/frameworks/av/include
-
-LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := \
-        android.hidl.memory@1.0
-
-LOCAL_MODULE:= libstagefright_omx
-LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-documentation
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-include $(BUILD_SHARED_LIBRARY)
-
-################################################################################
-
-include $(call all-makefiles-under,$(LOCAL_PATH)/hal)
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/libstagefright/omx/BWGraphicBufferSource.cpp b/media/libstagefright/omx/BWGraphicBufferSource.cpp
index f2a454f..2e2c461 100644
--- a/media/libstagefright/omx/BWGraphicBufferSource.cpp
+++ b/media/libstagefright/omx/BWGraphicBufferSource.cpp
@@ -21,7 +21,7 @@
 #include <OMX_IndexExt.h>
 
 #include <media/OMXBuffer.h>
-#include <IOMX.h>
+#include <media/IOMX.h>
 
 #include "OMXUtils.h"
 #include "BWGraphicBufferSource.h"
diff --git a/media/libstagefright/omx/BWGraphicBufferSource.h b/media/libstagefright/omx/BWGraphicBufferSource.h
index 43763c2..6f69d39 100644
--- a/media/libstagefright/omx/BWGraphicBufferSource.h
+++ b/media/libstagefright/omx/BWGraphicBufferSource.h
@@ -21,7 +21,7 @@
 #include <binder/Status.h>
 #include <android/BnGraphicBufferSource.h>
 #include <android/BnOMXBufferSource.h>
-#include <IOMX.h>
+#include <media/IOMX.h>
 
 #include "GraphicBufferSource.h"
 #include "IOmxNodeWrapper.h"
diff --git a/media/libstagefright/omx/GraphicBufferSource.cpp b/media/libstagefright/omx/GraphicBufferSource.cpp
index 103a3e9..a5c5108 100644
--- a/media/libstagefright/omx/GraphicBufferSource.cpp
+++ b/media/libstagefright/omx/GraphicBufferSource.cpp
@@ -35,7 +35,7 @@
 #include "omx/OMXUtils.h"
 #include <OMX_Component.h>
 #include <OMX_IndexExt.h>
-#include "OMXBuffer.h"
+#include "media/OMXBuffer.h"
 
 #include <inttypes.h>
 #include "FrameDropper.h"
diff --git a/media/libstagefright/omx/tests/Android.bp b/media/libstagefright/omx/tests/Android.bp
new file mode 100644
index 0000000..46428e3
--- /dev/null
+++ b/media/libstagefright/omx/tests/Android.bp
@@ -0,0 +1,51 @@
+cc_test {
+    name: "omx_tests",
+    gtest: false,
+
+    srcs: ["OMXHarness.cpp"],
+
+    shared_libs: [
+        "libstagefright",
+        "libbinder",
+        "libmedia",
+        "libutils",
+        "liblog",
+        "libstagefright_foundation",
+        "libcutils",
+        "libhidlbase",
+        "libhidlmemory",
+        "android.hidl.allocator@1.0",
+        "android.hidl.memory@1.0",
+        "android.hardware.media.omx@1.0",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+
+    compile_multilib: "32",
+}
+
+cc_test {
+    name: "FrameDropper_test",
+
+    srcs: ["FrameDropper_test.cpp"],
+
+    shared_libs: [
+        "libstagefright_omx",
+        "libutils",
+    ],
+
+    include_dirs: ["frameworks/av/media/libstagefright/omx"],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+}
diff --git a/media/libstagefright/omx/tests/Android.mk b/media/libstagefright/omx/tests/Android.mk
deleted file mode 100644
index 5941b94..0000000
--- a/media/libstagefright/omx/tests/Android.mk
+++ /dev/null
@@ -1,54 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES =       \
-        OMXHarness.cpp  \
-
-LOCAL_SHARED_LIBRARIES := \
-        libstagefright \
-        libbinder \
-        libmedia \
-        libutils \
-        liblog \
-        libstagefright_foundation \
-        libcutils \
-        libhidlbase \
-        libhidlmemory \
-        android.hidl.allocator@1.0 \
-        android.hidl.memory@1.0 \
-        android.hardware.media.omx@1.0 \
-
-LOCAL_C_INCLUDES := \
-        $(TOP)/frameworks/av/media/libstagefright \
-        $(TOP)/frameworks/native/include/media/openmax \
-        $(TOP)/system/libhidl/base/include \
-
-LOCAL_CFLAGS += -Werror -Wall
-
-LOCAL_MODULE := omx_tests
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_32_BIT_ONLY := true
-
-include $(BUILD_EXECUTABLE)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := FrameDropper_test
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-        FrameDropper_test.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-        libstagefright_omx \
-        libutils \
-
-LOCAL_C_INCLUDES := \
-        frameworks/av/media/libstagefright/omx \
-
-LOCAL_CFLAGS += -Werror -Wall
-
-include $(BUILD_NATIVE_TEST)
diff --git a/media/libstagefright/rtsp/Android.bp b/media/libstagefright/rtsp/Android.bp
new file mode 100644
index 0000000..debd07e
--- /dev/null
+++ b/media/libstagefright/rtsp/Android.bp
@@ -0,0 +1,96 @@
+cc_library_static {
+    name: "libstagefright_rtsp",
+
+    srcs: [
+        "AAMRAssembler.cpp",
+        "AAVCAssembler.cpp",
+        "AH263Assembler.cpp",
+        "AMPEG2TSAssembler.cpp",
+        "AMPEG4AudioAssembler.cpp",
+        "AMPEG4ElementaryAssembler.cpp",
+        "APacketSource.cpp",
+        "ARawAudioAssembler.cpp",
+        "ARTPAssembler.cpp",
+        "ARTPConnection.cpp",
+        "ARTPSource.cpp",
+        "ARTPWriter.cpp",
+        "ARTSPConnection.cpp",
+        "ASessionDescription.cpp",
+        "SDPLoader.cpp",
+    ],
+
+    shared_libs: [
+        "libcrypto",
+        "libmedia",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    arch: {
+        arm: {
+            cflags: ["-Wno-psabi"],
+        },
+    },
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
+
+//###############################################################################
+
+cc_test {
+    name: "rtp_test",
+    gtest: false,
+    enabled: false,
+
+    srcs: ["rtp_test.cpp"],
+
+    shared_libs: [
+        "libstagefright",
+        "liblog",
+        "libutils",
+        "libbinder",
+        "libstagefright_foundation",
+        "libmedia",
+    ],
+
+    static_libs: ["libstagefright_rtsp"],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/av/cmds/stagefright",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    cflags: [
+        "-Wno-multichar",
+        "-Werror",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/rtsp/Android.mk b/media/libstagefright/rtsp/Android.mk
deleted file mode 100644
index 3472e49..0000000
--- a/media/libstagefright/rtsp/Android.mk
+++ /dev/null
@@ -1,68 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=       \
-        AAMRAssembler.cpp           \
-        AAVCAssembler.cpp           \
-        AH263Assembler.cpp          \
-        AMPEG2TSAssembler.cpp       \
-        AMPEG4AudioAssembler.cpp    \
-        AMPEG4ElementaryAssembler.cpp \
-        APacketSource.cpp           \
-        ARawAudioAssembler.cpp      \
-        ARTPAssembler.cpp           \
-        ARTPConnection.cpp          \
-        ARTPSource.cpp              \
-        ARTPWriter.cpp              \
-        ARTSPConnection.cpp         \
-        ASessionDescription.cpp     \
-        SDPLoader.cpp               \
-
-LOCAL_SHARED_LIBRARIES += libcrypto libmedia
-
-LOCAL_C_INCLUDES:= \
-	$(TOP)/frameworks/av/media/libstagefright \
-	$(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_MODULE:= libstagefright_rtsp
-
-ifeq ($(TARGET_ARCH),arm)
-    LOCAL_CFLAGS += -Wno-psabi
-endif
-
-LOCAL_CFLAGS += -Werror -Wall
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-include $(BUILD_STATIC_LIBRARY)
-
-################################################################################
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	rtp_test.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-	libstagefright liblog libutils libbinder libstagefright_foundation libmedia
-
-LOCAL_STATIC_LIBRARIES := \
-	libstagefright_rtsp
-
-LOCAL_C_INCLUDES := \
-	frameworks/av/media/libstagefright \
-	frameworks/av/cmds/stagefright \
-	$(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_CFLAGS += -Wno-multichar -Werror -Wall
-LOCAL_SANITIZE := signed-integer-overflow
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_MODULE:= rtp_test
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-# include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/tests/Android.bp b/media/libstagefright/tests/Android.bp
new file mode 100644
index 0000000..35119c2
--- /dev/null
+++ b/media/libstagefright/tests/Android.bp
@@ -0,0 +1,68 @@
+// Build the unit tests.
+
+cc_test {
+    name: "SurfaceMediaSource_test",
+
+    srcs: [
+        "SurfaceMediaSource_test.cpp",
+        "DummyRecorder.cpp",
+    ],
+
+    shared_libs: [
+        "libEGL",
+        "libGLESv2",
+        "libbinder",
+        "libcutils",
+        "libgui",
+        "libmedia",
+        "libstagefright",
+        "libstagefright_foundation",
+        "libstagefright_omx",
+        "libsync",
+        "libui",
+        "libutils",
+        "liblog",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+        "frameworks/native/include/media/hardware",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+
+    compile_multilib: "32",
+}
+
+cc_test {
+    name: "MediaCodecListOverrides_test",
+
+    srcs: ["MediaCodecListOverrides_test.cpp"],
+
+    shared_libs: [
+        "libmedia",
+        "libstagefright",
+        "libstagefright_foundation",
+        "libstagefright_omx",
+        "libutils",
+        "liblog",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/av/media/libstagefright/include",
+        "frameworks/native/include/media/openmax",
+    ],
+
+    compile_multilib: "32",
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+}
diff --git a/media/libstagefright/tests/Android.mk b/media/libstagefright/tests/Android.mk
deleted file mode 100644
index c6963b1..0000000
--- a/media/libstagefright/tests/Android.mk
+++ /dev/null
@@ -1,77 +0,0 @@
-# Build the unit tests.
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_MODULE := SurfaceMediaSource_test
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-	SurfaceMediaSource_test.cpp \
-	DummyRecorder.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-	libEGL \
-	libGLESv2 \
-	libbinder \
-	libcutils \
-	libgui \
-	libmedia \
-	libstagefright \
-	libstagefright_foundation \
-	libstagefright_omx \
-	libsync \
-	libui \
-	libutils \
-	liblog
-
-LOCAL_C_INCLUDES := \
-	frameworks/av/media/libstagefright \
-	frameworks/av/media/libstagefright/include \
-	$(TOP)/frameworks/native/include/media/openmax \
-	$(TOP)/frameworks/native/include/media/hardware \
-
-LOCAL_CFLAGS += -Werror -Wall
-
-LOCAL_32_BIT_ONLY := true
-
-include $(BUILD_NATIVE_TEST)
-
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_MODULE := MediaCodecListOverrides_test
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-	MediaCodecListOverrides_test.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-	libmedia \
-	libstagefright \
-	libstagefright_foundation \
-	libstagefright_omx \
-	libutils \
-	liblog
-
-LOCAL_C_INCLUDES := \
-	frameworks/av/media/libstagefright \
-	frameworks/av/media/libstagefright/include \
-	frameworks/native/include/media/openmax \
-
-LOCAL_32_BIT_ONLY := true
-
-LOCAL_CFLAGS += -Werror -Wall
-
-include $(BUILD_NATIVE_TEST)
-
-# Include subdirectory makefiles
-# ============================================================
-
-# If we're building with ONE_SHOT_MAKEFILE (mm, mmm), then what the framework
-# team really wants is to build the stuff defined by this makefile.
-ifeq (,$(ONE_SHOT_MAKEFILE))
-include $(call first-makefiles-under,$(LOCAL_PATH))
-endif
diff --git a/media/libstagefright/timedtext/Android.bp b/media/libstagefright/timedtext/Android.bp
new file mode 100644
index 0000000..a5ad6c6
--- /dev/null
+++ b/media/libstagefright/timedtext/Android.bp
@@ -0,0 +1,27 @@
+cc_library_static {
+    name: "libstagefright_timedtext",
+
+    srcs: ["TextDescriptions.cpp"],
+
+    cflags: [
+        "-Wno-multichar",
+        "-Werror",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+    ],
+
+    shared_libs: ["libmedia"],
+}
diff --git a/media/libstagefright/timedtext/Android.mk b/media/libstagefright/timedtext/Android.mk
deleted file mode 100644
index 70ae46b..0000000
--- a/media/libstagefright/timedtext/Android.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=                 \
-        TextDescriptions.cpp      \
-
-LOCAL_CFLAGS += -Wno-multichar -Werror -Wall
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_C_INCLUDES:= \
-        $(TOP)/frameworks/av/include/media/stagefright/timedtext \
-        $(TOP)/frameworks/av/media/libstagefright
-
-LOCAL_SHARED_LIBRARIES := libmedia
-
-LOCAL_MODULE:= libstagefright_timedtext
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/webm/Android.bp b/media/libstagefright/webm/Android.bp
new file mode 100644
index 0000000..f968788
--- /dev/null
+++ b/media/libstagefright/webm/Android.bp
@@ -0,0 +1,37 @@
+cc_library_static {
+    name: "libstagefright_webm",
+
+    cppflags: ["-D__STDINT_LIMITS"],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+            "unsigned-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+
+    srcs: [
+        "EbmlUtil.cpp",
+        "WebmElement.cpp",
+        "WebmFrame.cpp",
+        "WebmFrameThread.cpp",
+        "WebmWriter.cpp",
+    ],
+
+    include_dirs: ["frameworks/av/include"],
+
+    shared_libs: [
+        "libstagefright_foundation",
+        "libutils",
+        "liblog",
+    ],
+}
diff --git a/media/libstagefright/webm/Android.mk b/media/libstagefright/webm/Android.mk
deleted file mode 100644
index 0d55de9..0000000
--- a/media/libstagefright/webm/Android.mk
+++ /dev/null
@@ -1,26 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_CPPFLAGS += -D__STDINT_LIMITS
-
-LOCAL_CFLAGS += -Werror -Wall
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_SRC_FILES:= EbmlUtil.cpp        \
-                  WebmElement.cpp     \
-                  WebmFrame.cpp       \
-                  WebmFrameThread.cpp \
-                  WebmWriter.cpp
-
-
-LOCAL_C_INCLUDES += $(TOP)/frameworks/av/include
-
-LOCAL_SHARED_LIBRARIES += libstagefright_foundation \
-                          libstagefright \
-                          libutils \
-                          liblog
-
-LOCAL_MODULE:= libstagefright_webm
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/webm/WebmFrameThread.cpp b/media/libstagefright/webm/WebmFrameThread.cpp
index 77de3c8..71bfbc9 100644
--- a/media/libstagefright/webm/WebmFrameThread.cpp
+++ b/media/libstagefright/webm/WebmFrameThread.cpp
@@ -124,7 +124,7 @@
 
 void WebmFrameSinkThread::writeCluster(List<sp<WebmElement> >& children) {
     // children must contain at least one simpleblock and its timecode
-    CHECK_GE(children.size(), 2);
+    CHECK_GE(children.size(), 2u);
 
     uint64_t size;
     sp<WebmElement> cluster = new WebmMaster(kMkvCluster, children);
@@ -155,7 +155,7 @@
         // flushing the second to last frame before we check its type. A audio frame
         // should precede the aforementioned video key frame in the next sequence, a video
         // frame should be the last frame in the current (to-be-flushed) sequence.
-        CHECK_GE(n, 2);
+        CHECK_GE(n, 2u);
         n -= 2;
     }
 
diff --git a/media/libstagefright/webm/WebmWriter.cpp b/media/libstagefright/webm/WebmWriter.cpp
index 25d6821..d6c6930 100644
--- a/media/libstagefright/webm/WebmWriter.cpp
+++ b/media/libstagefright/webm/WebmWriter.cpp
@@ -488,7 +488,7 @@
             params->findInt32(kKeyBitRate, &bitRate);
         }
         mEstimatedCuesSize = estimateCuesSize(bitRate);
-        CHECK_GE(mEstimatedCuesSize, 8);
+        CHECK_GE(mEstimatedCuesSize, 8u);
         cues = new EbmlVoid(mEstimatedCuesSize);
     }
 
diff --git a/media/libstagefright/wifi-display/Android.bp b/media/libstagefright/wifi-display/Android.bp
new file mode 100644
index 0000000..be23359
--- /dev/null
+++ b/media/libstagefright/wifi-display/Android.bp
@@ -0,0 +1,50 @@
+cc_library_shared {
+    name: "libstagefright_wfd",
+
+    srcs: [
+        "MediaSender.cpp",
+        "Parameters.cpp",
+        "rtp/RTPSender.cpp",
+        "source/Converter.cpp",
+        "source/MediaPuller.cpp",
+        "source/PlaybackSession.cpp",
+        "source/RepeaterSource.cpp",
+        "source/TSPacketizer.cpp",
+        "source/WifiDisplaySource.cpp",
+        "VideoFormats.cpp",
+    ],
+
+    include_dirs: [
+        "frameworks/av/media/libstagefright",
+        "frameworks/native/include/media/openmax",
+        "frameworks/native/include/media/hardware",
+        "frameworks/av/media/libstagefright/mpeg2ts",
+    ],
+
+    shared_libs: [
+        "libbinder",
+        "libcutils",
+        "liblog",
+        "libmedia",
+        "libstagefright",
+        "libstagefright_foundation",
+        "libui",
+        "libutils",
+    ],
+
+    cflags: [
+        "-Wno-multichar",
+        "-Werror",
+        "-Wall",
+    ],
+
+    sanitize: {
+        misc_undefined: [
+            "signed-integer-overflow",
+        ],
+        cfi: true,
+        diag: {
+            cfi: true,
+        },
+    },
+}
diff --git a/media/libstagefright/wifi-display/Android.mk b/media/libstagefright/wifi-display/Android.mk
deleted file mode 100644
index a1b4aec..0000000
--- a/media/libstagefright/wifi-display/Android.mk
+++ /dev/null
@@ -1,41 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-        MediaSender.cpp                 \
-        Parameters.cpp                  \
-        rtp/RTPSender.cpp               \
-        source/Converter.cpp            \
-        source/MediaPuller.cpp          \
-        source/PlaybackSession.cpp      \
-        source/RepeaterSource.cpp       \
-        source/TSPacketizer.cpp         \
-        source/WifiDisplaySource.cpp    \
-        VideoFormats.cpp                \
-
-LOCAL_C_INCLUDES:= \
-        $(TOP)/frameworks/av/media/libstagefright \
-        $(TOP)/frameworks/native/include/media/openmax \
-        $(TOP)/frameworks/native/include/media/hardware \
-        $(TOP)/frameworks/av/media/libstagefright/mpeg2ts \
-
-LOCAL_SHARED_LIBRARIES:= \
-        libbinder                       \
-        libcutils                       \
-        liblog                          \
-        libmedia                        \
-        libstagefright                  \
-        libstagefright_foundation       \
-        libui                           \
-        libutils                        \
-
-LOCAL_CFLAGS += -Wno-multichar -Werror -Wall
-LOCAL_SANITIZE := signed-integer-overflow cfi
-LOCAL_SANITIZE_DIAG := cfi
-
-LOCAL_MODULE:= libstagefright_wfd
-
-LOCAL_MODULE_TAGS:= optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/wifi-display/MediaSender.cpp b/media/libstagefright/wifi-display/MediaSender.cpp
index ae507fc..cc412f5 100644
--- a/media/libstagefright/wifi-display/MediaSender.cpp
+++ b/media/libstagefright/wifi-display/MediaSender.cpp
@@ -420,7 +420,7 @@
             CHECK(accessUnit->meta()->findInt32("rangeLength", &rangeLength));
             CHECK(accessUnit->meta()->findMessage("notify", &notify)
                     && notify != NULL);
-            CHECK_GE(accessUnit->size(), rangeLength);
+            CHECK_GE((int32_t)accessUnit->size(), rangeLength);
 
             sp<GraphicBuffer> grbuf(new GraphicBuffer(
                     rangeOffset + rangeLength /* width */, 1 /* height */,
diff --git a/media/libstagefright/wifi-display/rtp/RTPBase.h b/media/libstagefright/wifi-display/rtp/RTPBase.h
index 6178f00..194f1ee 100644
--- a/media/libstagefright/wifi-display/rtp/RTPBase.h
+++ b/media/libstagefright/wifi-display/rtp/RTPBase.h
@@ -36,10 +36,8 @@
         TRANSPORT_TCP_INTERLEAVED,
     };
 
-    enum {
-        // Really UDP _payload_ size
-        kMaxUDPPacketSize = 1472,   // 1472 good, 1473 bad on Android@Home
-    };
+    // Really UDP _payload_ size
+    const unsigned int kMaxUDPPacketSize = 1472;   // 1472 good, 1473 bad on Android@Home
 
     static int32_t PickRandomRTPPort();
 };
diff --git a/media/libstagefright/wifi-display/rtp/RTPSender.cpp b/media/libstagefright/wifi-display/rtp/RTPSender.cpp
index 83af393..ca9fdd2 100644
--- a/media/libstagefright/wifi-display/rtp/RTPSender.cpp
+++ b/media/libstagefright/wifi-display/rtp/RTPSender.cpp
@@ -247,7 +247,7 @@
 
 status_t RTPSender::queueTSPackets(
         const sp<ABuffer> &tsPackets, uint8_t packetType) {
-    CHECK_EQ(0, tsPackets->size() % 188);
+    CHECK_EQ(0u, tsPackets->size() % 188);
 
     int64_t timeUs;
     CHECK(tsPackets->meta()->findInt64("timeUs", &timeUs));
diff --git a/media/libstagefright/wifi-display/rtp/RTPSender.h b/media/libstagefright/wifi-display/rtp/RTPSender.h
index fefcab7..bedfd01 100644
--- a/media/libstagefright/wifi-display/rtp/RTPSender.h
+++ b/media/libstagefright/wifi-display/rtp/RTPSender.h
@@ -66,11 +66,9 @@
         kWhatRTCPNotify,
     };
 
-    enum {
-        kMaxNumTSPacketsPerRTPPacket = (kMaxUDPPacketSize - 12) / 188,
-        kMaxHistorySize              = 1024,
-        kSourceID                    = 0xdeadbeef,
-    };
+    const unsigned int kMaxNumTSPacketsPerRTPPacket = (kMaxUDPPacketSize - 12) / 188;
+    const unsigned int kMaxHistorySize              = 1024;
+    const unsigned int kSourceID                    = 0xdeadbeef;
 
     sp<ANetworkSession> mNetSession;
     sp<AMessage> mNotify;
diff --git a/media/libstagefright/wifi-display/source/TSPacketizer.cpp b/media/libstagefright/wifi-display/source/TSPacketizer.cpp
index 4c5ad17..865ba94 100644
--- a/media/libstagefright/wifi-display/source/TSPacketizer.cpp
+++ b/media/libstagefright/wifi-display/source/TSPacketizer.cpp
@@ -273,8 +273,8 @@
                 CHECK(mFormat->findInt32("profile-idc", &profileIdc));
                 CHECK(mFormat->findInt32("level-idc", &levelIdc));
                 CHECK(mFormat->findInt32("constraint-set", &constraintSet));
-                CHECK_GE(profileIdc, 0u);
-                CHECK_GE(levelIdc, 0u);
+                CHECK_GE(profileIdc, 0);
+                CHECK_GE(levelIdc, 0);
                 data[2] = profileIdc;    // profile_idc
                 data[3] = constraintSet; // constraint_set*
                 data[4] = levelIdc;      // level_idc
@@ -771,7 +771,7 @@
             program_info_length += mProgramInfoDescriptors.itemAt(i)->size();
         }
 
-        CHECK_LT(program_info_length, 0x400);
+        CHECK_LT(program_info_length, 0x400u);
         *ptr++ = 0xf0 | (program_info_length >> 8);
         *ptr++ = (program_info_length & 0xff);
 
@@ -795,7 +795,7 @@
             for (size_t i = 0; i < track->countDescriptors(); ++i) {
                 ES_info_length += track->descriptorAt(i)->size();
             }
-            CHECK_LE(ES_info_length, 0xfff);
+            CHECK_LE(ES_info_length, 0xfffu);
 
             *ptr++ = 0xf0 | (ES_info_length >> 8);
             *ptr++ = (ES_info_length & 0xff);
diff --git a/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp b/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp
index 9cda8dc..4695e5d 100644
--- a/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp
+++ b/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp
@@ -454,7 +454,7 @@
                 sp<ABuffer> data;
                 CHECK(msg->findBuffer("data", &data));
 
-                CHECK_LE(channel, 0xffu);
+                CHECK_LE(channel, 0xff);
                 CHECK_LE(data->size(), 0xffffu);
 
                 int32_t sessionID;
diff --git a/media/mtp/Android.bp b/media/mtp/Android.bp
new file mode 100644
index 0000000..5d5ae49
--- /dev/null
+++ b/media/mtp/Android.bp
@@ -0,0 +1,57 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_library_shared {
+    name: "libmtp",
+    srcs: [
+        "AsyncIO.cpp",
+        "MtpDataPacket.cpp",
+        "MtpDebug.cpp",
+        "MtpDevHandle.cpp",
+        "MtpDevice.cpp",
+        "MtpDeviceInfo.cpp",
+        "MtpEventPacket.cpp",
+        "MtpFfsHandle.cpp",
+        "MtpObjectInfo.cpp",
+        "MtpPacket.cpp",
+        "MtpProperty.cpp",
+        "MtpRequestPacket.cpp",
+        "MtpResponsePacket.cpp",
+        "MtpServer.cpp",
+        "MtpStorage.cpp",
+        "MtpStorageInfo.cpp",
+        "MtpStringBuffer.cpp",
+        "MtpUtils.cpp",
+    ],
+    export_include_dirs: ["."],
+    cflags: [
+        "-DMTP_DEVICE",
+        "-DMTP_HOST",
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+    shared_libs: [
+        "libbase",
+        "libutils",
+        "liblog",
+        "libusbhost",
+    ],
+}
+
+subdirs = [
+    "tests",
+]
diff --git a/media/mtp/Android.mk b/media/mtp/Android.mk
deleted file mode 100644
index 58753ff..0000000
--- a/media/mtp/Android.mk
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=                                       \
-                  AsyncIO.cpp                           \
-                  MtpDataPacket.cpp                     \
-                  MtpDebug.cpp                          \
-                  MtpDevHandle.cpp                      \
-                  MtpDevice.cpp                         \
-                  MtpDeviceInfo.cpp                     \
-                  MtpEventPacket.cpp                    \
-                  MtpFfsHandle.cpp                      \
-                  MtpObjectInfo.cpp                     \
-                  MtpPacket.cpp                         \
-                  MtpProperty.cpp                       \
-                  MtpRequestPacket.cpp                  \
-                  MtpResponsePacket.cpp                 \
-                  MtpServer.cpp                         \
-                  MtpStorage.cpp                        \
-                  MtpStorageInfo.cpp                    \
-                  MtpStringBuffer.cpp                   \
-                  MtpUtils.cpp                          \
-
-LOCAL_MODULE:= libmtp
-
-LOCAL_CFLAGS := -DMTP_DEVICE -DMTP_HOST -Wall -Wextra -Werror
-
-LOCAL_SHARED_LIBRARIES := libbase libutils libcutils liblog libusbhost libbinder
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index 88dabff..b773e8a 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -25,6 +25,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 
 #define LOG_TAG "MtpServer"
 
@@ -113,7 +114,8 @@
         mSessionOpen(false),
         mSendObjectHandle(kInvalidObjectHandle),
         mSendObjectFormat(0),
-        mSendObjectFileSize(0)
+        mSendObjectFileSize(0),
+        mSendObjectModifiedTime(0)
 {
 }
 
@@ -999,6 +1001,7 @@
         // save the handle for the SendObject call, which should follow
         mSendObjectHandle = handle;
         mSendObjectFormat = format;
+        mSendObjectModifiedTime = modifiedTime;
     }
 
     mResponse.setParameter(1, storageID);
@@ -1015,6 +1018,7 @@
     mode_t mask;
     int ret, initialData;
     bool isCanceled = false;
+    struct stat sstat = {};
 
     auto start = std::chrono::steady_clock::now();
 
@@ -1071,7 +1075,17 @@
             }
         }
     }
-    struct stat sstat;
+
+    if (mSendObjectModifiedTime) {
+        struct timespec newTime[2];
+        newTime[0].tv_nsec = UTIME_NOW;
+        newTime[1].tv_sec = mSendObjectModifiedTime;
+        newTime[1].tv_nsec = 0;
+        if (futimens(mfr.fd, newTime) < 0) {
+            ALOGW("changing modified time failed, %s", strerror(errno));
+        }
+    }
+
     fstat(mfr.fd, &sstat);
     close(mfr.fd);
 
@@ -1092,6 +1106,7 @@
             result == MTP_RESPONSE_OK);
     mSendObjectHandle = kInvalidObjectHandle;
     mSendObjectFormat = 0;
+    mSendObjectModifiedTime = 0;
 
     auto end = std::chrono::steady_clock::now();
     std::chrono::duration<double> diff = end - start;
diff --git a/media/mtp/MtpServer.h b/media/mtp/MtpServer.h
index 64d1b72..08a9e4a 100644
--- a/media/mtp/MtpServer.h
+++ b/media/mtp/MtpServer.h
@@ -78,6 +78,7 @@
     MtpObjectFormat     mSendObjectFormat;
     MtpString           mSendObjectFilePath;
     size_t              mSendObjectFileSize;
+    time_t              mSendObjectModifiedTime;
 
     Mutex               mMutex;
 
diff --git a/media/mtp/tests/Android.bp b/media/mtp/tests/Android.bp
new file mode 100644
index 0000000..356406d
--- /dev/null
+++ b/media/mtp/tests/Android.bp
@@ -0,0 +1,45 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_test {
+    name: "mtp_ffs_handle_test",
+    srcs: ["MtpFfsHandle_test.cpp"],
+    shared_libs: [
+        "libbase",
+        "libmtp",
+        "liblog",
+    ],
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+}
+
+cc_test {
+    name: "async_io_test",
+    srcs: ["AsyncIO_test.cpp"],
+    shared_libs: [
+        "libbase",
+        "libmtp",
+        "liblog",
+    ],
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+}
diff --git a/media/mtp/tests/Android.mk b/media/mtp/tests/Android.mk
deleted file mode 100644
index ace0d40..0000000
--- a/media/mtp/tests/Android.mk
+++ /dev/null
@@ -1,51 +0,0 @@
-# Build the unit tests.
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_MODULE := mtp_ffs_handle_test
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-	MtpFfsHandle_test.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-	libbase \
-	libcutils \
-	libmedia \
-	libmtp \
-	libutils \
-	liblog
-
-LOCAL_C_INCLUDES := \
-	frameworks/av/media/mtp \
-
-LOCAL_CFLAGS += -Werror -Wall
-
-include $(BUILD_NATIVE_TEST)
-
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_MODULE := async_io_test
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-	AsyncIO_test.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-	libbase \
-	libcutils \
-	libmedia \
-	libmtp \
-	libutils \
-	liblog
-
-LOCAL_C_INCLUDES := \
-	frameworks/av/media/mtp \
-
-LOCAL_CFLAGS += -Werror -Wall
-
-include $(BUILD_NATIVE_TEST)
diff --git a/media/ndk/Android.bp b/media/ndk/Android.bp
index 824872f..f5affe1 100644
--- a/media/ndk/Android.bp
+++ b/media/ndk/Android.bp
@@ -22,3 +22,11 @@
     first_version: "21",
     unversioned_until: "current",
 }
+
+ndk_headers {
+    name: "libmediandk_headers",
+    from: "include/media",
+    to: "media",
+    srcs: ["include/media/**/*.h"],
+    license: "NOTICE",
+}
diff --git a/media/ndk/Android.mk b/media/ndk/Android.mk
index 2c070af..413227f 100644
--- a/media/ndk/Android.mk
+++ b/media/ndk/Android.mk
@@ -37,11 +37,13 @@
     external/piex \
     frameworks/base/core/jni \
     frameworks/base/media/jni \
-    frameworks/av/include/ndk \
     frameworks/native/include \
     frameworks/native/include/media/openmax \
     system/media/camera/include \
     $(call include-path-for, libhardware)/hardware \
+    $(LOCAL_PATH)/include
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
 
 LOCAL_CFLAGS += -fvisibility=hidden -D EXPORT='__attribute__ ((visibility ("default")))'
 
diff --git a/media/ndk/NOTICE b/media/ndk/NOTICE
new file mode 100644
index 0000000..152be20
--- /dev/null
+++ b/media/ndk/NOTICE
@@ -0,0 +1,324 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Android-specific code.                        ==
+   =========================================================================
+
+Android Code
+Copyright 2005-2008 The Android Open Source Project
+
+This product includes software developed as part of
+The Android Open Source Project (http://source.android.com).
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for Apache Commons code.                              ==
+   =========================================================================
+
+Apache Commons
+Copyright 1999-2006 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for Jakarta Commons Logging.                          ==
+   =========================================================================
+
+Jakarta Commons Logging (JCL)
+Copyright 2005,2006 The Apache Software Foundation.
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Nuance code.                                  ==
+   =========================================================================
+
+These files are Copyright 2007 Nuance Communications, but released under
+the Apache2 License.
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Media Codecs code.                            ==
+   =========================================================================
+
+Media Codecs
+These files are Copyright 1998 - 2009 PacketVideo, but released under
+the Apache2 License.
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the TagSoup code.                                 ==
+   =========================================================================
+
+This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+
+TagSoup is licensed under the Apache License,
+Version 2.0.  You may obtain a copy of this license at
+http://www.apache.org/licenses/LICENSE-2.0 .  You may also have
+additional legal rights not granted by this license.
+
+TagSoup is distributed in the hope that it will be useful, but
+unless required by applicable law or agreed to in writing, TagSoup
+is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+OF ANY KIND, either express or implied; not even the implied warranty
+of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for Additional Codecs code.                           ==
+   =========================================================================
+
+Additional Codecs
+These files are Copyright 2003-2010 VisualOn, but released under
+the Apache2 License.
+
+  =========================================================================
+  ==  NOTICE file corresponding to the section 4 d of                    ==
+  ==  the Apache License, Version 2.0,                                   ==
+  ==  in this case for the Audio Effects code.                           ==
+  =========================================================================
+
+Audio Effects
+These files are Copyright (C) 2004-2010 NXP Software and
+Copyright (C) 2010 The Android Open Source Project, but released under
+the Apache2 License.
+
+
+                               Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+
+
+UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE
+
+Unicode Data Files include all data files under the directories
+http://www.unicode.org/Public/, http://www.unicode.org/reports/,
+and http://www.unicode.org/cldr/data/ . Unicode Software includes any
+source code published in the Unicode Standard or under the directories
+http://www.unicode.org/Public/, http://www.unicode.org/reports/, and
+http://www.unicode.org/cldr/data/.
+
+NOTICE TO USER: Carefully read the following legal agreement. BY
+DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S DATA
+FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"), YOU UNEQUIVOCALLY
+ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE TERMS AND CONDITIONS OF
+THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY,
+DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
+
+COPYRIGHT AND PERMISSION NOTICE
+
+Copyright © 1991-2008 Unicode, Inc. All rights reserved. Distributed
+under the Terms of Use in http://www.unicode.org/copyright.html.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Unicode data files and any associated documentation (the
+"Data Files") or Unicode software and any associated documentation (the
+"Software") to deal in the Data Files or Software without restriction,
+including without limitation the rights to use, copy, modify, merge,
+publish, distribute, and/or sell copies of the Data Files or Software,
+and to permit persons to whom the Data Files or Software are furnished to
+do so, provided that (a) the above copyright notice(s) and this permission
+notice appear with all copies of the Data Files or Software, (b) both the
+above copyright notice(s) and this permission notice appear in associated
+documentation, and (c) there is clear notice in each modified Data File
+or in the Software as well as in the documentation associated with the
+Data File(s) or Software that the data or software has been modified.
+
+THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
+INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
+OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+OR PERFORMANCE OF THE DATA FILES OR SOFTWARE.
+
+Except as contained in this notice, the name of a copyright holder
+shall not be used in advertising or otherwise to promote the sale, use
+or other dealings in these Data Files or Software without prior written
+authorization of the copyright holder.
diff --git a/media/ndk/NdkImagePriv.h b/media/ndk/NdkImagePriv.h
index e9073d5..e0f16da 100644
--- a/media/ndk/NdkImagePriv.h
+++ b/media/ndk/NdkImagePriv.h
@@ -25,7 +25,7 @@
 #include <gui/CpuConsumer.h>
 
 #include "NdkImageReaderPriv.h"
-#include "NdkImage.h"
+#include <media/NdkImage.h>
 
 
 using namespace android;
diff --git a/media/ndk/NdkImageReaderPriv.h b/media/ndk/NdkImageReaderPriv.h
index 35af169..989c1fd 100644
--- a/media/ndk/NdkImageReaderPriv.h
+++ b/media/ndk/NdkImageReaderPriv.h
@@ -19,7 +19,7 @@
 
 #include <inttypes.h>
 
-#include "NdkImageReader.h"
+#include <media/NdkImageReader.h>
 
 #include <utils/List.h>
 #include <utils/Mutex.h>
diff --git a/media/ndk/NdkMediaCodec.cpp b/media/ndk/NdkMediaCodec.cpp
index 6d02cf1..128edba 100644
--- a/media/ndk/NdkMediaCodec.cpp
+++ b/media/ndk/NdkMediaCodec.cpp
@@ -19,8 +19,8 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "NdkMediaCodec"
 
-#include "NdkMediaCodec.h"
-#include "NdkMediaError.h"
+#include <media/NdkMediaCodec.h>
+#include <media/NdkMediaError.h>
 #include "NdkMediaCryptoPriv.h"
 #include "NdkMediaFormatPriv.h"
 
diff --git a/media/ndk/NdkMediaCrypto.cpp b/media/ndk/NdkMediaCrypto.cpp
index 32aabdd..d7193ca 100644
--- a/media/ndk/NdkMediaCrypto.cpp
+++ b/media/ndk/NdkMediaCrypto.cpp
@@ -18,8 +18,8 @@
 #define LOG_TAG "NdkMediaCrypto"
 
 
-#include "NdkMediaCrypto.h"
-#include "NdkMediaCodec.h"
+#include <media/NdkMediaCrypto.h>
+#include <media/NdkMediaCodec.h>
 #include "NdkMediaFormatPriv.h"
 
 
diff --git a/media/ndk/NdkMediaDrm.cpp b/media/ndk/NdkMediaDrm.cpp
index 7a9240b..51143ac 100644
--- a/media/ndk/NdkMediaDrm.cpp
+++ b/media/ndk/NdkMediaDrm.cpp
@@ -17,7 +17,7 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "NdkMediaDrm"
 
-#include "NdkMediaDrm.h"
+#include <media/NdkMediaDrm.h>
 
 #include <cutils/properties.h>
 #include <utils/Log.h>
@@ -29,7 +29,7 @@
 #include <media/stagefright/MediaErrors.h>
 #include <binder/IServiceManager.h>
 #include <media/IMediaDrmService.h>
-#include <ndk/NdkMediaCrypto.h>
+#include <media/NdkMediaCrypto.h>
 
 
 using namespace android;
diff --git a/media/ndk/NdkMediaExtractor.cpp b/media/ndk/NdkMediaExtractor.cpp
index 805eafb..e677d00 100644
--- a/media/ndk/NdkMediaExtractor.cpp
+++ b/media/ndk/NdkMediaExtractor.cpp
@@ -18,8 +18,8 @@
 #define LOG_TAG "NdkMediaExtractor"
 
 
-#include "NdkMediaError.h"
-#include "NdkMediaExtractor.h"
+#include <media/NdkMediaError.h>
+#include <media/NdkMediaExtractor.h>
 #include "NdkMediaFormatPriv.h"
 
 
diff --git a/media/ndk/NdkMediaFormat.cpp b/media/ndk/NdkMediaFormat.cpp
index 5598d5d..ee27520 100644
--- a/media/ndk/NdkMediaFormat.cpp
+++ b/media/ndk/NdkMediaFormat.cpp
@@ -19,7 +19,7 @@
 
 #include <inttypes.h>
 
-#include "NdkMediaFormat.h"
+#include <media/NdkMediaFormat.h>
 
 #include <utils/Log.h>
 #include <utils/StrongPointer.h>
diff --git a/media/ndk/NdkMediaFormatPriv.h b/media/ndk/NdkMediaFormatPriv.h
index 02342d9..c6a6563 100644
--- a/media/ndk/NdkMediaFormatPriv.h
+++ b/media/ndk/NdkMediaFormatPriv.h
@@ -27,7 +27,7 @@
 #ifndef _NDK_MEDIA_FORMAT_PRIV_H
 #define _NDK_MEDIA_FORMAT_PRIV_H
 
-#include <NdkMediaFormat.h>
+#include <media/NdkMediaFormat.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/media/ndk/NdkMediaMuxer.cpp b/media/ndk/NdkMediaMuxer.cpp
index bbf33cd..80a4391 100644
--- a/media/ndk/NdkMediaMuxer.cpp
+++ b/media/ndk/NdkMediaMuxer.cpp
@@ -18,8 +18,8 @@
 #define LOG_TAG "NdkMediaMuxer"
 
 
-#include "NdkMediaMuxer.h"
-#include "NdkMediaCodec.h"
+#include <media/NdkMediaMuxer.h>
+#include <media/NdkMediaCodec.h>
 #include "NdkMediaFormatPriv.h"
 
 
diff --git a/include/ndk/NdkImage.h b/media/ndk/include/media/NdkImage.h
similarity index 100%
rename from include/ndk/NdkImage.h
rename to media/ndk/include/media/NdkImage.h
diff --git a/include/ndk/NdkImageReader.h b/media/ndk/include/media/NdkImageReader.h
similarity index 100%
rename from include/ndk/NdkImageReader.h
rename to media/ndk/include/media/NdkImageReader.h
diff --git a/include/ndk/NdkMediaCodec.h b/media/ndk/include/media/NdkMediaCodec.h
similarity index 100%
rename from include/ndk/NdkMediaCodec.h
rename to media/ndk/include/media/NdkMediaCodec.h
diff --git a/include/ndk/NdkMediaCrypto.h b/media/ndk/include/media/NdkMediaCrypto.h
similarity index 100%
rename from include/ndk/NdkMediaCrypto.h
rename to media/ndk/include/media/NdkMediaCrypto.h
diff --git a/include/ndk/NdkMediaDrm.h b/media/ndk/include/media/NdkMediaDrm.h
similarity index 100%
rename from include/ndk/NdkMediaDrm.h
rename to media/ndk/include/media/NdkMediaDrm.h
diff --git a/include/ndk/NdkMediaError.h b/media/ndk/include/media/NdkMediaError.h
similarity index 100%
rename from include/ndk/NdkMediaError.h
rename to media/ndk/include/media/NdkMediaError.h
diff --git a/include/ndk/NdkMediaExtractor.h b/media/ndk/include/media/NdkMediaExtractor.h
similarity index 100%
rename from include/ndk/NdkMediaExtractor.h
rename to media/ndk/include/media/NdkMediaExtractor.h
diff --git a/include/ndk/NdkMediaFormat.h b/media/ndk/include/media/NdkMediaFormat.h
similarity index 100%
rename from include/ndk/NdkMediaFormat.h
rename to media/ndk/include/media/NdkMediaFormat.h
diff --git a/include/ndk/NdkMediaMuxer.h b/media/ndk/include/media/NdkMediaMuxer.h
similarity index 100%
rename from include/ndk/NdkMediaMuxer.h
rename to media/ndk/include/media/NdkMediaMuxer.h
diff --git a/radio/Android.bp b/radio/Android.bp
new file mode 100644
index 0000000..8e614f2
--- /dev/null
+++ b/radio/Android.bp
@@ -0,0 +1,37 @@
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_shared {
+    name: "libradio",
+
+    srcs: [
+        "Radio.cpp",
+        "IRadio.cpp",
+        "IRadioClient.cpp",
+        "IRadioService.cpp",
+    ],
+
+    shared_libs: [
+        "libcutils",
+        "libutils",
+        "liblog",
+        "libbinder",
+        "libradio_metadata",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+}
diff --git a/radio/Android.mk b/radio/Android.mk
deleted file mode 100644
index be5d283..0000000
--- a/radio/Android.mk
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-	Radio.cpp \
-	IRadio.cpp \
-	IRadioClient.cpp \
-	IRadioService.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-	libutils \
-	liblog \
-	libbinder \
-	libradio_metadata
-
-#LOCAL_C_INCLUDES += \
-	system/media/camera/include \
-	system/media/private/camera/include
-
-LOCAL_MODULE:= libradio
-
-LOCAL_CFLAGS := -Werror -Wall
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/radio/Radio.cpp b/radio/Radio.cpp
index fa39589..9ddd221 100644
--- a/radio/Radio.cpp
+++ b/radio/Radio.cpp
@@ -117,8 +117,8 @@
 
 
 // Radio
-Radio::Radio(radio_handle_t handle, const sp<RadioCallback>& callback)
-    : mHandle(handle), mCallback(callback)
+Radio::Radio(radio_handle_t /*handle*/, const sp<RadioCallback>& callback)
+    : mCallback(callback)
 {
 }
 
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 9f19dfd..2c33fc2 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -41,7 +41,6 @@
 #include <utils/threads.h>
 #include <utils/Atomic.h>
 
-#include <cutils/bitops.h>
 #include <cutils/properties.h>
 
 #include <system/audio.h>
diff --git a/services/audiopolicy/common/managerdefinitions/include/TypeConverter.h b/services/audiopolicy/common/managerdefinitions/include/TypeConverter.h
index 9e705aa..fc95eb9 100644
--- a/services/audiopolicy/common/managerdefinitions/include/TypeConverter.h
+++ b/services/audiopolicy/common/managerdefinitions/include/TypeConverter.h
@@ -49,4 +49,13 @@
 typedef TypeConverter<RouteFlagTraits> RouteFlagTypeConverter;
 typedef TypeConverter<RuleTraits> RuleTypeConverter;
 
+template <>
+const DeviceCategoryConverter::Table DeviceCategoryConverter::mTable[];
+template <>
+const MixTypeConverter::Table MixTypeConverter::mTable[];
+template <>
+const RouteFlagTypeConverter::Table RouteFlagTypeConverter::mTable[];
+template <>
+const RuleTypeConverter::Table RuleTypeConverter::mTable[];
+
 }; // namespace android
diff --git a/services/camera/libcameraservice/Android.mk b/services/camera/libcameraservice/Android.mk
index ef2f3b3..789e2ac 100644
--- a/services/camera/libcameraservice/Android.mk
+++ b/services/camera/libcameraservice/Android.mk
@@ -76,8 +76,7 @@
     android.hardware.camera.common@1.0 \
     android.hardware.camera.provider@2.4 \
     android.hardware.camera.device@1.0 \
-    android.hardware.camera.device@3.2 \
-    android.hidl.manager@1.0
+    android.hardware.camera.device@3.2
 
 LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libbinder libcamera_client libfmq
 
diff --git a/services/mediadrm/Android.mk b/services/mediadrm/Android.mk
index fa3a02b..6b30db6 100644
--- a/services/mediadrm/Android.mk
+++ b/services/mediadrm/Android.mk
@@ -25,19 +25,13 @@
     libbinder \
     liblog \
     libmediadrm \
-    libutils
-ifneq ($(DISABLE_TREBLE_DRM), true)
-LOCAL_SHARED_LIBRARIES += \
+    libutils \
     libhidlbase \
     libhidlmemory \
-    android.hidl.base@1.0 \
+    libhidltransport \
     android.hardware.drm@1.0
-endif
 
 LOCAL_CFLAGS += -Wall -Wextra -Werror
-ifeq ($(DISABLE_TREBLE_DRM), true)
-LOCAL_CFLAGS += -DDISABLE_TREBLE_DRM=1
-endif
 
 LOCAL_MODULE:= mediadrmserver
 
diff --git a/services/mediadrm/MediaDrmService.cpp b/services/mediadrm/MediaDrmService.cpp
index b9ec347..a368c11 100644
--- a/services/mediadrm/MediaDrmService.cpp
+++ b/services/mediadrm/MediaDrmService.cpp
@@ -24,13 +24,8 @@
 #include <binder/IServiceManager.h>
 #include <utils/Log.h>
 
-#ifdef DISABLE_TREBLE_DRM
-#include <media/Crypto.h>
-#include <media/Drm.h>
-#else
 #include <media/CryptoHal.h>
 #include <media/DrmHal.h>
-#endif
 
 namespace android {
 
@@ -40,19 +35,11 @@
 }
 
 sp<ICrypto> MediaDrmService::makeCrypto() {
-#ifdef DISABLE_TREBLE_DRM
-    return new Crypto;
-#else
     return new CryptoHal;
-#endif
 }
 
 sp<IDrm> MediaDrmService::makeDrm() {
-#ifdef DISABLE_TREBLE_DRM
-    return new Drm;
-#else
     return new DrmHal;
-#endif
 }
 
 } // namespace android
diff --git a/soundtrigger/Android.bp b/soundtrigger/Android.bp
new file mode 100644
index 0000000..6178153
--- /dev/null
+++ b/soundtrigger/Android.bp
@@ -0,0 +1,36 @@
+// Copyright 2014 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_shared {
+    name: "libsoundtrigger",
+
+    srcs: [
+        "SoundTrigger.cpp",
+        "ISoundTrigger.cpp",
+        "ISoundTriggerClient.cpp",
+        "ISoundTriggerHwService.cpp",
+    ],
+
+    shared_libs: [
+        "libcutils",
+        "libutils",
+        "liblog",
+        "libbinder",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+}
diff --git a/soundtrigger/Android.mk b/soundtrigger/Android.mk
deleted file mode 100644
index e29adbf..0000000
--- a/soundtrigger/Android.mk
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-	SoundTrigger.cpp \
-	ISoundTrigger.cpp \
-	ISoundTriggerClient.cpp \
-	ISoundTriggerHwService.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-	libutils \
-	liblog \
-	libbinder \
-
-#LOCAL_C_INCLUDES += \
-	system/media/camera/include \
-	system/media/private/camera/include
-
-LOCAL_MODULE:= libsoundtrigger
-
-LOCAL_CFLAGS := -Werror -Wall
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/soundtrigger/SoundTrigger.cpp b/soundtrigger/SoundTrigger.cpp
index e959b83..289b7b1 100644
--- a/soundtrigger/SoundTrigger.cpp
+++ b/soundtrigger/SoundTrigger.cpp
@@ -124,9 +124,9 @@
 }
 
 // SoundTrigger
-SoundTrigger::SoundTrigger(sound_trigger_module_handle_t module,
+SoundTrigger::SoundTrigger(sound_trigger_module_handle_t /*module*/,
                                  const sp<SoundTriggerCallback>& callback)
-    : mModule(module), mCallback(callback)
+    : mCallback(callback)
 {
 }