Merge "aaudio: Fix getFramesWritten() for callback mode." into oc-dev
am: 441f2ccb10

Change-Id: I748c5485cf76a8fd3e6b73696fd6cb74d4774237
diff --git a/Android.bp b/Android.bp
index 53f8bec..c4d6789 100644
--- a/Android.bp
+++ b/Android.bp
@@ -15,6 +15,9 @@
 }
 
 subdirs = [
-    "camera/ndk",
+    "camera",
+    "drm/*",
     "media/*",
+    "radio",
+    "soundtrigger",
 ]
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/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/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/plugins/mock/MockDrmCryptoPlugin.cpp b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp
index c82b9d9..e9ec954 100644
--- a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp
+++ b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp
@@ -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..d65028f 100644
--- a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
+++ b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
@@ -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 120a074..dd510de 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 1282124..7d76f66 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 {
 
@@ -90,17 +87,17 @@
         Configuration()
             : Interpolator<S, T>()
             , 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))
             , 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/libmedia/Android.mk b/media/libmedia/Android.mk
index e2d48a2..3c94049 100644
--- a/media/libmedia/Android.mk
+++ b/media/libmedia/Android.mk
@@ -70,7 +70,6 @@
         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 \
@@ -89,7 +88,7 @@
 LOCAL_HEADER_LIBRARIES := libmedia_headers
 
 # for memory heap analysis
-LOCAL_STATIC_LIBRARIES := libc_malloc_debug_backtrace libc_logging
+LOCAL_STATIC_LIBRARIES := libc_malloc_debug_backtrace
 
 LOCAL_MODULE:= libmedia
 
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 9fe61703..abda34e 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
@@ -1103,7 +1103,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/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 cafedba..e105e3c 100755
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -138,7 +138,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);
         }
@@ -166,7 +166,7 @@
                 --iterations;
             }
             CHECK(it != mTableEntryList.end());
-            CHECK_EQ(iterations, 0);
+            CHECK_EQ(iterations, 0u);
 
             (*it)[(pos % (mElementCapacity * ENTRY_SIZE))] = value;
         }
@@ -187,7 +187,7 @@
                 --iterations;
             }
             CHECK(it != mTableEntryList.end());
-            CHECK_EQ(iterations, 0);
+            CHECK_EQ(iterations, 0u);
 
             value = (*it)[(pos % (mElementCapacity * ENTRY_SIZE))];
             return true;
@@ -235,12 +235,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;
@@ -1270,7 +1270,7 @@
 
         mOffset += length + 4;
     } else {
-        CHECK_LT(length, 65536);
+        CHECK_LT(length, 65536u);
 
         uint8_t x = length >> 8;
         ::write(mFd, &x, 1);
@@ -1330,7 +1330,7 @@
 }
 
 void MPEG4Writer::beginBox(const char *fourcc) {
-    CHECK_EQ(strlen(fourcc), 4);
+    CHECK_EQ(strlen(fourcc), 4u);
 
     mBoxes.push_back(mWriteMoovBoxToMemory?
             mMoovBoxBufferOffset: mOffset);
@@ -1381,7 +1381,7 @@
 }
 
 void MPEG4Writer::writeFourcc(const char *s) {
-    CHECK_EQ(strlen(s), 4);
+    CHECK_EQ(strlen(s), 4u);
     write(s, 1, 4);
 }
 
@@ -3353,10 +3353,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
@@ -3395,10 +3395,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");
 
@@ -3590,7 +3590,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.
@@ -3604,7 +3604,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/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/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.mk b/media/libstagefright/codecs/aacenc/Android.mk
index 527687b..a684342 100644
--- a/media/libstagefright/codecs/aacenc/Android.mk
+++ b/media/libstagefright/codecs/aacenc/Android.mk
@@ -131,8 +131,7 @@
   LOCAL_CFLAGS := -DOSCL_IMPORT_REF=
 
   LOCAL_CFLAGS += -Werror
-  LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow cfi
-  LOCAL_SANITIZE_DIAG := cfi
+  LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow
 
   LOCAL_STATIC_LIBRARIES := \
           libstagefright_aacenc
diff --git a/media/libstagefright/codecs/aacenc/SoftAACEncoder.cpp b/media/libstagefright/codecs/aacenc/SoftAACEncoder.cpp
index 96bbb85..1457242 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;
     }
 
@@ -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/amrwbenc/Android.mk b/media/libstagefright/codecs/amrwbenc/Android.mk
index 262f6c8..15e63f4 100644
--- a/media/libstagefright/codecs/amrwbenc/Android.mk
+++ b/media/libstagefright/codecs/amrwbenc/Android.mk
@@ -102,7 +102,8 @@
 	$(LOCAL_PATH)/inc
 
 LOCAL_CFLAGS += -Werror
-#LOCAL_SANITIZE := signed-integer-overflow
+LOCAL_SANITIZE := cfi
+LOCAL_SANITIZE_DIAG := cfi
 
 include $(BUILD_STATIC_LIBRARY)
 
diff --git a/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk b/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk
index 65d69a2..5a8aa07 100644
--- a/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk
+++ b/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk
@@ -24,7 +24,7 @@
     $(LOCAL_PATH)/../../common \
     $(LOCAL_PATH)/../../common/include
 
+LOCAL_SANITIZE := cfi
+LOCAL_SANITIZE_DIAG := cfi
+
 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/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/m4v_h263/dec/Android.mk b/media/libstagefright/codecs/m4v_h263/dec/Android.mk
index c20dc4d..fa9d11d 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/Android.mk
+++ b/media/libstagefright/codecs/m4v_h263/dec/Android.mk
@@ -47,7 +47,8 @@
 LOCAL_CFLAGS := -DOSCL_EXPORT_REF= -DOSCL_IMPORT_REF=
 
 LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow
+LOCAL_SANITIZE := signed-integer-overflow cfi
+LOCAL_SANITIZE_DIAG := cfi
 
 include $(BUILD_STATIC_LIBRARY)
 
diff --git a/media/libstagefright/codecs/m4v_h263/enc/Android.mk b/media/libstagefright/codecs/m4v_h263/enc/Android.mk
index f950052..8fac0dc 100644
--- a/media/libstagefright/codecs/m4v_h263/enc/Android.mk
+++ b/media/libstagefright/codecs/m4v_h263/enc/Android.mk
@@ -34,7 +34,8 @@
     $(TOP)/frameworks/native/include/media/openmax
 
 LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow
+LOCAL_SANITIZE := signed-integer-overflow cfi
+LOCAL_SANITIZE_DIAG := cfi
 
 include $(BUILD_STATIC_LIBRARY)
 
@@ -88,7 +89,8 @@
         $(LOCAL_PATH)/include
 
 LOCAL_CFLAGS := -DOSCL_EXPORT_REF= -DOSCL_IMPORT_REF= -DBX_RC
-LOCAL_SANITIZE := signed-integer-overflow
+LOCAL_SANITIZE := signed-integer-overflow cfi
+LOCAL_SANITIZE_DIAG := cfi
 
 LOCAL_STATIC_LIBRARIES := \
         libstagefright_m4vh263enc
diff --git a/media/libstagefright/codecs/mp3dec/Android.mk b/media/libstagefright/codecs/mp3dec/Android.mk
index 5d153d1..3b27740 100644
--- a/media/libstagefright/codecs/mp3dec/Android.mk
+++ b/media/libstagefright/codecs/mp3dec/Android.mk
@@ -54,7 +54,8 @@
         -D"OSCL_UNUSED_ARG(x)=(void)(x)"
 
 LOCAL_CFLAGS += -Werror
-LOCAL_SANITIZE := signed-integer-overflow
+LOCAL_SANITIZE := signed-integer-overflow cfi
+LOCAL_SANITIZE_DIAG := cfi
 
 LOCAL_MODULE := libstagefright_mp3dec
 
@@ -102,7 +103,9 @@
         $(LOCAL_PATH)/test/include \
         $(call include-path-for, audio-utils)
 
-LOCAL_SANITIZE := signed-integer-overflow
+LOCAL_SANITIZE := signed-integer-overflow cfi
+LOCAL_SANITIZE_DIAG := cfi
+
 LOCAL_STATIC_LIBRARIES := \
         libstagefright_mp3dec libsndfile
 
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/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.mk b/media/libstagefright/id3/Android.mk
index 827703e..0b8e686 100644
--- a/media/libstagefright/id3/Android.mk
+++ b/media/libstagefright/id3/Android.mk
@@ -33,4 +33,7 @@
 
 LOCAL_MODULE := testid3
 
+LOCAL_SANITIZE := cfi
+LOCAL_SANITIZE_DIAG := cfi
+
 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/omx/Android.mk b/media/libstagefright/omx/Android.mk
index 29e2ccc..a007b41 100644
--- a/media/libstagefright/omx/Android.mk
+++ b/media/libstagefright/omx/Android.mk
@@ -42,8 +42,8 @@
         libdl                                     \
         libhidlbase                               \
         libhidlmemory                             \
+        libhidltransport                          \
         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            \
diff --git a/media/libstagefright/rtsp/Android.mk b/media/libstagefright/rtsp/Android.mk
index 3472e49..02344c9 100644
--- a/media/libstagefright/rtsp/Android.mk
+++ b/media/libstagefright/rtsp/Android.mk
@@ -32,7 +32,8 @@
 endif
 
 LOCAL_CFLAGS += -Werror -Wall
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow
+LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
+LOCAL_SANITIZE_DIAG := cfi
 
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 
@@ -57,7 +58,8 @@
 	$(TOP)/frameworks/native/include/media/openmax
 
 LOCAL_CFLAGS += -Wno-multichar -Werror -Wall
-LOCAL_SANITIZE := signed-integer-overflow
+LOCAL_SANITIZE := signed-integer-overflow cfi
+LOCAL_SANITIZE_DIAG := cfi
 
 LOCAL_MODULE_TAGS := optional
 
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/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/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/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/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)
 {
 }