Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ce259c2 authored by Andreas Gampe's avatar Andreas Gampe Committed by Gerrit Code Review
Browse files

Merge "Frameworks/base: Fix AAPT warnings"

parents c46dbe8a 2412f840
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@
#include <dirent.h>
#include <errno.h>

static const char* kDefaultLocale = "default";
static const char* kWildcardName = "any";
static const char* kAssetDir = "assets";
static const char* kResourceDir = "res";
@@ -679,7 +678,6 @@ AaptGroupEntry::initFromDirName(const char* dir, String8* resType)
    String8 uiModeType, uiModeNight, smallestwidthdp, widthdp, heightdp;

    AaptLocaleValue locale;
    int numLocaleComponents = 0;

    const int N = parts.size();
    int index = 0;
@@ -2538,7 +2536,7 @@ bail:
}

ssize_t
AaptAssets::slurpResourceZip(Bundle* bundle, const char* filename)
AaptAssets::slurpResourceZip(Bundle* /* bundle */, const char* filename)
{
    int count = 0;
    SortedVector<AaptGroupEntry> entries;
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ LOCAL_CFLAGS += -D_DARWIN_UNLIMITED_STREAMS
endif

LOCAL_CFLAGS += -DSTATIC_ANDROIDFW_FOR_TOOLS
LOCAL_CFLAGS += -Wall -Werror

LOCAL_C_INCLUDES += external/libpng
LOCAL_C_INCLUDES += external/zlib
@@ -83,6 +84,7 @@ LOCAL_C_INCLUDES += external/libpng
LOCAL_C_INCLUDES += external/zlib

LOCAL_CFLAGS += -Wno-non-virtual-dtor
LOCAL_CFLAGS += -Wall -Werror

LOCAL_SHARED_LIBRARIES := \
        libandroidfw \
+3 −1
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ public:

    // Process an image from source out to dest
    virtual void processImage(String8 source, String8 dest) = 0;

    virtual ~CacheUpdater() {}
private:
};

+94 −98
Original line number Diff line number Diff line
@@ -14,7 +14,8 @@
#include <png.h>
#include <zlib.h>

#define NOISY(x) //x
// Change this to true for noisy debug output.
static const bool kIsDebug = false;

static void
png_write_aapt_file(png_structp png_ptr, png_bytep data, png_size_t length)
@@ -28,7 +29,7 @@ png_write_aapt_file(png_structp png_ptr, png_bytep data, png_size_t length)


static void
png_flush_aapt_file(png_structp png_ptr)
png_flush_aapt_file(png_structp /* png_ptr */)
{
}

@@ -138,11 +139,13 @@ static void read_png(const char* imageName,

    png_read_end(read_ptr, read_info);

    NOISY(printf("Image %s: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
    if (kIsDebug) {
        printf("Image %s: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
                imageName,
                (int)outImageInfo->width, (int)outImageInfo->height,
                bit_depth, color_type,
                 interlace_type, compression_type));
                interlace_type, compression_type);
    }

    png_get_IHDR(read_ptr, read_info, &outImageInfo->width,
       &outImageInfo->height, &bit_depth, &color_type,
@@ -312,7 +315,7 @@ static status_t get_vertical_ticks(
}

static status_t get_horizontal_layout_bounds_ticks(
        png_bytep row, int width, bool transparent, bool required,
        png_bytep row, int width, bool transparent, bool /* required */,
        int32_t* outLeft, int32_t* outRight, const char** outError)
{
    int i;
@@ -350,7 +353,7 @@ static status_t get_horizontal_layout_bounds_ticks(
}

static status_t get_vertical_layout_bounds_ticks(
        png_bytepp rows, int offset, int height, bool transparent, bool required,
        png_bytepp rows, int offset, int height, bool transparent, bool /* required */,
        int32_t* outTop, int32_t* outBottom, const char** outError)
{
    int i;
@@ -418,41 +421,6 @@ static uint32_t get_color(
    return (color[3]<<24) | (color[0]<<16) | (color[1]<<8) | color[2];
}

static void select_patch(
    int which, int front, int back, int size, int* start, int* end)
{
    switch (which) {
    case 0:
        *start = 0;
        *end = front-1;
        break;
    case 1:
        *start = front;
        *end = back-1;
        break;
    case 2:
        *start = back;
        *end = size-1;
        break;
    }
}

static uint32_t get_color(image_info* image, int hpatch, int vpatch)
{
    int left, right, top, bottom;
    select_patch(
        hpatch, image->xDivs[0], image->xDivs[1],
        image->width, &left, &right);
    select_patch(
        vpatch, image->yDivs[0], image->yDivs[1],
        image->height, &top, &bottom);
    //printf("Selecting h=%d v=%d: (%d,%d)-(%d,%d)\n",
    //       hpatch, vpatch, left, top, right, bottom);
    const uint32_t c = get_color(image->rows, left, top, right, bottom);
    NOISY(printf("Color in (%d,%d)-(%d,%d): #%08x\n", left, top, right, bottom, c));
    return c;
}

static status_t do_9patch(const char* imageName, image_info* image)
{
    image->is9Patch = true;
@@ -557,8 +525,10 @@ static status_t do_9patch(const char* imageName, image_info* image)
                               || image->layoutBoundsBottom != 0;

    if (image->haveLayoutBounds) {
        NOISY(printf("layoutBounds=%d %d %d %d\n", image->layoutBoundsLeft, image->layoutBoundsTop,
                image->layoutBoundsRight, image->layoutBoundsBottom));
        if (kIsDebug) {
            printf("layoutBounds=%d %d %d %d\n", image->layoutBoundsLeft, image->layoutBoundsTop,
                    image->layoutBoundsRight, image->layoutBoundsBottom);
        }
    }

    // If padding is not yet specified, take values from size.
@@ -577,12 +547,14 @@ static status_t do_9patch(const char* imageName, image_info* image)
        image->info9Patch.paddingBottom = H - 2 - image->info9Patch.paddingBottom;
    }

    NOISY(printf("Size ticks for %s: x0=%d, x1=%d, y0=%d, y1=%d\n", imageName,
                 image->info9Patch.xDivs[0], image->info9Patch.xDivs[1],
                 image->info9Patch.yDivs[0], image->info9Patch.yDivs[1]));
    NOISY(printf("padding ticks for %s: l=%d, r=%d, t=%d, b=%d\n", imageName,
    if (kIsDebug) {
        printf("Size ticks for %s: x0=%d, x1=%d, y0=%d, y1=%d\n", imageName,
                image->info9Patch.getXDivs()[0], image->info9Patch.getXDivs()[1],
                image->info9Patch.getYDivs()[0], image->info9Patch.getYDivs()[1]);
        printf("padding ticks for %s: l=%d, r=%d, t=%d, b=%d\n", imageName,
                image->info9Patch.paddingLeft, image->info9Patch.paddingRight,
                 image->info9Patch.paddingTop, image->info9Patch.paddingBottom));
                image->info9Patch.paddingTop, image->info9Patch.paddingBottom);
    }

    // Remove frame from image.
    image->rows = (png_bytepp)malloc((H-2) * sizeof(png_bytep));
@@ -664,7 +636,10 @@ static status_t do_9patch(const char* imageName, image_info* image)
            }
            c = get_color(image->rows, left, top, right - 1, bottom - 1);
            image->colors[colorIndex++] = c;
            NOISY(if (c != Res_png_9patch::NO_COLOR) hasColor = true);
            if (kIsDebug) {
                if (c != Res_png_9patch::NO_COLOR)
                    hasColor = true;
            }
            left = right;
        }
        top = bottom;
@@ -767,7 +742,7 @@ static void dump_image(int w, int h, png_bytepp rows, int color_type)
                break;
            }
            if (i == (w - 1)) {
                NOISY(printf("\n"));
                printf("\n");
            }
        }
    }
@@ -797,8 +772,10 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
    // 2. Every pixel has A == 255 (opaque)
    // 3. There are no more than 256 distinct RGBA colors

    // NOISY(printf("Initial image data:\n"));
    // dump_image(w, h, imageInfo.rows, PNG_COLOR_TYPE_RGB_ALPHA);
    if (kIsDebug) {
        printf("Initial image data:\n");
        dump_image(w, h, imageInfo.rows, PNG_COLOR_TYPE_RGB_ALPHA);
    }

    for (j = 0; j < h; j++) {
        png_bytep row = imageInfo.rows[j];
@@ -814,15 +791,19 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
            maxGrayDeviation = MAX(ABS(gg - bb), maxGrayDeviation);
            maxGrayDeviation = MAX(ABS(bb - rr), maxGrayDeviation);
            if (maxGrayDeviation > odev) {
                NOISY(printf("New max dev. = %d at pixel (%d, %d) = (%d %d %d %d)\n",
                             maxGrayDeviation, i, j, rr, gg, bb, aa));
                if (kIsDebug) {
                    printf("New max dev. = %d at pixel (%d, %d) = (%d %d %d %d)\n",
                            maxGrayDeviation, i, j, rr, gg, bb, aa);
                }
            }

            // Check if image is really grayscale
            if (isGrayscale) {
                if (rr != gg || rr != bb) {
                     NOISY(printf("Found a non-gray pixel at %d, %d = (%d %d %d %d)\n",
                                  i, j, rr, gg, bb, aa));
                    if (kIsDebug) {
                        printf("Found a non-gray pixel at %d, %d = (%d %d %d %d)\n",
                                i, j, rr, gg, bb, aa);
                    }
                    isGrayscale = false;
                }
            }
@@ -830,8 +811,10 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
            // Check if image is really opaque
            if (isOpaque) {
                if (aa != 0xff) {
                    NOISY(printf("Found a non-opaque pixel at %d, %d = (%d %d %d %d)\n",
                                 i, j, rr, gg, bb, aa));
                    if (kIsDebug) {
                        printf("Found a non-opaque pixel at %d, %d = (%d %d %d %d)\n",
                                i, j, rr, gg, bb, aa);
                    }
                    isOpaque = false;
                }
            }
@@ -853,7 +836,9 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
                *out++ = idx;
                if (!match) {
                    if (num_colors == 256) {
                        NOISY(printf("Found 257th color at %d, %d\n", i, j));
                        if (kIsDebug) {
                            printf("Found 257th color at %d, %d\n", i, j);
                        }
                        isPalette = false;
                    } else {
                        colors[num_colors++] = col;
@@ -868,12 +853,14 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
    int bpp = isOpaque ? 3 : 4;
    int paletteSize = w * h + bpp * num_colors;

    NOISY(printf("isGrayscale = %s\n", isGrayscale ? "true" : "false"));
    NOISY(printf("isOpaque = %s\n", isOpaque ? "true" : "false"));
    NOISY(printf("isPalette = %s\n", isPalette ? "true" : "false"));
    NOISY(printf("Size w/ palette = %d, gray+alpha = %d, rgb(a) = %d\n",
                 paletteSize, 2 * w * h, bpp * w * h));
    NOISY(printf("Max gray deviation = %d, tolerance = %d\n", maxGrayDeviation, grayscaleTolerance));
    if (kIsDebug) {
        printf("isGrayscale = %s\n", isGrayscale ? "true" : "false");
        printf("isOpaque = %s\n", isOpaque ? "true" : "false");
        printf("isPalette = %s\n", isPalette ? "true" : "false");
        printf("Size w/ palette = %d, gray+alpha = %d, rgb(a) = %d\n",
                paletteSize, 2 * w * h, bpp * w * h);
        printf("Max gray deviation = %d, tolerance = %d\n", maxGrayDeviation, grayscaleTolerance);
    }

    // Choose the best color type for the image.
    // 1. Opaque gray - use COLOR_TYPE_GRAY at 1 byte/pixel
@@ -950,7 +937,6 @@ static void write_png(const char* imageName,
                      png_structp write_ptr, png_infop write_info,
                      image_info& imageInfo, int grayscaleTolerance)
{
    bool optimize = true;
    png_uint_32 width, height;
    int color_type;
    int bit_depth, interlace_type, compression_type;
@@ -975,8 +961,10 @@ static void write_png(const char* imageName,

    png_set_compression_level(write_ptr, Z_BEST_COMPRESSION);

    NOISY(printf("Writing image %s: w = %d, h = %d\n", imageName,
          (int) imageInfo.width, (int) imageInfo.height));
    if (kIsDebug) {
        printf("Writing image %s: w = %d, h = %d\n", imageName,
                (int) imageInfo.width, (int) imageInfo.height);
    }

    png_color rgbPalette[256];
    png_byte alphaPalette[256];
@@ -993,25 +981,27 @@ static void write_png(const char* imageName,
        color_type = PNG_COLOR_TYPE_RGB_ALPHA;
    }

    if (kIsDebug) {
        switch (color_type) {
        case PNG_COLOR_TYPE_PALETTE:
        NOISY(printf("Image %s has %d colors%s, using PNG_COLOR_TYPE_PALETTE\n",
            printf("Image %s has %d colors%s, using PNG_COLOR_TYPE_PALETTE\n",
                    imageName, paletteEntries,
                     hasTransparency ? " (with alpha)" : ""));
                    hasTransparency ? " (with alpha)" : "");
            break;
        case PNG_COLOR_TYPE_GRAY:
        NOISY(printf("Image %s is opaque gray, using PNG_COLOR_TYPE_GRAY\n", imageName));
            printf("Image %s is opaque gray, using PNG_COLOR_TYPE_GRAY\n", imageName);
            break;
        case PNG_COLOR_TYPE_GRAY_ALPHA:
        NOISY(printf("Image %s is gray + alpha, using PNG_COLOR_TYPE_GRAY_ALPHA\n", imageName));
            printf("Image %s is gray + alpha, using PNG_COLOR_TYPE_GRAY_ALPHA\n", imageName);
            break;
        case PNG_COLOR_TYPE_RGB:
        NOISY(printf("Image %s is opaque RGB, using PNG_COLOR_TYPE_RGB\n", imageName));
            printf("Image %s is opaque RGB, using PNG_COLOR_TYPE_RGB\n", imageName);
            break;
        case PNG_COLOR_TYPE_RGB_ALPHA:
        NOISY(printf("Image %s is RGB + alpha, using PNG_COLOR_TYPE_RGB_ALPHA\n", imageName));
            printf("Image %s is RGB + alpha, using PNG_COLOR_TYPE_RGB_ALPHA\n", imageName);
            break;
        }
    }

    png_set_IHDR(write_ptr, write_info, imageInfo.width, imageInfo.height,
                 8, color_type, PNG_INTERLACE_NONE,
@@ -1034,7 +1024,9 @@ static void write_png(const char* imageName,
        png_byte *chunk_names = imageInfo.haveLayoutBounds
                ? (png_byte*)"npLb\0npTc\0"
                : (png_byte*)"npTc";
        NOISY(printf("Adding 9-patch info...\n"));
        if (kIsDebug) {
            printf("Adding 9-patch info...\n");
        }
        strcpy((char*)unknowns[p_index].name, "npTc");
        unknowns[p_index].data = (png_byte*)imageInfo.serialize9patch();
        unknowns[p_index].size = imageInfo.info9Patch.serializedSize();
@@ -1078,8 +1070,10 @@ static void write_png(const char* imageName,
    }
    png_write_image(write_ptr, rows);

//     NOISY(printf("Final image data:\n"));
//     dump_image(imageInfo.width, imageInfo.height, rows, color_type);
    if (kIsDebug) {
        printf("Final image data:\n");
        dump_image(imageInfo.width, imageInfo.height, rows, color_type);
    }

    png_write_end(write_ptr, write_info);

@@ -1094,13 +1088,15 @@ static void write_png(const char* imageName,
       &bit_depth, &color_type, &interlace_type,
       &compression_type, NULL);

    NOISY(printf("Image written: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
    if (kIsDebug) {
        printf("Image written: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
                (int)width, (int)height, bit_depth, color_type, interlace_type,
                 compression_type));
                compression_type);
    }
}

status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& assets,
                         const sp<AaptFile>& file, String8* outNewLeafName)
status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& /* assets */,
                         const sp<AaptFile>& file, String8* /* outNewLeafName */)
{
    String8 ext(file->getPath().getPathExtension());

+0 −1
Original line number Diff line number Diff line
@@ -455,7 +455,6 @@ bool endsWith(const char* haystack, const char* needle)

ssize_t processJarFile(ZipFile* jar, ZipFile* out)
{
    status_t err;
    size_t N = jar->getNumEntries();
    size_t count = 0;
    for (size_t i=0; i<N; i++) {
Loading