Frameworks/base: Turn on -Wall -Werror in cmds

Fix small warnings, turn on -Wall -Werror.

Change-Id: Iab1f01a7c7ebd6ba832b75067c5e395f380a1b8b
diff --git a/cmds/app_process/Android.mk b/cmds/app_process/Android.mk
index 397a7d1..dd5e0ea 100644
--- a/cmds/app_process/Android.mk
+++ b/cmds/app_process/Android.mk
@@ -3,17 +3,17 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-	app_main.cpp
+    app_main.cpp
 
 LOCAL_LDFLAGS := -Wl,--version-script,art/sigchainlib/version-script.txt -Wl,--export-dynamic
 
 LOCAL_SHARED_LIBRARIES := \
-	libdl \
-	libcutils \
-	libutils \
-	liblog \
-	libbinder \
-	libandroid_runtime
+    libdl \
+    libcutils \
+    libutils \
+    liblog \
+    libbinder \
+    libandroid_runtime
 
 LOCAL_WHOLE_STATIC_LIBRARIES := libsigchain
 
@@ -21,6 +21,9 @@
 LOCAL_MULTILIB := both
 LOCAL_MODULE_STEM_32 := app_process32
 LOCAL_MODULE_STEM_64 := app_process64
+
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_EXECUTABLE)
 
 # Create a symlink from app_process to app_process32 or 64
@@ -34,14 +37,14 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-	app_main.cpp
+    app_main.cpp
 
 LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-	libutils \
-	liblog \
-	libbinder \
-	libandroid_runtime
+    libcutils \
+    libutils \
+    liblog \
+    libbinder \
+    libandroid_runtime
 
 LOCAL_WHOLE_STATIC_LIBRARIES := libsigchain
 
@@ -54,6 +57,8 @@
 LOCAL_MODULE_STEM := app_process
 LOCAL_ADDRESS_SANITIZER := true
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_EXECUTABLE)
 
 endif # ifeq($(TARGET_ARCH),arm)
diff --git a/cmds/app_process/app_main.cpp b/cmds/app_process/app_main.cpp
index 1bb28c3..fbdbb25 100644
--- a/cmds/app_process/app_main.cpp
+++ b/cmds/app_process/app_main.cpp
@@ -24,7 +24,7 @@
 
 namespace android {
 
-void app_usage()
+static void app_usage()
 {
     fprintf(stderr,
         "Usage: app_process [java-options] cmd-dir start-class-name [options]\n");
diff --git a/cmds/backup/Android.mk b/cmds/backup/Android.mk
index 42e5133..8e1508c 100644
--- a/cmds/backup/Android.mk
+++ b/cmds/backup/Android.mk
@@ -12,4 +12,6 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
 LOCAL_MODULE_TAGS := optional
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_EXECUTABLE)
diff --git a/cmds/backup/backup.cpp b/cmds/backup/backup.cpp
index ea1888b..03ceffae0 100644
--- a/cmds/backup/backup.cpp
+++ b/cmds/backup/backup.cpp
@@ -25,8 +25,7 @@
 
 #include <unistd.h>
 
-int
-usage(int argc, const char** argv)
+static int usage(int /* argc */, const char** argv)
 {
     const char* p = argv[0];
 
@@ -44,15 +43,13 @@
     return 1;
 }
 
-int
-perform_full_backup()
+static int perform_full_backup()
 {
     printf("this would have written all of your data to stdout\n");
     return 0;
 }
 
-int
-perform_list(const char* filename)
+static int perform_list(const char* filename)
 {
     int err;
     int fd;
@@ -95,14 +92,13 @@
     return 0;
 }
 
-int perform_print(const char* entityname, const char* filename)
+static int perform_print(const char* entityname, const char* filename)
 {
     printf("perform_print(%s, %s);", entityname, filename);
     return 0;
 }
 
-int
-main(int argc, const char** argv)
+int main(int argc, const char** argv)
 {
     if (argc <= 1) {
         return perform_full_backup();
diff --git a/cmds/bootanimation/Android.mk b/cmds/bootanimation/Android.mk
index d6ecbe3..2ee586f 100644
--- a/cmds/bootanimation/Android.mk
+++ b/cmds/bootanimation/Android.mk
@@ -2,22 +2,24 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-	bootanimation_main.cpp \
-	AudioPlayer.cpp \
-	BootAnimation.cpp
+    bootanimation_main.cpp \
+    AudioPlayer.cpp \
+    BootAnimation.cpp
 
 LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 LOCAL_C_INCLUDES += external/tinyalsa/include
 
 LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-	liblog \
-	libandroidfw \
-	libutils \
-	libbinder \
+    libcutils \
+    liblog \
+    libandroidfw \
+    libutils \
+    libbinder \
     libui \
-	libskia \
+    libskia \
     libEGL \
     libGLESv1_CM \
     libgui \
diff --git a/cmds/bootanimation/AudioPlayer.cpp b/cmds/bootanimation/AudioPlayer.cpp
index 471b77f..459190f 100644
--- a/cmds/bootanimation/AudioPlayer.cpp
+++ b/cmds/bootanimation/AudioPlayer.cpp
@@ -207,7 +207,6 @@
     struct pcm *pcm = NULL;
     bool moreChunks = true;
     const struct chunk_fmt* chunkFmt = NULL;
-    void* buffer = NULL;
     int bufferSize;
     const uint8_t* wavData;
     size_t wavLength;
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 167014e..1d4de22 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -42,9 +42,13 @@
 #include <gui/Surface.h>
 #include <gui/SurfaceComposerClient.h>
 
+// TODO: Fix Skia.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <SkBitmap.h>
 #include <SkStream.h>
 #include <SkImageDecoder.h>
+#pragma GCC diagnostic pop
 
 #include <GLES/gl.h>
 #include <GLES/glext.h>
@@ -105,7 +109,7 @@
 status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets,
         const char* name) {
     Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);
-    if (!asset)
+    if (asset == NULL)
         return NO_INIT;
     SkBitmap bitmap;
     SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(),
@@ -164,7 +168,7 @@
     SkBitmap bitmap;
     SkMemoryStream  stream(frame.map->getDataPtr(), frame.map->getDataLength());
     SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
-    if (codec) {
+    if (codec != NULL) {
         codec->setDitherImage(false);
         codec->decode(&stream, &bitmap,
                 kN32_SkColorType,
@@ -252,7 +256,7 @@
             EGL_DEPTH_SIZE, 0,
             EGL_NONE
     };
-    EGLint w, h, dummy;
+    EGLint w, h;
     EGLint numConfigs;
     EGLConfig config;
     EGLSurface surface;
@@ -470,7 +474,7 @@
     // Parse the description file
     for (;;) {
         const char* endl = strstr(s, "\n");
-        if (!endl) break;
+        if (endl == NULL) break;
         String8 line(s, endl - s);
         const char* l = line.string();
         int fps, width, height, count, pause;
@@ -572,7 +576,6 @@
 
     const int xc = (mWidth - animation.width) / 2;
     const int yc = ((mHeight - animation.height) / 2);
-    nsecs_t lastFrame = systemTime();
     nsecs_t frameDuration = s2ns(1) / animation.fps;
 
     Region clearReg(Rect(mWidth, mHeight));
@@ -620,9 +623,9 @@
                     Region::const_iterator tail(clearReg.end());
                     glEnable(GL_SCISSOR_TEST);
                     while (head != tail) {
-                        const Rect& r(*head++);
-                        glScissor(r.left, mHeight - r.bottom,
-                                r.width(), r.height());
+                        const Rect& r2(*head++);
+                        glScissor(r2.left, mHeight - r2.bottom,
+                                r2.width(), r2.height());
                         glClear(GL_COLOR_BUFFER_BIT);
                     }
                     glDisable(GL_SCISSOR_TEST);
diff --git a/cmds/bootanimation/bootanimation_main.cpp b/cmds/bootanimation/bootanimation_main.cpp
index 417e138..6550d22 100644
--- a/cmds/bootanimation/bootanimation_main.cpp
+++ b/cmds/bootanimation/bootanimation_main.cpp
@@ -36,7 +36,7 @@
 
 // ---------------------------------------------------------------------------
 
-int main(int argc, char** argv)
+int main()
 {
 #if defined(HAVE_PTHREADS)
     setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);
diff --git a/cmds/idmap/Android.mk b/cmds/idmap/Android.mk
index ffa83f2..50ccb07 100644
--- a/cmds/idmap/Android.mk
+++ b/cmds/idmap/Android.mk
@@ -25,4 +25,6 @@
 
 LOCAL_MODULE_TAGS := optional
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_EXECUTABLE)
diff --git a/cmds/idmap/create.cpp b/cmds/idmap/create.cpp
index 593a197..28da3d6 100644
--- a/cmds/idmap/create.cpp
+++ b/cmds/idmap/create.cpp
@@ -22,7 +22,7 @@
         if (entry == NULL) {
             return -1;
         }
-        if (!zip->getEntryInfo(entry, NULL, NULL, NULL, NULL, NULL, (long*)crc)) {
+        if (!zip->getEntryInfo(entry, NULL, NULL, NULL, NULL, NULL, reinterpret_cast<long*>(crc))) {
             return -1;
         }
         zip->releaseEntry(entry);
@@ -66,7 +66,7 @@
                 fprintf(stderr, "error: write: %s\n", strerror(errno));
                 return -1;
             }
-            bytesLeft -= w;
+            bytesLeft -= static_cast<size_t>(w);
         }
         return 0;
     }
@@ -84,7 +84,7 @@
         }
 
         char buf[N];
-        ssize_t bytesLeft = N;
+        size_t bytesLeft = N;
         if (lseek(idmap_fd, SEEK_SET, 0) < 0) {
             return true;
         }
@@ -93,7 +93,7 @@
             if (r < 0) {
                 return true;
             }
-            bytesLeft -= r;
+            bytesLeft -= static_cast<size_t>(r);
             if (bytesLeft == 0) {
                 break;
             }
diff --git a/cmds/idmap/inspect.cpp b/cmds/idmap/inspect.cpp
index b9ac8a5..f6afc85 100644
--- a/cmds/idmap/inspect.cpp
+++ b/cmds/idmap/inspect.cpp
@@ -152,13 +152,13 @@
             printe("failed to get resource name id=0x%08x\n", res_id);
             return UNKNOWN_ERROR;
         }
-        if (package) {
+        if (package != NULL) {
             *package = String8(String16(data.package, data.packageLen));
         }
-        if (type) {
+        if (type != NULL) {
             *type = String8(String16(data.type, data.typeLen));
         }
-        if (name) {
+        if (name != NULL) {
             *name = String8(String16(data.name, data.nameLen));
         }
         return NO_ERROR;
diff --git a/cmds/idmap/scan.cpp b/cmds/idmap/scan.cpp
index 1153f38..4f19a74 100644
--- a/cmds/idmap/scan.cpp
+++ b/cmds/idmap/scan.cpp
@@ -64,30 +64,6 @@
         return String8(tmp);
     }
 
-    int mkdir_p(const String8& path, uid_t uid, gid_t gid)
-    {
-        static const mode_t mode =
-            S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH;
-        struct stat st;
-
-        if (stat(path.string(), &st) == 0) {
-            return 0;
-        }
-        if (mkdir_p(path.getPathDir(), uid, gid) < 0) {
-            return -1;
-        }
-        if (mkdir(path.string(), 0755) != 0) {
-            return -1;
-        }
-        if (chown(path.string(), uid, gid) == -1) {
-            return -1;
-        }
-        if (chmod(path.string(), mode) == -1) {
-            return -1;
-        }
-        return 0;
-    }
-
     int parse_overlay_tag(const ResXMLTree& parser, const char *target_package_name)
     {
         const size_t N = parser.getAttributeCount();
@@ -98,7 +74,7 @@
             String16 key(parser.getAttributeName(i, &len));
             if (key == String16("targetPackage")) {
                 const uint16_t *p = parser.getAttributeStringValue(i, &len);
-                if (p) {
+                if (p != NULL) {
                     target = String16(p, len);
                 }
             } else if (key == String16("priority")) {
@@ -164,7 +140,7 @@
             return -1;
         }
         FileMap *dataMap = zip->createEntryFileMap(entry);
-        if (!dataMap) {
+        if (dataMap == NULL) {
             ALOGW("%s: failed to create FileMap\n", __FUNCTION__);
             return -1;
         }
diff --git a/cmds/interrupter/Android.mk b/cmds/interrupter/Android.mk
index e324627..97a96bf 100644
--- a/cmds/interrupter/Android.mk
+++ b/cmds/interrupter/Android.mk
@@ -7,6 +7,7 @@
 LOCAL_MODULE := interrupter
 LOCAL_MODULE_TAGS := eng tests
 LOCAL_LDFLAGS := -ldl
+LOCAL_CFLAGS := -Wall -Werror -Wunused -Wunreachable-code
 
 include $(BUILD_SHARED_LIBRARY)
 
@@ -17,5 +18,6 @@
 LOCAL_MODULE := interrupter
 LOCAL_MODULE_TAGS := eng tests
 LOCAL_LDFLAGS := -ldl
+LOCAL_CFLAGS := -Wall -Werror -Wunused -Wunreachable-code
 
-include $(BUILD_HOST_SHARED_LIBRARY)
\ No newline at end of file
+include $(BUILD_HOST_SHARED_LIBRARY)
diff --git a/cmds/screencap/Android.mk b/cmds/screencap/Android.mk
index 5c11b75..b0dc422 100644
--- a/cmds/screencap/Android.mk
+++ b/cmds/screencap/Android.mk
@@ -2,13 +2,13 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-	screencap.cpp
+    screencap.cpp
 
 LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-	libutils \
-	libbinder \
-	libskia \
+    libcutils \
+    libutils \
+    libbinder \
+    libskia \
     libui \
     libgui
 
@@ -16,4 +16,6 @@
 
 LOCAL_MODULE_TAGS := optional
 
+LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
+
 include $(BUILD_EXECUTABLE)
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp
index 1ddbecb..b0aee7b 100644
--- a/cmds/screencap/screencap.cpp
+++ b/cmds/screencap/screencap.cpp
@@ -32,10 +32,14 @@
 
 #include <ui/PixelFormat.h>
 
+// TODO: Fix Skia.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <SkImageEncoder.h>
 #include <SkBitmap.h>
 #include <SkData.h>
 #include <SkStream.h>
+#pragma GCC diagnostic pop
 
 using namespace android;
 
@@ -129,7 +133,7 @@
     argv += optind;
 
     int fd = -1;
-    const char* fn;
+    const char* fn = NULL;
     if (argc == 0) {
         fd = dup(STDOUT_FILENO);
     } else if (argc == 1) {
@@ -153,7 +157,7 @@
     void const* mapbase = MAP_FAILED;
     ssize_t mapsize = -1;
 
-    void const* base = 0;
+    void const* base = NULL;
     uint32_t w, s, h, f;
     size_t size = 0;
 
@@ -190,7 +194,7 @@
         }
     }
 
-    if (base) {
+    if (base != NULL) {
         if (png) {
             const SkImageInfo info = SkImageInfo::Make(w, h, flinger2skia(f),
                                                        kPremul_SkAlphaType);
@@ -202,7 +206,9 @@
             SkData* streamData = stream.copyToData();
             write(fd, streamData->data(), streamData->size());
             streamData->unref();
-            notifyMediaScanner(fn);
+            if (fn != NULL) {
+                notifyMediaScanner(fn);
+            }
         } else {
             write(fd, &w, 4);
             write(fd, &h, 4);