Merge "Frameworks/base: Wall Werror in libs/hwui"
diff --git a/cmds/backup/backup.cpp b/cmds/backup/backup.cpp
index 03ceffae0..8d9b528 100644
--- a/cmds/backup/backup.cpp
+++ b/cmds/backup/backup.cpp
@@ -75,7 +75,7 @@
                 size_t dataSize;
                 err = reader.ReadEntityHeader(&key, &dataSize);
                 if (err == 0) {
-                    printf("   entity: %s (%d bytes)\n", key.string(), dataSize);
+                    printf("   entity: %s (%zu bytes)\n", key.string(), dataSize);
                 } else {
                     printf("   Error reading entity header\n");
                 }
diff --git a/cmds/idmap/create.cpp b/cmds/idmap/create.cpp
index 28da3d6..7a501a4 100644
--- a/cmds/idmap/create.cpp
+++ b/cmds/idmap/create.cpp
@@ -78,7 +78,7 @@
         if (fstat(idmap_fd, &st) == -1) {
             return true;
         }
-        if (st.st_size < N) {
+        if (st.st_size < static_cast<off_t>(N)) {
             // file is empty or corrupt
             return true;
         }
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 8ea28ec..e0abc24 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -478,7 +478,7 @@
 
     NPE_CHECK_RETURN_ZERO(env, fileDescriptor);
 
-    jint descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
+    int descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
 
     struct stat fdStat;
     if (fstat(descriptor, &fdStat) == -1) {
@@ -486,16 +486,27 @@
         return nullObjectReturn("fstat return -1");
     }
 
-    // Restore the descriptor's offset on exiting this function.
+    // Restore the descriptor's offset on exiting this function. Even though
+    // we dup the descriptor, both the original and dup refer to the same open
+    // file description and changes to the file offset in one impact the other.
     AutoFDSeek autoRestore(descriptor);
 
-    FILE* file = fdopen(descriptor, "r");
+    // Duplicate the descriptor here to prevent leaking memory. A leak occurs
+    // if we only close the file descriptor and not the file object it is used to
+    // create.  If we don't explicitly clean up the file (which in turn closes the
+    // descriptor) the buffers allocated internally by fseek will be leaked.
+    int dupDescriptor = dup(descriptor);
+
+    FILE* file = fdopen(dupDescriptor, "r");
     if (file == NULL) {
+        // cleanup the duplicated descriptor since it will not be closed when the
+        // file is cleaned up (fclose).
+        close(dupDescriptor);
         return nullObjectReturn("Could not open file");
     }
 
     SkAutoTUnref<SkFILEStream> fileStream(new SkFILEStream(file,
-                         SkFILEStream::kCallerRetains_Ownership));
+                         SkFILEStream::kCallerPasses_Ownership));
 
     // Use a buffered stream. Although an SkFILEStream can be rewound, this
     // ensures that SkImageDecoder::Factory never rewinds beyond the
diff --git a/core/jni/android_util_FileObserver.cpp b/core/jni/android_util_FileObserver.cpp
index 0327d8c..b906cfd 100644
--- a/core/jni/android_util_FileObserver.cpp
+++ b/core/jni/android_util_FileObserver.cpp
@@ -29,7 +29,7 @@
 #include <sys/ioctl.h>
 #include <errno.h>
 
-#ifdef HAVE_INOTIFY
+#if defined(__linux__)
 #include <sys/inotify.h>
 #endif
 
@@ -39,29 +39,25 @@
 
 static jint android_os_fileobserver_init(JNIEnv* env, jobject object)
 {
-#ifdef HAVE_INOTIFY
-
-    return (jint)inotify_init();    
-
-#else // HAVE_INOTIFY
-
+#if defined(__linux__)
+    return (jint)inotify_init();
+#else
     return -1;
-
-#endif // HAVE_INOTIFY
+#endif
 }
 
 static void android_os_fileobserver_observe(JNIEnv* env, jobject object, jint fd)
 {
-#ifdef HAVE_INOTIFY
- 
+#if defined(__linux__)
+
     char event_buf[512];
     struct inotify_event* event;
-         
+
     while (1)
     {
         int event_pos = 0;
         int num_bytes = read(fd, event_buf, sizeof(event_buf));
-        
+
         if (num_bytes < (int)sizeof(*event))
         {
             if (errno == EINTR)
@@ -70,14 +66,14 @@
             ALOGE("***** ERROR! android_os_fileobserver_observe() got a short event!");
             return;
         }
-        
+
         while (num_bytes >= (int)sizeof(*event))
         {
             int event_size;
             event = (struct inotify_event *)(event_buf + event_pos);
 
             jstring path = NULL;
-            
+
             if (event->len > 0)
             {
                 path = env->NewStringUTF(event->name);
@@ -98,37 +94,37 @@
             event_pos += event_size;
         }
     }
-    
-#endif // HAVE_INOTIFY
+
+#endif
 }
 
 static jint android_os_fileobserver_startWatching(JNIEnv* env, jobject object, jint fd, jstring pathString, jint mask)
 {
     int res = -1;
-    
-#ifdef HAVE_INOTIFY
-   
+
+#if defined(__linux__)
+
     if (fd >= 0)
     {
         const char* path = env->GetStringUTFChars(pathString, NULL);
-        
+
         res = inotify_add_watch(fd, path, mask);
-        
+
         env->ReleaseStringUTFChars(pathString, path);
     }
 
-#endif // HAVE_INOTIFY
-    
+#endif
+
     return res;
 }
 
 static void android_os_fileobserver_stopWatching(JNIEnv* env, jobject object, jint fd, jint wfd)
 {
-#ifdef HAVE_INOTIFY
+#if defined(__linux__)
 
     inotify_rm_watch((int)fd, (uint32_t)wfd);
 
-#endif // HAVE_INOTIFY
+#endif
 }
 
 static JNINativeMethod sMethods[] = {
@@ -137,7 +133,7 @@
     { "observe", "(I)V", (void*)android_os_fileobserver_observe },
     { "startWatching", "(ILjava/lang/String;I)I", (void*)android_os_fileobserver_startWatching },
     { "stopWatching", "(II)V", (void*)android_os_fileobserver_stopWatching }
-    
+
 };
 
 int register_android_os_FileObserver(JNIEnv* env)
diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp
index 6506190..2b0960f 100644
--- a/core/jni/android_util_Process.cpp
+++ b/core/jni/android_util_Process.cpp
@@ -287,7 +287,8 @@
 void android_os_Process_setThreadScheduler(JNIEnv* env, jclass clazz,
                                               jint tid, jint policy, jint pri)
 {
-#ifdef HAVE_SCHED_SETSCHEDULER
+// linux has sched_setscheduler(), others don't.
+#if defined(__linux__)
     struct sched_param param;
     param.sched_priority = pri;
     int rc = sched_setscheduler(tid, policy, &param);
diff --git a/drm/jni/Android.mk b/drm/jni/Android.mk
index 474b9b2..08c7b95 100644
--- a/drm/jni/Android.mk
+++ b/drm/jni/Android.mk
@@ -39,8 +39,8 @@
     $(TOP)/frameworks/av/include \
     $(TOP)/libcore/include
 
-
-
 LOCAL_MODULE_TAGS := optional
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/drm/jni/android_drm_DrmManagerClient.cpp b/drm/jni/android_drm_DrmManagerClient.cpp
index d321baf..52597e1 100644
--- a/drm/jni/android_drm_DrmManagerClient.cpp
+++ b/drm/jni/android_drm_DrmManagerClient.cpp
@@ -381,7 +381,8 @@
 }
 
 static void android_drm_DrmManagerClient_installDrmEngine(
-            JNIEnv* env, jobject thiz, jint uniqueId, jstring engineFilePath) {
+            JNIEnv* /* env */, jobject /* thiz */, jint /* uniqueId */,
+            jstring /* engineFilePath */) {
     ALOGV("installDrmEngine - Enter");
     //getDrmManagerClient(env, thiz)
     //  ->installDrmEngine(uniqueId, Utility::getStringValue(env, engineFilePath));
@@ -776,7 +777,7 @@
     return result;
 }
 
-jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) {
     JNIEnv* env = NULL;
     jint result = -1;
 
diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h
index f7730f2f..a44975b 100644
--- a/include/androidfw/ResourceTypes.h
+++ b/include/androidfw/ResourceTypes.h
@@ -1773,9 +1773,7 @@
             const char* targetPath, const char* overlayPath,
             void** outData, size_t* outSize) const;
 
-    enum {
-        IDMAP_HEADER_SIZE_BYTES = 4 * sizeof(uint32_t) + 2 * 256,
-    };
+    static const size_t IDMAP_HEADER_SIZE_BYTES = 4 * sizeof(uint32_t) + 2 * 256;
 
     // Retrieve idmap meta-data.
     //
diff --git a/libs/androidfw/BackupData.cpp b/libs/androidfw/BackupData.cpp
index 2b45a70..ba4a4ff 100644
--- a/libs/androidfw/BackupData.cpp
+++ b/libs/androidfw/BackupData.cpp
@@ -45,12 +45,6 @@
 const static int ROUND_UP[4] = { 0, 3, 2, 1 };
 
 static inline size_t
-round_up(size_t n)
-{
-    return n + ROUND_UP[n % 4];
-}
-
-static inline size_t
 padding_extra(size_t n)
 {
     return ROUND_UP[n % 4];
@@ -343,7 +337,7 @@
     }
     int remaining = m_dataEndPos - m_pos;
     if (kIsDebug) {
-        ALOGD("ReadEntityData size=%d m_pos=0x%x m_dataEndPos=0x%x remaining=%d\n",
+        ALOGD("ReadEntityData size=%zu m_pos=0x%zx m_dataEndPos=0x%zx remaining=%d\n",
                 size, m_pos, m_dataEndPos, remaining);
     }
     if (remaining <= 0) {
@@ -353,7 +347,7 @@
         size = remaining;
     }
     if (kIsDebug) {
-        ALOGD("   reading %d bytes", size);
+        ALOGD("   reading %zu bytes", size);
     }
     int amt = read(m_fd, data, size);
     if (amt < 0) {
diff --git a/libs/androidfw/BackupHelpers.cpp b/libs/androidfw/BackupHelpers.cpp
index 36a4cfe..3f82830 100644
--- a/libs/androidfw/BackupHelpers.cpp
+++ b/libs/androidfw/BackupHelpers.cpp
@@ -555,7 +555,7 @@
     snprintf(buf + 124, 12, "%011llo", (isdir) ? 0LL : s.st_size);
 
     // [ 136 :  12 ] last mod time as a UTC time_t
-    snprintf(buf + 136, 12, "%0lo", s.st_mtime);
+    snprintf(buf + 136, 12, "%0lo", (unsigned long)s.st_mtime);
 
     // [ 156 :   1 ] link/file type
     uint8_t type;
@@ -1307,23 +1307,12 @@
         fprintf(stderr, "stat '%s' failed: %s\n", filename, strerror(errno));
         return errno;
     }
-    times[0].tv_sec = st.st_atime;
-    times[1].tv_sec = st.st_mtime;
 
-    // If st_atime is a macro then struct stat64 uses struct timespec
-    // to store the access and modif time values and typically
-    // st_*time_nsec is not defined. In glibc, this is controlled by
-    // __USE_MISC.
-#ifdef __USE_MISC
-#if !defined(st_atime) || defined(st_atime_nsec)
-#error "Check if this __USE_MISC conditional is still needed."
-#endif
+    times[0].tv_sec = st.st_atim.tv_sec;
     times[0].tv_usec = st.st_atim.tv_nsec / 1000;
+
+    times[1].tv_sec = st.st_mtim.tv_sec;
     times[1].tv_usec = st.st_mtim.tv_nsec / 1000;
-#else
-    times[0].tv_usec = st.st_atime_nsec / 1000;
-    times[1].tv_usec = st.st_mtime_nsec / 1000;
-#endif
 
     return 0;
 }
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index e2263d2..679a75f 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -733,8 +733,8 @@
                         }
 #else
                         // We do not want to be in this case when actually running Android.
-                        ALOGW("CREATING STRING CACHE OF %d bytes",
-                                mHeader->stringCount*sizeof(char16_t**));
+                        ALOGW("CREATING STRING CACHE OF %zu bytes",
+                                static_cast<size_t>(mHeader->stringCount*sizeof(char16_t**)));
 #endif
                         mCache = (char16_t**)calloc(mHeader->stringCount, sizeof(char16_t**));
                         if (mCache == NULL) {
diff --git a/libs/storage/Android.mk b/libs/storage/Android.mk
index 7a9dd6c..fae2bf7 100644
--- a/libs/storage/Android.mk
+++ b/libs/storage/Android.mk
@@ -9,4 +9,6 @@
 
 LOCAL_MODULE:= libstorage
 
+LOCAL_CFLAGS += -Wall -Werror
+
 include $(BUILD_STATIC_LIBRARY)
diff --git a/libs/storage/IMountService.cpp b/libs/storage/IMountService.cpp
index 621de18..7ac7737 100644
--- a/libs/storage/IMountService.cpp
+++ b/libs/storage/IMountService.cpp
@@ -207,12 +207,19 @@
             ALOGD("getStorageUsers caught exception %d\n", err);
             return err;
         }
-        const int32_t numUsers = reply.readInt32();
+        int32_t numUsersI = reply.readInt32();
+        uint32_t numUsers;
+        if (numUsersI < 0) {
+            ALOGW("Number of users is negative: %d\n", numUsersI);
+            numUsers = 0;
+        } else {
+            numUsers = static_cast<uint32_t>(numUsersI);
+        }
         *users = (int32_t*)malloc(sizeof(int32_t)*numUsers);
-        for (int i = 0; i < numUsers; i++) {
+        for (size_t i = 0; i < numUsers; i++) {
             **users++ = reply.readInt32();
         }
-        return numUsers;
+        return static_cast<int32_t>(numUsers);
     }
 
     int32_t getVolumeState(const String16& mountPoint)
@@ -546,8 +553,8 @@
     }
 };
 
-IMPLEMENT_META_INTERFACE(MountService, "IMountService");
+IMPLEMENT_META_INTERFACE(MountService, "IMountService")
 
 // ----------------------------------------------------------------------
 
-};
+}
diff --git a/libs/storage/IMountServiceListener.cpp b/libs/storage/IMountServiceListener.cpp
index c98a424..11b53fd 100644
--- a/libs/storage/IMountServiceListener.cpp
+++ b/libs/storage/IMountServiceListener.cpp
@@ -34,7 +34,7 @@
             onUsbMassStorageConnectionChanged(connected);
             reply->writeNoException();
             return NO_ERROR;
-        } break;
+        }
         case TRANSACTION_onStorageStateChanged: {
             CHECK_INTERFACE(IMountServiceListener, data, reply);
             String16 path = data.readString16();
@@ -50,4 +50,4 @@
 }
 // ----------------------------------------------------------------------
 
-};
+}
diff --git a/libs/storage/IMountShutdownObserver.cpp b/libs/storage/IMountShutdownObserver.cpp
index 1a6fdee..a74a768 100644
--- a/libs/storage/IMountShutdownObserver.cpp
+++ b/libs/storage/IMountShutdownObserver.cpp
@@ -33,11 +33,11 @@
             onShutDownComplete(statusCode);
             reply->writeNoException();
             return NO_ERROR;
-        } break;
+        }
         default:
             return BBinder::onTransact(code, data, reply, flags);
     }
 }
 // ----------------------------------------------------------------------
 
-};
+}
diff --git a/libs/storage/IObbActionListener.cpp b/libs/storage/IObbActionListener.cpp
index eaa211e..9656e65 100644
--- a/libs/storage/IObbActionListener.cpp
+++ b/libs/storage/IObbActionListener.cpp
@@ -30,10 +30,11 @@
         : BpInterface<IObbActionListener>(impl)
     { }
 
-    virtual void onObbResult(const String16& filename, const int32_t nonce, const int32_t state) { }
+    virtual void onObbResult(const String16& /* filename */, const int32_t /* nonce */,
+                             const int32_t /* state */) { }
 };
 
-IMPLEMENT_META_INTERFACE(ObbActionListener, "IObbActionListener");
+IMPLEMENT_META_INTERFACE(ObbActionListener, "IObbActionListener")
 
 // ----------------------------------------------------------------------
 
@@ -49,7 +50,7 @@
             onObbResult(filename, nonce, state);
             reply->writeNoException();
             return NO_ERROR;
-        } break;
+        }
         default:
             return BBinder::onTransact(code, data, reply, flags);
     }
@@ -57,4 +58,4 @@
 
 // ----------------------------------------------------------------------
 
-};
+}
diff --git a/media/jni/Android.mk b/media/jni/Android.mk
index 90fe695..4ebbe26 100644
--- a/media/jni/Android.mk
+++ b/media/jni/Android.mk
@@ -64,7 +64,7 @@
     $(PV_INCLUDES) \
     $(JNI_H_INCLUDE)
 
-LOCAL_CFLAGS +=
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
 
 LOCAL_MODULE:= libmedia_jni
 
diff --git a/media/jni/android_media_AmrInputStream.cpp b/media/jni/android_media_AmrInputStream.cpp
index 3df6530..afb5d5c 100644
--- a/media/jni/android_media_AmrInputStream.cpp
+++ b/media/jni/android_media_AmrInputStream.cpp
@@ -50,7 +50,7 @@
 };
 
 static jlong android_media_AmrInputStream_GsmAmrEncoderNew
-        (JNIEnv *env, jclass clazz) {
+        (JNIEnv *env, jclass /* clazz */) {
     GsmAmrEncoderState* gae = new GsmAmrEncoderState();
     if (gae == NULL) {
         jniThrowRuntimeException(env, "Out of memory");
@@ -59,7 +59,7 @@
 }
 
 static void android_media_AmrInputStream_GsmAmrEncoderInitialize
-        (JNIEnv *env, jclass clazz, jlong gae) {
+        (JNIEnv *env, jclass /* clazz */, jlong gae) {
     GsmAmrEncoderState *state = (GsmAmrEncoderState *) gae;
     int32_t nResult = AMREncodeInit(&state->mEncState, &state->mSidState, false);
     if (nResult != OK) {
@@ -69,7 +69,7 @@
 }
 
 static jint android_media_AmrInputStream_GsmAmrEncoderEncode
-        (JNIEnv *env, jclass clazz,
+        (JNIEnv *env, jclass /* clazz */,
          jlong gae, jbyteArray pcm, jint pcmOffset, jbyteArray amr, jint amrOffset) {
 
     jbyte inBuf[BYTES_PER_FRAME];
@@ -105,7 +105,7 @@
 }
 
 static void android_media_AmrInputStream_GsmAmrEncoderCleanup
-        (JNIEnv *env, jclass clazz, jlong gae) {
+        (JNIEnv* /* env */, jclass /* clazz */, jlong gae) {
     GsmAmrEncoderState *state = (GsmAmrEncoderState *) gae;
     AMREncodeExit(&state->mEncState, &state->mSidState);
     state->mEncState = NULL;
@@ -113,7 +113,7 @@
 }
 
 static void android_media_AmrInputStream_GsmAmrEncoderDelete
-        (JNIEnv *env, jclass clazz, jlong gae) {
+        (JNIEnv* /* env */, jclass /* clazz */, jlong gae) {
     delete (GsmAmrEncoderState*)gae;
 }
 
diff --git a/media/jni/android_media_ImageReader.cpp b/media/jni/android_media_ImageReader.cpp
index aaff9a2..45377ad 100644
--- a/media/jni/android_media_ImageReader.cpp
+++ b/media/jni/android_media_ImageReader.cpp
@@ -502,7 +502,6 @@
         case HAL_PIXEL_FORMAT_Y8:
             // Single plane 8bpp data.
             ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
-            pixelStride;
             break;
         case HAL_PIXEL_FORMAT_YV12:
             pixelStride = 1;
diff --git a/media/jni/android_media_MediaCodecList.cpp b/media/jni/android_media_MediaCodecList.cpp
index 12eb7d2..f8c349b 100644
--- a/media/jni/android_media_MediaCodecList.cpp
+++ b/media/jni/android_media_MediaCodecList.cpp
@@ -42,7 +42,7 @@
 }
 
 static jint android_media_MediaCodecList_getCodecCount(
-        JNIEnv *env, jobject thiz) {
+        JNIEnv *env, jobject /* thiz */) {
     sp<IMediaCodecList> mcl = getCodecList(env);
     if (mcl == NULL) {
         // Runtime exception already pending.
@@ -52,7 +52,7 @@
 }
 
 static jstring android_media_MediaCodecList_getCodecName(
-        JNIEnv *env, jobject thiz, jint index) {
+        JNIEnv *env, jobject /* thiz */, jint index) {
     sp<IMediaCodecList> mcl = getCodecList(env);
     if (mcl == NULL) {
         // Runtime exception already pending.
@@ -70,7 +70,7 @@
 }
 
 static jint android_media_MediaCodecList_findCodecByName(
-        JNIEnv *env, jobject thiz, jstring name) {
+        JNIEnv *env, jobject /* thiz */, jstring name) {
     if (name == NULL) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
         return -ENOENT;
@@ -95,7 +95,7 @@
 }
 
 static jboolean android_media_MediaCodecList_isEncoder(
-        JNIEnv *env, jobject thiz, jint index) {
+        JNIEnv *env, jobject /* thiz */, jint index) {
     sp<IMediaCodecList> mcl = getCodecList(env);
     if (mcl == NULL) {
         // Runtime exception already pending.
@@ -112,7 +112,7 @@
 }
 
 static jarray android_media_MediaCodecList_getSupportedTypes(
-        JNIEnv *env, jobject thiz, jint index) {
+        JNIEnv *env, jobject /* thiz */, jint index) {
     sp<IMediaCodecList> mcl = getCodecList(env);
     if (mcl == NULL) {
         // Runtime exception already pending.
@@ -144,7 +144,7 @@
 }
 
 static jobject android_media_MediaCodecList_getCodecCapabilities(
-        JNIEnv *env, jobject thiz, jint index, jstring type) {
+        JNIEnv *env, jobject /* thiz */, jint index, jstring type) {
     if (type == NULL) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
         return NULL;
@@ -262,7 +262,7 @@
     return caps;
 }
 
-static void android_media_MediaCodecList_native_init(JNIEnv *env) {
+static void android_media_MediaCodecList_native_init(JNIEnv* /* env */) {
 }
 
 static JNINativeMethod gMethods[] = {
diff --git a/media/jni/android_media_MediaCrypto.cpp b/media/jni/android_media_MediaCrypto.cpp
index a6f8dcd..d2216fb 100644
--- a/media/jni/android_media_MediaCrypto.cpp
+++ b/media/jni/android_media_MediaCrypto.cpp
@@ -224,7 +224,7 @@
 }
 
 static jboolean android_media_MediaCrypto_isCryptoSchemeSupportedNative(
-        JNIEnv *env, jobject thiz, jbyteArray uuidObj) {
+        JNIEnv *env, jobject /* thiz */, jbyteArray uuidObj) {
     jsize uuidLength = env->GetArrayLength(uuidObj);
 
     if (uuidLength != 16) {
diff --git a/media/jni/android_media_MediaDrm.cpp b/media/jni/android_media_MediaDrm.cpp
index 0fed27e..91eb499 100644
--- a/media/jni/android_media_MediaDrm.cpp
+++ b/media/jni/android_media_MediaDrm.cpp
@@ -667,7 +667,7 @@
 }
 
 static jboolean android_media_MediaDrm_isCryptoSchemeSupportedNative(
-    JNIEnv *env, jobject thiz, jbyteArray uuidObj, jstring jmimeType) {
+    JNIEnv *env, jobject /* thiz */, jbyteArray uuidObj, jstring jmimeType) {
 
     if (uuidObj == NULL) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
@@ -1137,7 +1137,7 @@
 }
 
 static void android_media_MediaDrm_setCipherAlgorithmNative(
-    JNIEnv *env, jobject thiz, jobject jdrm, jbyteArray jsessionId,
+    JNIEnv *env, jobject /* thiz */, jobject jdrm, jbyteArray jsessionId,
     jstring jalgorithm) {
 
     sp<IDrm> drm = GetDrm(env, jdrm);
@@ -1161,7 +1161,7 @@
 }
 
 static void android_media_MediaDrm_setMacAlgorithmNative(
-    JNIEnv *env, jobject thiz, jobject jdrm, jbyteArray jsessionId,
+    JNIEnv *env, jobject /* thiz */, jobject jdrm, jbyteArray jsessionId,
     jstring jalgorithm) {
 
     sp<IDrm> drm = GetDrm(env, jdrm);
@@ -1186,7 +1186,7 @@
 
 
 static jbyteArray android_media_MediaDrm_encryptNative(
-    JNIEnv *env, jobject thiz, jobject jdrm, jbyteArray jsessionId,
+    JNIEnv *env, jobject /* thiz */, jobject jdrm, jbyteArray jsessionId,
     jbyteArray jkeyId, jbyteArray jinput, jbyteArray jiv) {
 
     sp<IDrm> drm = GetDrm(env, jdrm);
@@ -1217,7 +1217,7 @@
 }
 
 static jbyteArray android_media_MediaDrm_decryptNative(
-    JNIEnv *env, jobject thiz, jobject jdrm, jbyteArray jsessionId,
+    JNIEnv *env, jobject /* thiz */, jobject jdrm, jbyteArray jsessionId,
     jbyteArray jkeyId, jbyteArray jinput, jbyteArray jiv) {
 
     sp<IDrm> drm = GetDrm(env, jdrm);
@@ -1247,7 +1247,7 @@
 }
 
 static jbyteArray android_media_MediaDrm_signNative(
-    JNIEnv *env, jobject thiz, jobject jdrm, jbyteArray jsessionId,
+    JNIEnv *env, jobject /* thiz */, jobject jdrm, jbyteArray jsessionId,
     jbyteArray jkeyId, jbyteArray jmessage) {
 
     sp<IDrm> drm = GetDrm(env, jdrm);
@@ -1277,7 +1277,7 @@
 }
 
 static jboolean android_media_MediaDrm_verifyNative(
-    JNIEnv *env, jobject thiz, jobject jdrm, jbyteArray jsessionId,
+    JNIEnv *env, jobject /* thiz */, jobject jdrm, jbyteArray jsessionId,
     jbyteArray jkeyId, jbyteArray jmessage, jbyteArray jsignature) {
 
     sp<IDrm> drm = GetDrm(env, jdrm);
@@ -1306,7 +1306,7 @@
 
 
 static jbyteArray android_media_MediaDrm_signRSANative(
-    JNIEnv *env, jobject thiz, jobject jdrm, jbyteArray jsessionId,
+    JNIEnv *env, jobject /* thiz */, jobject jdrm, jbyteArray jsessionId,
     jstring jalgorithm, jbyteArray jwrappedKey, jbyteArray jmessage) {
 
     sp<IDrm> drm = GetDrm(env, jdrm);
diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp
index fbe5340..dae6d3b 100644
--- a/media/jni/android_media_MediaMetadataRetriever.cpp
+++ b/media/jni/android_media_MediaMetadataRetriever.cpp
@@ -77,7 +77,6 @@
 static void setRetriever(JNIEnv* env, jobject thiz, MediaMetadataRetriever* retriever)
 {
     // No lock is needed, since it is called internally by other methods that are protected
-    MediaMetadataRetriever *old = (MediaMetadataRetriever*) env->GetLongField(thiz, fields.context);
     env->SetLongField(thiz, fields.context, (jlong) retriever);
 }
 
diff --git a/media/jni/android_media_MediaMuxer.cpp b/media/jni/android_media_MediaMuxer.cpp
index 3fef446f..f234a1b 100644
--- a/media/jni/android_media_MediaMuxer.cpp
+++ b/media/jni/android_media_MediaMuxer.cpp
@@ -41,7 +41,7 @@
 using namespace android;
 
 static jint android_media_MediaMuxer_addTrack(
-        JNIEnv *env, jclass clazz, jlong nativeObject, jobjectArray keys,
+        JNIEnv *env, jclass /* clazz */, jlong nativeObject, jobjectArray keys,
         jobjectArray values) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
@@ -71,7 +71,7 @@
 }
 
 static void android_media_MediaMuxer_writeSampleData(
-        JNIEnv *env, jclass clazz, jlong nativeObject, jint trackIndex,
+        JNIEnv *env, jclass /* clazz */, jlong nativeObject, jint trackIndex,
         jobject byteBuf, jint offset, jint size, jlong timeUs, jint flags) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
@@ -146,7 +146,7 @@
 }
 
 static void android_media_MediaMuxer_setOrientationHint(
-        JNIEnv *env, jclass clazz, jlong nativeObject, jint degrees) {
+        JNIEnv *env, jclass /* clazz */, jlong nativeObject, jint degrees) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -164,7 +164,7 @@
 }
 
 static void android_media_MediaMuxer_setLocation(
-        JNIEnv *env, jclass clazz, jlong nativeObject, jint latitude, jint longitude) {
+        JNIEnv *env, jclass /* clazz */, jlong nativeObject, jint latitude, jint longitude) {
     MediaMuxer* muxer = reinterpret_cast<MediaMuxer *>(nativeObject);
 
     status_t res = muxer->setLocation(latitude, longitude);
@@ -175,7 +175,7 @@
     }
 }
 
-static void android_media_MediaMuxer_start(JNIEnv *env, jclass clazz,
+static void android_media_MediaMuxer_start(JNIEnv *env, jclass /* clazz */,
                                            jlong nativeObject) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
@@ -193,7 +193,7 @@
 
 }
 
-static void android_media_MediaMuxer_stop(JNIEnv *env, jclass clazz,
+static void android_media_MediaMuxer_stop(JNIEnv *env, jclass /* clazz */,
                                           jlong nativeObject) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
@@ -212,7 +212,7 @@
 }
 
 static void android_media_MediaMuxer_native_release(
-        JNIEnv *env, jclass clazz, jlong nativeObject) {
+        JNIEnv* /* env */, jclass clazz, jlong nativeObject) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer != NULL) {
         muxer->decStrong(clazz);
diff --git a/media/jni/android_media_MediaProfiles.cpp b/media/jni/android_media_MediaProfiles.cpp
index 007fc14..ca9db91 100644
--- a/media/jni/android_media_MediaProfiles.cpp
+++ b/media/jni/android_media_MediaProfiles.cpp
@@ -34,7 +34,7 @@
 // This function is called from a static block in MediaProfiles.java class,
 // which won't run until the first time an instance of this class is used.
 static void
-android_media_MediaProfiles_native_init(JNIEnv *env)
+android_media_MediaProfiles_native_init(JNIEnv* /* env */)
 {
     ALOGV("native_init");
     Mutex::Autolock lock(sLock);
@@ -45,14 +45,14 @@
 }
 
 static jint
-android_media_MediaProfiles_native_get_num_file_formats(JNIEnv *env, jobject thiz)
+android_media_MediaProfiles_native_get_num_file_formats(JNIEnv* /* env */, jobject /* thiz */)
 {
     ALOGV("native_get_num_file_formats");
     return (jint) sProfiles->getOutputFileFormats().size();
 }
 
 static jint
-android_media_MediaProfiles_native_get_file_format(JNIEnv *env, jobject thiz, jint index)
+android_media_MediaProfiles_native_get_file_format(JNIEnv *env, jobject /* thiz */, jint index)
 {
     ALOGV("native_get_file_format: %d", index);
     Vector<output_format> formats = sProfiles->getOutputFileFormats();
@@ -65,14 +65,15 @@
 }
 
 static jint
-android_media_MediaProfiles_native_get_num_video_encoders(JNIEnv *env, jobject thiz)
+android_media_MediaProfiles_native_get_num_video_encoders(JNIEnv* /* env */, jobject /* thiz */)
 {
     ALOGV("native_get_num_video_encoders");
     return sProfiles->getVideoEncoders().size();
 }
 
 static jobject
-android_media_MediaProfiles_native_get_video_encoder_cap(JNIEnv *env, jobject thiz, jint index)
+android_media_MediaProfiles_native_get_video_encoder_cap(JNIEnv *env, jobject /* thiz */,
+                                                         jint index)
 {
     ALOGV("native_get_video_encoder_cap: %d", index);
     Vector<video_encoder> encoders = sProfiles->getVideoEncoders();
@@ -116,14 +117,15 @@
 }
 
 static jint
-android_media_MediaProfiles_native_get_num_audio_encoders(JNIEnv *env, jobject thiz)
+android_media_MediaProfiles_native_get_num_audio_encoders(JNIEnv* /* env */, jobject /* thiz */)
 {
     ALOGV("native_get_num_audio_encoders");
     return (jint) sProfiles->getAudioEncoders().size();
 }
 
 static jobject
-android_media_MediaProfiles_native_get_audio_encoder_cap(JNIEnv *env, jobject thiz, jint index)
+android_media_MediaProfiles_native_get_audio_encoder_cap(JNIEnv *env, jobject /* thiz */,
+                                                         jint index)
 {
     ALOGV("native_get_audio_encoder_cap: %d", index);
     Vector<audio_encoder> encoders = sProfiles->getAudioEncoders();
@@ -172,7 +174,8 @@
 }
 
 static jobject
-android_media_MediaProfiles_native_get_camcorder_profile(JNIEnv *env, jobject thiz, jint id, jint quality)
+android_media_MediaProfiles_native_get_camcorder_profile(JNIEnv *env, jobject /* thiz */, jint id,
+                                                         jint quality)
 {
     ALOGV("native_get_camcorder_profile: %d %d", id, quality);
     if (!isCamcorderQualityKnown(quality)) {
@@ -221,7 +224,8 @@
 }
 
 static jboolean
-android_media_MediaProfiles_native_has_camcorder_profile(JNIEnv *env, jobject thiz, jint id, jint quality)
+android_media_MediaProfiles_native_has_camcorder_profile(JNIEnv* /* env */, jobject /* thiz */,
+                                                         jint id, jint quality)
 {
     ALOGV("native_has_camcorder_profile: %d %d", id, quality);
     if (!isCamcorderQualityKnown(quality)) {
@@ -233,14 +237,15 @@
 }
 
 static jint
-android_media_MediaProfiles_native_get_num_video_decoders(JNIEnv *env, jobject thiz)
+android_media_MediaProfiles_native_get_num_video_decoders(JNIEnv* /* env */, jobject /* thiz */)
 {
     ALOGV("native_get_num_video_decoders");
     return (jint) sProfiles->getVideoDecoders().size();
 }
 
 static jint
-android_media_MediaProfiles_native_get_video_decoder_type(JNIEnv *env, jobject thiz, jint index)
+android_media_MediaProfiles_native_get_video_decoder_type(JNIEnv *env, jobject /* thiz */,
+                                                          jint index)
 {
     ALOGV("native_get_video_decoder_type: %d", index);
     Vector<video_decoder> decoders = sProfiles->getVideoDecoders();
@@ -254,14 +259,15 @@
 }
 
 static jint
-android_media_MediaProfiles_native_get_num_audio_decoders(JNIEnv *env, jobject thiz)
+android_media_MediaProfiles_native_get_num_audio_decoders(JNIEnv* /* env */, jobject /* thiz */)
 {
     ALOGV("native_get_num_audio_decoders");
     return (jint) sProfiles->getAudioDecoders().size();
 }
 
 static jint
-android_media_MediaProfiles_native_get_audio_decoder_type(JNIEnv *env, jobject thiz, jint index)
+android_media_MediaProfiles_native_get_audio_decoder_type(JNIEnv *env, jobject /* thiz */,
+                                                          jint index)
 {
     ALOGV("native_get_audio_decoder_type: %d", index);
     Vector<audio_decoder> decoders = sProfiles->getAudioDecoders();
@@ -275,14 +281,17 @@
 }
 
 static jint
-android_media_MediaProfiles_native_get_num_image_encoding_quality_levels(JNIEnv *env, jobject thiz, jint cameraId)
+android_media_MediaProfiles_native_get_num_image_encoding_quality_levels(JNIEnv* /* env */,
+                                                                         jobject /* thiz */,
+                                                                         jint cameraId)
 {
     ALOGV("native_get_num_image_encoding_quality_levels");
     return (jint) sProfiles->getImageEncodingQualityLevels(cameraId).size();
 }
 
 static jint
-android_media_MediaProfiles_native_get_image_encoding_quality_level(JNIEnv *env, jobject thiz, jint cameraId, jint index)
+android_media_MediaProfiles_native_get_image_encoding_quality_level(JNIEnv *env, jobject /* thiz */,
+                                                                    jint cameraId, jint index)
 {
     ALOGV("native_get_image_encoding_quality_level");
     Vector<int> levels = sProfiles->getImageEncodingQualityLevels(cameraId);
diff --git a/media/jni/android_media_MediaScanner.cpp b/media/jni/android_media_MediaScanner.cpp
index 321c2e3..1a9384e 100644
--- a/media/jni/android_media_MediaScanner.cpp
+++ b/media/jni/android_media_MediaScanner.cpp
@@ -360,7 +360,6 @@
         env->SetByteArrayRegion(array, 0, mediaAlbumArt->size(), data);
     }
 
-done:
     free(mediaAlbumArt);
     // if NewByteArray() returned NULL, an out-of-memory
     // exception will have been raised. I just want to
diff --git a/media/jni/android_media_ResampleInputStream.cpp b/media/jni/android_media_ResampleInputStream.cpp
index d5a4a17..1549a30 100644
--- a/media/jni/android_media_ResampleInputStream.cpp
+++ b/media/jni/android_media_ResampleInputStream.cpp
@@ -73,7 +73,7 @@
 static const int BUF_SIZE = 2048;
 
 
-static void android_media_ResampleInputStream_fir21(JNIEnv *env, jclass clazz,
+static void android_media_ResampleInputStream_fir21(JNIEnv *env, jclass /* clazz */,
          jbyteArray jIn,  jint jInOffset,
          jbyteArray jOut, jint jOutOffset,
          jint jNpoints) {
diff --git a/media/jni/android_media_Utils.cpp b/media/jni/android_media_Utils.cpp
index 54c5e9b..ea33a2f 100644
--- a/media/jni/android_media_Utils.cpp
+++ b/media/jni/android_media_Utils.cpp
@@ -136,8 +136,7 @@
     jstring keyObj = env->NewStringUTF(key);
     jobject valueObj = makeIntegerObject(env, value);
 
-    jobject res = env->CallObjectMethod(
-            hashMapObj, hashMapPutID, keyObj, valueObj);
+    env->CallObjectMethod(hashMapObj, hashMapPutID, keyObj, valueObj);
 
     env->DeleteLocalRef(valueObj); valueObj = NULL;
     env->DeleteLocalRef(keyObj); keyObj = NULL;
@@ -266,8 +265,7 @@
         if (valueObj != NULL) {
             jstring keyObj = env->NewStringUTF(key);
 
-            jobject res = env->CallObjectMethod(
-                    hashMap, hashMapPutID, keyObj, valueObj);
+            env->CallObjectMethod(hashMap, hashMapPutID, keyObj, valueObj);
 
             env->DeleteLocalRef(keyObj); keyObj = NULL;
             env->DeleteLocalRef(valueObj); valueObj = NULL;
diff --git a/media/jni/android_mtp_MtpDatabase.cpp b/media/jni/android_mtp_MtpDatabase.cpp
index 19b54a6..1a0675e 100644
--- a/media/jni/android_mtp_MtpDatabase.cpp
+++ b/media/jni/android_mtp_MtpDatabase.cpp
@@ -761,7 +761,7 @@
     return result;
 }
 
-static void foreachentry(ExifEntry *entry, void *user) {
+static void foreachentry(ExifEntry *entry, void* /* user */) {
     char buf[1024];
     ALOGI("entry %x, format %d, size %d: %s",
             entry->tag, entry->format, entry->size, exif_entry_get_value(entry, buf, sizeof(buf)));
@@ -779,7 +779,6 @@
 
 MtpResponseCode MyMtpDatabase::getObjectInfo(MtpObjectHandle handle,
                                             MtpObjectInfo& info) {
-    char            date[20];
     MtpString       path;
     int64_t         length;
     MtpObjectFormat format;
@@ -807,9 +806,11 @@
     info.mDateModified = longValues[1];
     env->ReleaseLongArrayElements(mLongBuffer, longValues, 0);
 
-//    info.mAssociationType = (format == MTP_FORMAT_ASSOCIATION ?
-//                            MTP_ASSOCIATION_TYPE_GENERIC_FOLDER :
-//                            MTP_ASSOCIATION_TYPE_UNDEFINED);
+    if ((false)) {
+        info.mAssociationType = (format == MTP_FORMAT_ASSOCIATION ?
+                                MTP_ASSOCIATION_TYPE_GENERIC_FOLDER :
+                                MTP_ASSOCIATION_TYPE_UNDEFINED);
+    }
     info.mAssociationType = MTP_ASSOCIATION_TYPE_UNDEFINED;
 
     jchar* str = env->GetCharArrayElements(mStringBuffer, 0);
@@ -822,7 +823,9 @@
 
         ExifData *exifdata = exif_data_new_from_file(path);
         if (exifdata) {
-            //exif_data_foreach_content(exifdata, foreachcontent, NULL);
+            if ((false)) {
+                exif_data_foreach_content(exifdata, foreachcontent, NULL);
+            }
 
             // XXX get this from exif, or parse jpeg header instead?
             ExifEntry *w = exif_content_get_entry(
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp
index 8e013a0..fb15770 100644
--- a/media/jni/android_mtp_MtpDevice.cpp
+++ b/media/jni/android_mtp_MtpDevice.cpp
@@ -91,14 +91,6 @@
     return (MtpDevice*)env->GetLongField(javaDevice, field_context);
 }
 
-static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
-    if (env->ExceptionCheck()) {
-        ALOGE("An exception was thrown by callback '%s'.", methodName);
-        LOGE_EX(env);
-        env->ExceptionClear();
-    }
-}
-
 // ----------------------------------------------------------------------------
 
 static jboolean
diff --git a/media/jni/audioeffect/Android.mk b/media/jni/audioeffect/Android.mk
index 3b1fb19..5c22c9b 100644
--- a/media/jni/audioeffect/Android.mk
+++ b/media/jni/audioeffect/Android.mk
@@ -2,20 +2,22 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-	android_media_AudioEffect.cpp \
-	android_media_Visualizer.cpp
+    android_media_AudioEffect.cpp \
+    android_media_Visualizer.cpp
 
 LOCAL_SHARED_LIBRARIES := \
-	liblog \
-	libcutils \
-	libutils \
-	libandroid_runtime \
-	libnativehelper \
-	libmedia
+    liblog \
+    libcutils \
+    libutils \
+    libandroid_runtime \
+    libnativehelper \
+    libmedia
 
 LOCAL_C_INCLUDES := \
-	$(call include-path-for, audio-effects)
+    $(call include-path-for, audio-effects)
 
 LOCAL_MODULE:= libaudioeffect_jni
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/media/jni/audioeffect/android_media_Visualizer.cpp b/media/jni/audioeffect/android_media_Visualizer.cpp
index 8463d94..9183ad2 100644
--- a/media/jni/audioeffect/android_media_Visualizer.cpp
+++ b/media/jni/audioeffect/android_media_Visualizer.cpp
@@ -162,10 +162,6 @@
         uint8_t *fft,
         uint32_t samplingrate) {
 
-    int arg1 = 0;
-    int arg2 = 0;
-    size_t size;
-
     visualizer_callback_cookie *callbackInfo = (visualizer_callback_cookie *)user;
     JNIEnv *env = AndroidRuntime::getJNIEnv();
 
@@ -486,7 +482,7 @@
 }
 
 static jintArray
-android_media_visualizer_native_getCaptureSizeRange(JNIEnv *env, jobject thiz)
+android_media_visualizer_native_getCaptureSizeRange(JNIEnv *env, jobject /* thiz */)
 {
     jintArray jRange = env->NewIntArray(2);
     jint *nRange = env->GetIntArrayElements(jRange, NULL);
@@ -498,7 +494,7 @@
 }
 
 static jint
-android_media_visualizer_native_getMaxCaptureRate(JNIEnv *env, jobject thiz)
+android_media_visualizer_native_getMaxCaptureRate(JNIEnv* /* env */, jobject /* thiz */)
 {
     return (jint) Visualizer::getMaxCaptureRate();
 }
diff --git a/media/jni/soundpool/Android.mk b/media/jni/soundpool/Android.mk
index ed8d7c1..3382512 100644
--- a/media/jni/soundpool/Android.mk
+++ b/media/jni/soundpool/Android.mk
@@ -2,16 +2,18 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-	android_media_SoundPool_SoundPoolImpl.cpp
+    android_media_SoundPool_SoundPoolImpl.cpp
 
 LOCAL_SHARED_LIBRARIES := \
-	liblog \
-	libcutils \
-	libutils \
-	libandroid_runtime \
-	libnativehelper \
-	libmedia
+    liblog \
+    libcutils \
+    libutils \
+    libandroid_runtime \
+    libnativehelper \
+    libmedia
 
 LOCAL_MODULE:= libsoundpool
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp b/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp
index 89b2893..ce20e52 100644
--- a/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp
+++ b/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp
@@ -312,7 +312,7 @@
 
 static const char* const kClassPathName = "android/media/SoundPool$SoundPoolImpl";
 
-jint JNI_OnLoad(JavaVM* vm, void* reserved)
+jint JNI_OnLoad(JavaVM* vm, void* /* reserved */)
 {
     JNIEnv* env = NULL;
     jint result = -1;
diff --git a/media/mca/filterfw/jni/Android.mk b/media/mca/filterfw/jni/Android.mk
index 5aa5af1..67337e0 100644
--- a/media/mca/filterfw/jni/Android.mk
+++ b/media/mca/filterfw/jni/Android.mk
@@ -38,8 +38,8 @@
 
 # Also need the JNI headers.
 LOCAL_C_INCLUDES += \
-	$(JNI_H_INCLUDE) \
-	$(LOCAL_PATH)/..
+    $(JNI_H_INCLUDE) \
+    $(LOCAL_PATH)/..
 
 # Don't prelink this library.  For more efficient code, you may want
 # to add this library to the prelink map and set this to true. However,
@@ -47,5 +47,7 @@
 # part of a system image.
 LOCAL_PRELINK_MODULE := false
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_STATIC_LIBRARY)
 
diff --git a/media/mca/filterfw/jni/jni_gl_environment.cpp b/media/mca/filterfw/jni/jni_gl_environment.cpp
index 6da7b7c..5f00739 100644
--- a/media/mca/filterfw/jni/jni_gl_environment.cpp
+++ b/media/mca/filterfw/jni/jni_gl_environment.cpp
@@ -20,8 +20,8 @@
 
 #include "jni/jni_gl_environment.h"
 #include "jni/jni_util.h"
-#include <media/mediarecorder.h>
 #include "native/core/gl_env.h"
+#include <media/mediarecorder.h>
 
 #include <gui/IGraphicBufferProducer.h>
 #include <gui/Surface.h>
@@ -92,8 +92,8 @@
   return gl_env ? ToJBool(gl_env->IsContextActive()) : JNI_FALSE;
 }
 
-jboolean Java_android_filterfw_core_GLEnvironment_nativeIsAnyContextActive(JNIEnv* env,
-                                                                           jclass clazz) {
+jboolean Java_android_filterfw_core_GLEnvironment_nativeIsAnyContextActive(JNIEnv* /* env */,
+                                                                           jclass /* clazz */) {
   return ToJBool(GLEnv::IsAnyContextActive());
 }
 
diff --git a/media/mca/filterfw/jni/jni_init.cpp b/media/mca/filterfw/jni/jni_init.cpp
index 3b131f1..956a5a5 100644
--- a/media/mca/filterfw/jni/jni_init.cpp
+++ b/media/mca/filterfw/jni/jni_init.cpp
@@ -27,7 +27,7 @@
 
 JavaVM* g_current_java_vm_ = NULL;
 
-jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) {
   // Set the current vm pointer
   g_current_java_vm_ = vm;
 
diff --git a/media/mca/filterfw/native/Android.mk b/media/mca/filterfw/native/Android.mk
index 46ee283..7c4703f 100644
--- a/media/mca/filterfw/native/Android.mk
+++ b/media/mca/filterfw/native/Android.mk
@@ -39,6 +39,8 @@
 # gcc should always be placed at the end.
 LOCAL_EXPORT_LDLIBS := -llog -lgcc
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 # TODO: Build a shared library as well?
 include $(BUILD_STATIC_LIBRARY)
 
diff --git a/media/mca/filterfw/native/core/shader_program.cpp b/media/mca/filterfw/native/core/shader_program.cpp
index d92eb31..002327b 100644
--- a/media/mca/filterfw/native/core/shader_program.cpp
+++ b/media/mca/filterfw/native/core/shader_program.cpp
@@ -318,15 +318,15 @@
       ALOGE("Problem compiling shader! Source:");
       ALOGE("%s", source);
       std::string src(source);
-      unsigned int cur_pos = 0;
-      unsigned int next_pos = 0;
-      int line_number = 1;
+      size_t cur_pos = 0;
+      size_t next_pos = 0;
+      size_t line_number = 1;
       while ( (next_pos = src.find_first_of('\n', cur_pos)) != std::string::npos) {
         ALOGE("%03d : %s", line_number, src.substr(cur_pos, next_pos-cur_pos).c_str());
         cur_pos = next_pos + 1;
         line_number++;
       }
-      ALOGE("%03d : %s", line_number, src.substr(cur_pos, next_pos-cur_pos).c_str());
+      ALOGE("%03zu : %s", line_number, src.substr(cur_pos, next_pos-cur_pos).c_str());
 
       GLint log_length = 0;
       glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length);
diff --git a/media/mca/filterfw/native/core/vertex_frame.cpp b/media/mca/filterfw/native/core/vertex_frame.cpp
index 822573f..9fb9eaa 100644
--- a/media/mca/filterfw/native/core/vertex_frame.cpp
+++ b/media/mca/filterfw/native/core/vertex_frame.cpp
@@ -25,10 +25,6 @@
 namespace android {
 namespace filterfw {
 
-// GL Extensions that are dynamically looked up at runtime
-static PFNGLMAPBUFFEROESPROC    GLMapBufferOES    = NULL;
-static PFNGLUNMAPBUFFEROESPROC  GLUnmapBufferOES  = NULL;
-
 VertexFrame::VertexFrame(int size)
   : vbo_(0),
     size_(size) {
diff --git a/media/mca/filterpacks/Android.mk b/media/mca/filterpacks/Android.mk
index 6e54f60..d030749 100644
--- a/media/mca/filterpacks/Android.mk
+++ b/media/mca/filterpacks/Android.mk
@@ -28,6 +28,8 @@
 
 LOCAL_CFLAGS := -DANDROID
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include external/stlport/libstlport.mk
 
 include $(BUILD_STATIC_LIBRARY)
@@ -50,4 +52,6 @@
 
 LOCAL_PRELINK_MODULE := false
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/media/mca/filterpacks/native/imageproc/invert.c b/media/mca/filterpacks/native/imageproc/invert.c
index 5938aac..f5f9e27 100644
--- a/media/mca/filterpacks/native/imageproc/invert.c
+++ b/media/mca/filterpacks/native/imageproc/invert.c
@@ -16,12 +16,14 @@
 
 #include <android/log.h>
 
+#define ATTRIBUTE_UNUSED __attribute__((unused))
+
 int invert_process(const char** inputs,
                    const int* input_sizes,
                    int input_count,
                    char* output,
                    int output_size,
-                   void* user_data) {
+                   void* user_data ATTRIBUTE_UNUSED) {
   // Make sure we have exactly one input
   if (input_count != 1)
     return 0;
diff --git a/media/mca/filterpacks/native/imageproc/to_rgba.c b/media/mca/filterpacks/native/imageproc/to_rgba.c
index bf4db2a..80094c0 100644
--- a/media/mca/filterpacks/native/imageproc/to_rgba.c
+++ b/media/mca/filterpacks/native/imageproc/to_rgba.c
@@ -16,12 +16,14 @@
 
 #include <stdlib.h>
 
+#define ATTRIBUTE_UNUSED __attribute__((unused))
+
 int gray_to_rgb_process(const char** inputs,
                         const int* input_sizes,
                         int input_count,
                         char* output,
                         int output_size,
-                        void* user_data) {
+                        void* user_data ATTRIBUTE_UNUSED) {
   // Make sure we have exactly one input
   if (input_count != 1)
     return 0;
@@ -52,7 +54,7 @@
                         int input_count,
                         char* output,
                         int output_size,
-                        void* user_data) {
+                        void* user_data ATTRIBUTE_UNUSED) {
   // Make sure we have exactly one input
   if (input_count != 1)
     return 0;
@@ -84,7 +86,7 @@
                          int input_count,
                          char* output,
                          int output_size,
-                         void* user_data) {
+                         void* user_data ATTRIBUTE_UNUSED) {
   // Make sure we have exactly one input
   if (input_count != 1)
     return 0;
@@ -116,7 +118,7 @@
                         int input_count,
                         char* output,
                         int output_size,
-                        void* user_data) {
+                        void* user_data ATTRIBUTE_UNUSED) {
   // Make sure we have exactly one input
   if (input_count != 1)
     return 0;
diff --git a/native/android/Android.mk b/native/android/Android.mk
index cda38e0..b3a74a8 100644
--- a/native/android/Android.mk
+++ b/native/android/Android.mk
@@ -34,6 +34,8 @@
     frameworks/base/native/include \
     frameworks/base/core/jni/android
 
-LOCAL_MODULE:= libandroid
+LOCAL_MODULE := libandroid
+
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/native/graphics/jni/Android.mk b/native/graphics/jni/Android.mk
index 3154030..88954f0 100644
--- a/native/graphics/jni/Android.mk
+++ b/native/graphics/jni/Android.mk
@@ -6,27 +6,29 @@
 # setup for skia optimizations
 #
 ifneq ($(ARCH_ARM_HAVE_VFP),true)
-	LOCAL_CFLAGS += -DSK_SOFTWARE_FLOAT
+    LOCAL_CFLAGS += -DSK_SOFTWARE_FLOAT
 endif
 
 ifeq ($(ARCH_ARM_HAVE_NEON),true)
-	LOCAL_CFLAGS += -D__ARM_HAVE_NEON
+    LOCAL_CFLAGS += -D__ARM_HAVE_NEON
 endif
 
 # our source files
 #
 LOCAL_SRC_FILES:= \
-	bitmap.cpp
+    bitmap.cpp
 
 LOCAL_SHARED_LIBRARIES := \
     libandroid_runtime \
     libskia
 
 LOCAL_C_INCLUDES += \
-	frameworks/base/native/include \
-	frameworks/base/core/jni/android/graphics
+    frameworks/base/native/include \
+    frameworks/base/core/jni/android/graphics
 
 LOCAL_MODULE:= libjnigraphics
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp
index df0751d..ea32edc 100644
--- a/native/graphics/jni/bitmap.cpp
+++ b/native/graphics/jni/bitmap.cpp
@@ -15,7 +15,11 @@
  */
 
 #include <android/bitmap.h>
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <GraphicsJNI.h>
+#pragma GCC diagnostic pop
 
 int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
                           AndroidBitmapInfo* info) {
diff --git a/tools/aidl/aidl.cpp b/tools/aidl/aidl.cpp
index 45dd23b..14c9f95 100644
--- a/tools/aidl/aidl.cpp
+++ b/tools/aidl/aidl.cpp
@@ -228,7 +228,8 @@
         }
 #endif
 
-#ifdef OS_CASE_SENSITIVE
+        // aidl assumes case-insensitivity on Mac Os and Windows.
+#if defined(__linux__)
         valid = (expected == p);
 #else
         valid = !strcasecmp(expected.c_str(), p);