diff options
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/app_process/Android.mk | 32 | ||||
-rw-r--r-- | cmds/app_process/app_main.cpp | 17 | ||||
-rw-r--r-- | cmds/backup/Android.mk | 2 | ||||
-rw-r--r-- | cmds/backup/backup.cpp | 16 | ||||
-rw-r--r-- | cmds/bootanimation/Android.mk | 20 | ||||
-rw-r--r-- | cmds/bootanimation/AudioPlayer.cpp | 11 | ||||
-rw-r--r-- | cmds/bootanimation/AudioPlayer.h | 5 | ||||
-rw-r--r-- | cmds/bootanimation/BootAnimation.cpp | 33 | ||||
-rw-r--r-- | cmds/bootanimation/bootanimation_main.cpp | 14 | ||||
-rw-r--r-- | cmds/idmap/Android.mk | 2 | ||||
-rw-r--r-- | cmds/idmap/create.cpp | 11 | ||||
-rw-r--r-- | cmds/idmap/inspect.cpp | 6 | ||||
-rw-r--r-- | cmds/idmap/scan.cpp | 45 | ||||
-rw-r--r-- | cmds/interrupter/Android.mk | 4 | ||||
-rw-r--r-- | cmds/pm/src/com/android/commands/pm/Pm.java | 5 | ||||
-rw-r--r-- | cmds/screencap/Android.mk | 12 | ||||
-rw-r--r-- | cmds/screencap/screencap.cpp | 31 |
17 files changed, 141 insertions, 125 deletions
diff --git a/cmds/app_process/Android.mk b/cmds/app_process/Android.mk index 397a7d1..ce6d7b5 100644 --- a/cmds/app_process/Android.mk +++ b/cmds/app_process/Android.mk @@ -3,17 +3,17 @@ LOCAL_PATH:= $(call my-dir) 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_MODULE:= app_process 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 @@ ifeq ($(TARGET_ARCH),arm) 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 @@ -53,6 +56,9 @@ LOCAL_MODULE_TAGS := eng LOCAL_MODULE_PATH := $(TARGET_OUT_EXECUTABLES)/asan LOCAL_MODULE_STEM := app_process LOCAL_ADDRESS_SANITIZER := true +LOCAL_CLANG := true + +LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code include $(BUILD_EXECUTABLE) diff --git a/cmds/app_process/app_main.cpp b/cmds/app_process/app_main.cpp index 91cec19..3a6abd3 100644 --- a/cmds/app_process/app_main.cpp +++ b/cmds/app_process/app_main.cpp @@ -7,6 +7,12 @@ #define LOG_TAG "appproc" +#include <stdio.h> +#include <stdlib.h> +#include <sys/prctl.h> +#include <sys/stat.h> +#include <unistd.h> + #include <binder/IPCThreadState.h> #include <binder/ProcessState.h> #include <utils/Log.h> @@ -17,14 +23,9 @@ #include <android_runtime/AndroidRuntime.h> #include <private/android_filesystem_config.h> // for AID_SYSTEM -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <sys/prctl.h> - namespace android { -void app_usage() +static void app_usage() { fprintf(stderr, "Usage: app_process [java-options] cmd-dir start-class-name [options]\n"); @@ -146,8 +147,10 @@ static void maybeCreateDalvikCache() { static const char kInstructionSet[] = "arm"; #elif defined(__i386__) static const char kInstructionSet[] = "x86"; -#elif defined (__mips__) +#elif defined (__mips__) && !defined(__LP64__) static const char kInstructionSet[] = "mips"; +#elif defined (__mips__) && defined(__LP64__) + static const char kInstructionSet[] = "mips64"; #else #error "Unknown instruction set" #endif 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:= btool 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..8d9b528 100644 --- a/cmds/backup/backup.cpp +++ b/cmds/backup/backup.cpp @@ -25,8 +25,7 @@ using namespace android; #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 @@ usage(int argc, const char** argv) 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; @@ -78,7 +75,7 @@ perform_list(const char* filename) 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"); } @@ -95,14 +92,13 @@ perform_list(const char* filename) 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 @@ LOCAL_PATH:= $(call my-dir) 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..2932130 100644 --- a/cmds/bootanimation/AudioPlayer.cpp +++ b/cmds/bootanimation/AudioPlayer.cpp @@ -98,16 +98,16 @@ static bool setMixerValue(struct mixer* mixer, const char* name, const char* val ALOGE("mixer_ctl_set_value failed for %s %d", name, intValue); } } else { - ALOGE("Could not parse %s as int for %d", intValue, name); + ALOGE("Could not parse %s as int for %s", values, name); } break; case MIXER_CTL_TYPE_ENUM: if (sscanf(values, "%s", stringValue) == 1) { if (mixer_ctl_set_enum_by_string(ctl, stringValue) != 0) { - ALOGE("mixer_ctl_set_enum_by_string failed for %s %%s", name, stringValue); + ALOGE("mixer_ctl_set_enum_by_string failed for %s %s", name, stringValue); } } else { - ALOGE("Could not parse %s as enum for %d", stringValue, name); + ALOGE("Could not parse %s as enum for %s", values, name); } break; default: @@ -193,7 +193,7 @@ bool AudioPlayer::init(const char* config) return false; } -void AudioPlayer::playFile(struct FileMap* fileMap) { +void AudioPlayer::playFile(FileMap* fileMap) { // stop any currently playing sound requestExitAndWait(); @@ -207,7 +207,6 @@ bool AudioPlayer::threadLoop() 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; @@ -306,7 +305,7 @@ bool AudioPlayer::threadLoop() exit: if (pcm) pcm_close(pcm); - mCurrentFile->release(); + delete mCurrentFile; mCurrentFile = NULL; return false; } diff --git a/cmds/bootanimation/AudioPlayer.h b/cmds/bootanimation/AudioPlayer.h index 7e82a07..1def0ae 100644 --- a/cmds/bootanimation/AudioPlayer.h +++ b/cmds/bootanimation/AudioPlayer.h @@ -18,6 +18,7 @@ #define _BOOTANIMATION_AUDIOPLAYER_H #include <utils/Thread.h> +#include <utils/FileMap.h> namespace android { @@ -28,7 +29,7 @@ public: virtual ~AudioPlayer(); bool init(const char* config); - void playFile(struct FileMap* fileMap); + void playFile(FileMap* fileMap); private: virtual bool threadLoop(); @@ -39,7 +40,7 @@ private: int mPeriodSize; int mPeriodCount; - struct FileMap* mCurrentFile; + FileMap* mCurrentFile; }; } // namespace android diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp index b2474f2..21dc1e2 100644 --- a/cmds/bootanimation/BootAnimation.cpp +++ b/cmds/bootanimation/BootAnimation.cpp @@ -23,6 +23,7 @@ #include <fcntl.h> #include <utils/misc.h> #include <signal.h> +#include <time.h> #include <cutils/properties.h> @@ -41,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> @@ -57,10 +62,6 @@ #define SYSTEM_ENCRYPTED_BOOTANIMATION_FILE "/system/media/bootanimation-encrypted.zip" #define EXIT_PROP_NAME "service.bootanim.exit" -extern "C" int clock_nanosleep(clockid_t clock_id, int flags, - const struct timespec *request, - struct timespec *remain); - namespace android { static const int ANIM_ENTRY_NAME_MAX = 256; @@ -108,7 +109,7 @@ void BootAnimation::binderDied(const wp<IBinder>&) 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(), @@ -167,7 +168,7 @@ status_t BootAnimation::initTexture(const Animation::Frame& frame) 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, @@ -178,7 +179,7 @@ status_t BootAnimation::initTexture(const Animation::Frame& frame) // FileMap memory is never released until application exit. // Release it now as the texture is already loaded and the memory used for // the packed resource can be released. - frame.map->release(); + delete frame.map; // ensure we can call getPixels(). No need to call unlock, since the // bitmap will go out of scope when we return from this method. @@ -255,7 +256,7 @@ status_t BootAnimation::readyToRun() { EGL_DEPTH_SIZE, 0, EGL_NONE }; - EGLint w, h, dummy; + EGLint w, h; EGLint numConfigs; EGLConfig config; EGLSurface surface; @@ -445,7 +446,7 @@ bool BootAnimation::readFile(const char* name, String8& outString) } outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength()); - entryMap->release(); + delete entryMap; return true; } @@ -473,7 +474,7 @@ bool BootAnimation::movie() // 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; @@ -575,7 +576,6 @@ bool BootAnimation::movie() 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)); @@ -623,14 +623,17 @@ bool BootAnimation::movie() 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); } - glDrawTexiOES(xc, yc, 0, animation.width, animation.height); + // specify the y center as ceiling((mHeight - animation.height) / 2) + // which is equivalent to mHeight - (yc + animation.height) + glDrawTexiOES(xc, mHeight - (yc + animation.height), + 0, animation.width, animation.height); eglSwapBuffers(mDisplay, mSurface); nsecs_t now = systemTime(); diff --git a/cmds/bootanimation/bootanimation_main.cpp b/cmds/bootanimation/bootanimation_main.cpp index 417e138..48a34e7 100644 --- a/cmds/bootanimation/bootanimation_main.cpp +++ b/cmds/bootanimation/bootanimation_main.cpp @@ -16,31 +16,23 @@ #define LOG_TAG "BootAnimation" -#include <cutils/properties.h> - #include <binder/IPCThreadState.h> #include <binder/ProcessState.h> #include <binder/IServiceManager.h> - +#include <cutils/properties.h> +#include <sys/resource.h> #include <utils/Log.h> #include <utils/threads.h> -#if defined(HAVE_PTHREADS) -# include <pthread.h> -# include <sys/resource.h> -#endif - #include "BootAnimation.h" using namespace android; // --------------------------------------------------------------------------- -int main(int argc, char** argv) +int main() { -#if defined(HAVE_PTHREADS) setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY); -#endif char value[PROPERTY_VALUE_MAX]; property_get("debug.sf.nobootanimation", value, "0"); 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_C_INCLUDES := external/zlib 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..16532b8 100644 --- a/cmds/idmap/create.cpp +++ b/cmds/idmap/create.cpp @@ -7,6 +7,7 @@ #include <utils/String8.h> #include <fcntl.h> +#include <sys/file.h> #include <sys/stat.h> using namespace android; @@ -22,7 +23,7 @@ namespace { 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 +67,7 @@ fail: fprintf(stderr, "error: write: %s\n", strerror(errno)); return -1; } - bytesLeft -= w; + bytesLeft -= static_cast<size_t>(w); } return 0; } @@ -78,13 +79,13 @@ fail: 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; } char buf[N]; - ssize_t bytesLeft = N; + size_t bytesLeft = N; if (lseek(idmap_fd, SEEK_SET, 0) < 0) { return true; } @@ -93,7 +94,7 @@ fail: 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 @@ namespace { 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..84158d3 100644 --- a/cmds/idmap/scan.cpp +++ b/cmds/idmap/scan.cpp @@ -1,3 +1,6 @@ +#include <dirent.h> +#include <sys/stat.h> + #include "idmap.h" #include <UniquePtr.h> @@ -9,8 +12,6 @@ #include <utils/String16.h> #include <utils/String8.h> -#include <dirent.h> - #define NO_OVERLAY_TAG (-1000) using namespace android; @@ -64,30 +65,6 @@ namespace { 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(); @@ -97,8 +74,8 @@ namespace { size_t len; String16 key(parser.getAttributeName(i, &len)); if (key == String16("targetPackage")) { - const uint16_t *p = parser.getAttributeStringValue(i, &len); - if (p) { + const char16_t *p = parser.getAttributeStringValue(i, &len); + if (p != NULL) { target = String16(p, len); } } else if (key == String16("priority")) { @@ -164,27 +141,27 @@ namespace { return -1; } FileMap *dataMap = zip->createEntryFileMap(entry); - if (!dataMap) { + if (dataMap == NULL) { ALOGW("%s: failed to create FileMap\n", __FUNCTION__); return -1; } char *buf = new char[uncompLen]; if (NULL == buf) { - ALOGW("%s: failed to allocate %d byte\n", __FUNCTION__, uncompLen); - dataMap->release(); + ALOGW("%s: failed to allocate %zd byte\n", __FUNCTION__, uncompLen); + delete dataMap; return -1; } StreamingZipInflater inflater(dataMap, uncompLen); if (inflater.read(buf, uncompLen) < 0) { - ALOGW("%s: failed to inflate %d byte\n", __FUNCTION__, uncompLen); + ALOGW("%s: failed to inflate %zd byte\n", __FUNCTION__, uncompLen); delete[] buf; - dataMap->release(); + delete dataMap; return -1; } int priority = parse_manifest(buf, uncompLen, target_package_name); delete[] buf; - dataMap->release(); + delete dataMap; return priority; } } 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_SRC_FILES := \ 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_SRC_FILES := \ 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/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java index 0a573ca..7a01701 100644 --- a/cmds/pm/src/com/android/commands/pm/Pm.java +++ b/cmds/pm/src/com/android/commands/pm/Pm.java @@ -549,7 +549,10 @@ public final class Pm { if (res != 0) { Resources r = getResources(pii); if (r != null) { - return r.getString(res); + try { + return r.getString(res); + } catch (Resources.NotFoundException e) { + } } } return null; 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 @@ LOCAL_PATH:= $(call my-dir) 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:= screencap 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 6b2a0e2..b0aee7b 100644 --- a/cmds/screencap/screencap.cpp +++ b/cmds/screencap/screencap.cpp @@ -18,6 +18,8 @@ #include <unistd.h> #include <stdio.h> #include <fcntl.h> +#include <stdlib.h> +#include <string.h> #include <linux/fb.h> #include <sys/ioctl.h> @@ -30,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; @@ -86,6 +92,21 @@ static status_t vinfoToPixelFormat(const fb_var_screeninfo& vinfo, return NO_ERROR; } +static status_t notifyMediaScanner(const char* fileName) { + String8 cmd("am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file://"); + String8 fileUrl("\""); + fileUrl.append(fileName); + fileUrl.append("\""); + cmd.append(fileName); + cmd.append(" > /dev/null"); + int result = system(cmd.string()); + if (result < 0) { + fprintf(stderr, "Unable to broadcast intent for media scanner.\n"); + return UNKNOWN_ERROR; + } + return NO_ERROR; +} + int main(int argc, char** argv) { ProcessState::self()->startThreadPool(); @@ -112,10 +133,11 @@ int main(int argc, char** argv) argv += optind; int fd = -1; + const char* fn = NULL; if (argc == 0) { fd = dup(STDOUT_FILENO); } else if (argc == 1) { - const char* fn = argv[0]; + fn = argv[0]; fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0664); if (fd == -1) { fprintf(stderr, "Error opening file: %s (%s)\n", fn, strerror(errno)); @@ -135,7 +157,7 @@ int main(int argc, char** argv) 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; @@ -172,7 +194,7 @@ int main(int argc, char** argv) } } - if (base) { + if (base != NULL) { if (png) { const SkImageInfo info = SkImageInfo::Make(w, h, flinger2skia(f), kPremul_SkAlphaType); @@ -184,6 +206,9 @@ int main(int argc, char** argv) SkData* streamData = stream.copyToData(); write(fd, streamData->data(), streamData->size()); streamData->unref(); + if (fn != NULL) { + notifyMediaScanner(fn); + } } else { write(fd, &w, 4); write(fd, &h, 4); |