Merge "Frameworks/base: Fix AAPT warnings"
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static const char* kDefaultLocale = "default";
|
|
||||||
static const char* kWildcardName = "any";
|
static const char* kWildcardName = "any";
|
||||||
static const char* kAssetDir = "assets";
|
static const char* kAssetDir = "assets";
|
||||||
static const char* kResourceDir = "res";
|
static const char* kResourceDir = "res";
|
||||||
@@ -679,7 +678,6 @@ AaptGroupEntry::initFromDirName(const char* dir, String8* resType)
|
|||||||
String8 uiModeType, uiModeNight, smallestwidthdp, widthdp, heightdp;
|
String8 uiModeType, uiModeNight, smallestwidthdp, widthdp, heightdp;
|
||||||
|
|
||||||
AaptLocaleValue locale;
|
AaptLocaleValue locale;
|
||||||
int numLocaleComponents = 0;
|
|
||||||
|
|
||||||
const int N = parts.size();
|
const int N = parts.size();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -2538,7 +2536,7 @@ bail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
AaptAssets::slurpResourceZip(Bundle* bundle, const char* filename)
|
AaptAssets::slurpResourceZip(Bundle* /* bundle */, const char* filename)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
SortedVector<AaptGroupEntry> entries;
|
SortedVector<AaptGroupEntry> entries;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ LOCAL_CFLAGS += -D_DARWIN_UNLIMITED_STREAMS
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
LOCAL_CFLAGS += -DSTATIC_ANDROIDFW_FOR_TOOLS
|
LOCAL_CFLAGS += -DSTATIC_ANDROIDFW_FOR_TOOLS
|
||||||
|
LOCAL_CFLAGS += -Wall -Werror
|
||||||
|
|
||||||
LOCAL_C_INCLUDES += external/libpng
|
LOCAL_C_INCLUDES += external/libpng
|
||||||
LOCAL_C_INCLUDES += external/zlib
|
LOCAL_C_INCLUDES += external/zlib
|
||||||
@@ -83,6 +84,7 @@ LOCAL_C_INCLUDES += external/libpng
|
|||||||
LOCAL_C_INCLUDES += external/zlib
|
LOCAL_C_INCLUDES += external/zlib
|
||||||
|
|
||||||
LOCAL_CFLAGS += -Wno-non-virtual-dtor
|
LOCAL_CFLAGS += -Wno-non-virtual-dtor
|
||||||
|
LOCAL_CFLAGS += -Wall -Werror
|
||||||
|
|
||||||
LOCAL_SHARED_LIBRARIES := \
|
LOCAL_SHARED_LIBRARIES := \
|
||||||
libandroidfw \
|
libandroidfw \
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public:
|
|||||||
|
|
||||||
// Process an image from source out to dest
|
// Process an image from source out to dest
|
||||||
virtual void processImage(String8 source, String8 dest) = 0;
|
virtual void processImage(String8 source, String8 dest) = 0;
|
||||||
|
|
||||||
|
virtual ~CacheUpdater() {}
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -104,4 +106,4 @@ private:
|
|||||||
Bundle* bundle;
|
Bundle* bundle;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CACHE_UPDATER_H
|
#endif // CACHE_UPDATER_H
|
||||||
|
|||||||
@@ -101,4 +101,4 @@ bool CrunchCache::needsUpdating(String8 relativePath) const
|
|||||||
time_t sourceDate = mSourceFiles.valueFor(mSourcePath.appendPathCopy(relativePath));
|
time_t sourceDate = mSourceFiles.valueFor(mSourcePath.appendPathCopy(relativePath));
|
||||||
time_t destDate = mDestFiles.valueFor(mDestPath.appendPathCopy(relativePath));
|
time_t destDate = mDestFiles.valueFor(mDestPath.appendPathCopy(relativePath));
|
||||||
return sourceDate > destDate;
|
return sourceDate > destDate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
#include <png.h>
|
#include <png.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#define NOISY(x) //x
|
// Change this to true for noisy debug output.
|
||||||
|
static const bool kIsDebug = false;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
png_write_aapt_file(png_structp png_ptr, png_bytep data, png_size_t length)
|
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
|
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);
|
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) {
|
||||||
imageName,
|
printf("Image %s: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
|
||||||
(int)outImageInfo->width, (int)outImageInfo->height,
|
imageName,
|
||||||
bit_depth, color_type,
|
(int)outImageInfo->width, (int)outImageInfo->height,
|
||||||
interlace_type, compression_type));
|
bit_depth, color_type,
|
||||||
|
interlace_type, compression_type);
|
||||||
|
}
|
||||||
|
|
||||||
png_get_IHDR(read_ptr, read_info, &outImageInfo->width,
|
png_get_IHDR(read_ptr, read_info, &outImageInfo->width,
|
||||||
&outImageInfo->height, &bit_depth, &color_type,
|
&outImageInfo->height, &bit_depth, &color_type,
|
||||||
@@ -312,7 +315,7 @@ static status_t get_vertical_ticks(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static status_t get_horizontal_layout_bounds_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)
|
int32_t* outLeft, int32_t* outRight, const char** outError)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -350,7 +353,7 @@ static status_t get_horizontal_layout_bounds_ticks(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static status_t get_vertical_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)
|
int32_t* outTop, int32_t* outBottom, const char** outError)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -418,41 +421,6 @@ static uint32_t get_color(
|
|||||||
return (color[3]<<24) | (color[0]<<16) | (color[1]<<8) | color[2];
|
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)
|
static status_t do_9patch(const char* imageName, image_info* image)
|
||||||
{
|
{
|
||||||
image->is9Patch = true;
|
image->is9Patch = true;
|
||||||
@@ -557,8 +525,10 @@ static status_t do_9patch(const char* imageName, image_info* image)
|
|||||||
|| image->layoutBoundsBottom != 0;
|
|| image->layoutBoundsBottom != 0;
|
||||||
|
|
||||||
if (image->haveLayoutBounds) {
|
if (image->haveLayoutBounds) {
|
||||||
NOISY(printf("layoutBounds=%d %d %d %d\n", image->layoutBoundsLeft, image->layoutBoundsTop,
|
if (kIsDebug) {
|
||||||
image->layoutBoundsRight, image->layoutBoundsBottom));
|
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.
|
// 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;
|
image->info9Patch.paddingBottom = H - 2 - image->info9Patch.paddingBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("Size ticks for %s: x0=%d, x1=%d, y0=%d, y1=%d\n", imageName,
|
if (kIsDebug) {
|
||||||
image->info9Patch.xDivs[0], image->info9Patch.xDivs[1],
|
printf("Size ticks for %s: x0=%d, x1=%d, y0=%d, y1=%d\n", imageName,
|
||||||
image->info9Patch.yDivs[0], image->info9Patch.yDivs[1]));
|
image->info9Patch.getXDivs()[0], image->info9Patch.getXDivs()[1],
|
||||||
NOISY(printf("padding ticks for %s: l=%d, r=%d, t=%d, b=%d\n", imageName,
|
image->info9Patch.getYDivs()[0], image->info9Patch.getYDivs()[1]);
|
||||||
image->info9Patch.paddingLeft, image->info9Patch.paddingRight,
|
printf("padding ticks for %s: l=%d, r=%d, t=%d, b=%d\n", imageName,
|
||||||
image->info9Patch.paddingTop, image->info9Patch.paddingBottom));
|
image->info9Patch.paddingLeft, image->info9Patch.paddingRight,
|
||||||
|
image->info9Patch.paddingTop, image->info9Patch.paddingBottom);
|
||||||
|
}
|
||||||
|
|
||||||
// Remove frame from image.
|
// Remove frame from image.
|
||||||
image->rows = (png_bytepp)malloc((H-2) * sizeof(png_bytep));
|
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);
|
c = get_color(image->rows, left, top, right - 1, bottom - 1);
|
||||||
image->colors[colorIndex++] = c;
|
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;
|
left = right;
|
||||||
}
|
}
|
||||||
top = bottom;
|
top = bottom;
|
||||||
@@ -767,7 +742,7 @@ static void dump_image(int w, int h, png_bytepp rows, int color_type)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i == (w - 1)) {
|
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)
|
// 2. Every pixel has A == 255 (opaque)
|
||||||
// 3. There are no more than 256 distinct RGBA colors
|
// 3. There are no more than 256 distinct RGBA colors
|
||||||
|
|
||||||
// NOISY(printf("Initial image data:\n"));
|
if (kIsDebug) {
|
||||||
// dump_image(w, h, imageInfo.rows, PNG_COLOR_TYPE_RGB_ALPHA);
|
printf("Initial image data:\n");
|
||||||
|
dump_image(w, h, imageInfo.rows, PNG_COLOR_TYPE_RGB_ALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
for (j = 0; j < h; j++) {
|
for (j = 0; j < h; j++) {
|
||||||
png_bytep row = imageInfo.rows[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(gg - bb), maxGrayDeviation);
|
||||||
maxGrayDeviation = MAX(ABS(bb - rr), maxGrayDeviation);
|
maxGrayDeviation = MAX(ABS(bb - rr), maxGrayDeviation);
|
||||||
if (maxGrayDeviation > odev) {
|
if (maxGrayDeviation > odev) {
|
||||||
NOISY(printf("New max dev. = %d at pixel (%d, %d) = (%d %d %d %d)\n",
|
if (kIsDebug) {
|
||||||
maxGrayDeviation, i, j, rr, gg, bb, aa));
|
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
|
// Check if image is really grayscale
|
||||||
if (isGrayscale) {
|
if (isGrayscale) {
|
||||||
if (rr != gg || rr != bb) {
|
if (rr != gg || rr != bb) {
|
||||||
NOISY(printf("Found a non-gray pixel at %d, %d = (%d %d %d %d)\n",
|
if (kIsDebug) {
|
||||||
i, j, rr, gg, bb, aa));
|
printf("Found a non-gray pixel at %d, %d = (%d %d %d %d)\n",
|
||||||
|
i, j, rr, gg, bb, aa);
|
||||||
|
}
|
||||||
isGrayscale = false;
|
isGrayscale = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -830,8 +811,10 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
|
|||||||
// Check if image is really opaque
|
// Check if image is really opaque
|
||||||
if (isOpaque) {
|
if (isOpaque) {
|
||||||
if (aa != 0xff) {
|
if (aa != 0xff) {
|
||||||
NOISY(printf("Found a non-opaque pixel at %d, %d = (%d %d %d %d)\n",
|
if (kIsDebug) {
|
||||||
i, j, rr, gg, bb, aa));
|
printf("Found a non-opaque pixel at %d, %d = (%d %d %d %d)\n",
|
||||||
|
i, j, rr, gg, bb, aa);
|
||||||
|
}
|
||||||
isOpaque = false;
|
isOpaque = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -853,7 +836,9 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
|
|||||||
*out++ = idx;
|
*out++ = idx;
|
||||||
if (!match) {
|
if (!match) {
|
||||||
if (num_colors == 256) {
|
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;
|
isPalette = false;
|
||||||
} else {
|
} else {
|
||||||
colors[num_colors++] = col;
|
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 bpp = isOpaque ? 3 : 4;
|
||||||
int paletteSize = w * h + bpp * num_colors;
|
int paletteSize = w * h + bpp * num_colors;
|
||||||
|
|
||||||
NOISY(printf("isGrayscale = %s\n", isGrayscale ? "true" : "false"));
|
if (kIsDebug) {
|
||||||
NOISY(printf("isOpaque = %s\n", isOpaque ? "true" : "false"));
|
printf("isGrayscale = %s\n", isGrayscale ? "true" : "false");
|
||||||
NOISY(printf("isPalette = %s\n", isPalette ? "true" : "false"));
|
printf("isOpaque = %s\n", isOpaque ? "true" : "false");
|
||||||
NOISY(printf("Size w/ palette = %d, gray+alpha = %d, rgb(a) = %d\n",
|
printf("isPalette = %s\n", isPalette ? "true" : "false");
|
||||||
paletteSize, 2 * w * h, bpp * w * h));
|
printf("Size w/ palette = %d, gray+alpha = %d, rgb(a) = %d\n",
|
||||||
NOISY(printf("Max gray deviation = %d, tolerance = %d\n", maxGrayDeviation, grayscaleTolerance));
|
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.
|
// Choose the best color type for the image.
|
||||||
// 1. Opaque gray - use COLOR_TYPE_GRAY at 1 byte/pixel
|
// 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,
|
png_structp write_ptr, png_infop write_info,
|
||||||
image_info& imageInfo, int grayscaleTolerance)
|
image_info& imageInfo, int grayscaleTolerance)
|
||||||
{
|
{
|
||||||
bool optimize = true;
|
|
||||||
png_uint_32 width, height;
|
png_uint_32 width, height;
|
||||||
int color_type;
|
int color_type;
|
||||||
int bit_depth, interlace_type, compression_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);
|
png_set_compression_level(write_ptr, Z_BEST_COMPRESSION);
|
||||||
|
|
||||||
NOISY(printf("Writing image %s: w = %d, h = %d\n", imageName,
|
if (kIsDebug) {
|
||||||
(int) imageInfo.width, (int) imageInfo.height));
|
printf("Writing image %s: w = %d, h = %d\n", imageName,
|
||||||
|
(int) imageInfo.width, (int) imageInfo.height);
|
||||||
|
}
|
||||||
|
|
||||||
png_color rgbPalette[256];
|
png_color rgbPalette[256];
|
||||||
png_byte alphaPalette[256];
|
png_byte alphaPalette[256];
|
||||||
@@ -993,24 +981,26 @@ static void write_png(const char* imageName,
|
|||||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (color_type) {
|
if (kIsDebug) {
|
||||||
case PNG_COLOR_TYPE_PALETTE:
|
switch (color_type) {
|
||||||
NOISY(printf("Image %s has %d colors%s, using PNG_COLOR_TYPE_PALETTE\n",
|
case PNG_COLOR_TYPE_PALETTE:
|
||||||
imageName, paletteEntries,
|
printf("Image %s has %d colors%s, using PNG_COLOR_TYPE_PALETTE\n",
|
||||||
hasTransparency ? " (with alpha)" : ""));
|
imageName, paletteEntries,
|
||||||
break;
|
hasTransparency ? " (with alpha)" : "");
|
||||||
case PNG_COLOR_TYPE_GRAY:
|
break;
|
||||||
NOISY(printf("Image %s is opaque gray, using PNG_COLOR_TYPE_GRAY\n", imageName));
|
case PNG_COLOR_TYPE_GRAY:
|
||||||
break;
|
printf("Image %s is opaque gray, using PNG_COLOR_TYPE_GRAY\n", imageName);
|
||||||
case PNG_COLOR_TYPE_GRAY_ALPHA:
|
break;
|
||||||
NOISY(printf("Image %s is gray + alpha, using PNG_COLOR_TYPE_GRAY_ALPHA\n", imageName));
|
case PNG_COLOR_TYPE_GRAY_ALPHA:
|
||||||
break;
|
printf("Image %s is gray + alpha, using PNG_COLOR_TYPE_GRAY_ALPHA\n", imageName);
|
||||||
case PNG_COLOR_TYPE_RGB:
|
break;
|
||||||
NOISY(printf("Image %s is opaque RGB, using PNG_COLOR_TYPE_RGB\n", imageName));
|
case PNG_COLOR_TYPE_RGB:
|
||||||
break;
|
printf("Image %s is opaque RGB, using PNG_COLOR_TYPE_RGB\n", imageName);
|
||||||
case PNG_COLOR_TYPE_RGB_ALPHA:
|
break;
|
||||||
NOISY(printf("Image %s is RGB + alpha, using PNG_COLOR_TYPE_RGB_ALPHA\n", imageName));
|
case PNG_COLOR_TYPE_RGB_ALPHA:
|
||||||
break;
|
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,
|
png_set_IHDR(write_ptr, write_info, imageInfo.width, imageInfo.height,
|
||||||
@@ -1034,7 +1024,9 @@ static void write_png(const char* imageName,
|
|||||||
png_byte *chunk_names = imageInfo.haveLayoutBounds
|
png_byte *chunk_names = imageInfo.haveLayoutBounds
|
||||||
? (png_byte*)"npLb\0npTc\0"
|
? (png_byte*)"npLb\0npTc\0"
|
||||||
: (png_byte*)"npTc";
|
: (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");
|
strcpy((char*)unknowns[p_index].name, "npTc");
|
||||||
unknowns[p_index].data = (png_byte*)imageInfo.serialize9patch();
|
unknowns[p_index].data = (png_byte*)imageInfo.serialize9patch();
|
||||||
unknowns[p_index].size = imageInfo.info9Patch.serializedSize();
|
unknowns[p_index].size = imageInfo.info9Patch.serializedSize();
|
||||||
@@ -1078,8 +1070,10 @@ static void write_png(const char* imageName,
|
|||||||
}
|
}
|
||||||
png_write_image(write_ptr, rows);
|
png_write_image(write_ptr, rows);
|
||||||
|
|
||||||
// NOISY(printf("Final image data:\n"));
|
if (kIsDebug) {
|
||||||
// dump_image(imageInfo.width, imageInfo.height, rows, color_type);
|
printf("Final image data:\n");
|
||||||
|
dump_image(imageInfo.width, imageInfo.height, rows, color_type);
|
||||||
|
}
|
||||||
|
|
||||||
png_write_end(write_ptr, write_info);
|
png_write_end(write_ptr, write_info);
|
||||||
|
|
||||||
@@ -1094,13 +1088,15 @@ static void write_png(const char* imageName,
|
|||||||
&bit_depth, &color_type, &interlace_type,
|
&bit_depth, &color_type, &interlace_type,
|
||||||
&compression_type, NULL);
|
&compression_type, NULL);
|
||||||
|
|
||||||
NOISY(printf("Image written: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
|
if (kIsDebug) {
|
||||||
(int)width, (int)height, bit_depth, color_type, interlace_type,
|
printf("Image written: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
|
||||||
compression_type));
|
(int)width, (int)height, bit_depth, color_type, interlace_type,
|
||||||
|
compression_type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& assets,
|
status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& /* assets */,
|
||||||
const sp<AaptFile>& file, String8* outNewLeafName)
|
const sp<AaptFile>& file, String8* /* outNewLeafName */)
|
||||||
{
|
{
|
||||||
String8 ext(file->getPath().getPathExtension());
|
String8 ext(file->getPath().getPathExtension());
|
||||||
|
|
||||||
|
|||||||
@@ -455,7 +455,6 @@ bool endsWith(const char* haystack, const char* needle)
|
|||||||
|
|
||||||
ssize_t processJarFile(ZipFile* jar, ZipFile* out)
|
ssize_t processJarFile(ZipFile* jar, ZipFile* out)
|
||||||
{
|
{
|
||||||
status_t err;
|
|
||||||
size_t N = jar->getNumEntries();
|
size_t N = jar->getNumEntries();
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
for (size_t i=0; i<N; i++) {
|
for (size_t i=0; i<N; i++) {
|
||||||
|
|||||||
@@ -16,15 +16,19 @@
|
|||||||
|
|
||||||
#include "WorkQueue.h"
|
#include "WorkQueue.h"
|
||||||
|
|
||||||
|
// STATUST: mingw does seem to redefine UNKNOWN_ERROR from our enum value, so a cast is necessary.
|
||||||
#if HAVE_PRINTF_ZD
|
#if HAVE_PRINTF_ZD
|
||||||
# define ZD "%zd"
|
# define ZD "%zd"
|
||||||
# define ZD_TYPE ssize_t
|
# define ZD_TYPE ssize_t
|
||||||
|
# define STATUST(x) x
|
||||||
#else
|
#else
|
||||||
# define ZD "%ld"
|
# define ZD "%ld"
|
||||||
# define ZD_TYPE long
|
# define ZD_TYPE long
|
||||||
|
# define STATUST(x) (status_t)x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NOISY(x) // x
|
// Set to true for noisy debug output.
|
||||||
|
static const bool kIsDebug = false;
|
||||||
|
|
||||||
// Number of threads to use for preprocessing images.
|
// Number of threads to use for preprocessing images.
|
||||||
static const size_t MAX_THREADS = 4;
|
static const size_t MAX_THREADS = 4;
|
||||||
@@ -125,15 +129,17 @@ public:
|
|||||||
String8 leaf(group->getLeaf());
|
String8 leaf(group->getLeaf());
|
||||||
mLeafName = String8(leaf);
|
mLeafName = String8(leaf);
|
||||||
mParams = file->getGroupEntry().toParams();
|
mParams = file->getGroupEntry().toParams();
|
||||||
NOISY(printf("Dir %s: mcc=%d mnc=%d lang=%c%c cnt=%c%c orient=%d ui=%d density=%d touch=%d key=%d inp=%d nav=%d\n",
|
if (kIsDebug) {
|
||||||
group->getPath().string(), mParams.mcc, mParams.mnc,
|
printf("Dir %s: mcc=%d mnc=%d lang=%c%c cnt=%c%c orient=%d ui=%d density=%d touch=%d key=%d inp=%d nav=%d\n",
|
||||||
mParams.language[0] ? mParams.language[0] : '-',
|
group->getPath().string(), mParams.mcc, mParams.mnc,
|
||||||
mParams.language[1] ? mParams.language[1] : '-',
|
mParams.language[0] ? mParams.language[0] : '-',
|
||||||
mParams.country[0] ? mParams.country[0] : '-',
|
mParams.language[1] ? mParams.language[1] : '-',
|
||||||
mParams.country[1] ? mParams.country[1] : '-',
|
mParams.country[0] ? mParams.country[0] : '-',
|
||||||
mParams.orientation, mParams.uiMode,
|
mParams.country[1] ? mParams.country[1] : '-',
|
||||||
mParams.density, mParams.touchscreen, mParams.keyboard,
|
mParams.orientation, mParams.uiMode,
|
||||||
mParams.inputFlags, mParams.navigation));
|
mParams.density, mParams.touchscreen, mParams.keyboard,
|
||||||
|
mParams.inputFlags, mParams.navigation);
|
||||||
|
}
|
||||||
mPath = "res";
|
mPath = "res";
|
||||||
mPath.appendPath(file->getGroupEntry().toDirName(mResType));
|
mPath.appendPath(file->getGroupEntry().toDirName(mResType));
|
||||||
mPath.appendPath(leaf);
|
mPath.appendPath(leaf);
|
||||||
@@ -144,7 +150,9 @@ public:
|
|||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("file name=%s\n", mBaseName.string()));
|
if (kIsDebug) {
|
||||||
|
printf("file name=%s\n", mBaseName.string());
|
||||||
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
@@ -306,7 +314,7 @@ static status_t makeFileResources(Bundle* bundle, const sp<AaptAssets>& assets,
|
|||||||
assets->addResource(it.getLeafName(), resPath, it.getFile(), type8);
|
assets->addResource(it.getLeafName(), resPath, it.getFile(), type8);
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
|
return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PreProcessImageWorkUnit : public WorkQueue::WorkUnit {
|
class PreProcessImageWorkUnit : public WorkQueue::WorkUnit {
|
||||||
@@ -356,7 +364,7 @@ static status_t preProcessImages(const Bundle* bundle, const sp<AaptAssets>& ass
|
|||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (hasErrors || (res < NO_ERROR)) ? UNKNOWN_ERROR : NO_ERROR;
|
return (hasErrors || (res < NO_ERROR)) ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t postProcessImages(const sp<AaptAssets>& assets,
|
status_t postProcessImages(const sp<AaptAssets>& assets,
|
||||||
@@ -373,7 +381,7 @@ status_t postProcessImages(const sp<AaptAssets>& assets,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (hasErrors || (res < NO_ERROR)) ? UNKNOWN_ERROR : NO_ERROR;
|
return (hasErrors || (res < NO_ERROR)) ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void collect_files(const sp<AaptDir>& dir,
|
static void collect_files(const sp<AaptDir>& dir,
|
||||||
@@ -398,27 +406,35 @@ static void collect_files(const sp<AaptDir>& dir,
|
|||||||
|
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
sp<ResourceTypeSet> set = new ResourceTypeSet();
|
sp<ResourceTypeSet> set = new ResourceTypeSet();
|
||||||
NOISY(printf("Creating new resource type set for leaf %s with group %s (%p)\n",
|
if (kIsDebug) {
|
||||||
leafName.string(), group->getPath().string(), group.get()));
|
printf("Creating new resource type set for leaf %s with group %s (%p)\n",
|
||||||
|
leafName.string(), group->getPath().string(), group.get());
|
||||||
|
}
|
||||||
set->add(leafName, group);
|
set->add(leafName, group);
|
||||||
resources->add(resType, set);
|
resources->add(resType, set);
|
||||||
} else {
|
} else {
|
||||||
sp<ResourceTypeSet> set = resources->valueAt(index);
|
sp<ResourceTypeSet> set = resources->valueAt(index);
|
||||||
index = set->indexOfKey(leafName);
|
index = set->indexOfKey(leafName);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
NOISY(printf("Adding to resource type set for leaf %s group %s (%p)\n",
|
if (kIsDebug) {
|
||||||
leafName.string(), group->getPath().string(), group.get()));
|
printf("Adding to resource type set for leaf %s group %s (%p)\n",
|
||||||
|
leafName.string(), group->getPath().string(), group.get());
|
||||||
|
}
|
||||||
set->add(leafName, group);
|
set->add(leafName, group);
|
||||||
} else {
|
} else {
|
||||||
sp<AaptGroup> existingGroup = set->valueAt(index);
|
sp<AaptGroup> existingGroup = set->valueAt(index);
|
||||||
NOISY(printf("Extending to resource type set for leaf %s group %s (%p)\n",
|
if (kIsDebug) {
|
||||||
leafName.string(), group->getPath().string(), group.get()));
|
printf("Extending to resource type set for leaf %s group %s (%p)\n",
|
||||||
|
leafName.string(), group->getPath().string(), group.get());
|
||||||
|
}
|
||||||
for (size_t j=0; j<files.size(); j++) {
|
for (size_t j=0; j<files.size(); j++) {
|
||||||
NOISY(printf("Adding file %s in group %s resType %s\n",
|
if (kIsDebug) {
|
||||||
files.valueAt(j)->getSourceFile().string(),
|
printf("Adding file %s in group %s resType %s\n",
|
||||||
files.keyAt(j).toDirName(String8()).string(),
|
files.valueAt(j)->getSourceFile().string(),
|
||||||
resType.string()));
|
files.keyAt(j).toDirName(String8()).string(),
|
||||||
status_t err = existingGroup->addFile(files.valueAt(j));
|
resType.string());
|
||||||
|
}
|
||||||
|
existingGroup->addFile(files.valueAt(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -433,12 +449,16 @@ static void collect_files(const sp<AaptAssets>& ass,
|
|||||||
|
|
||||||
for (int i=0; i<N; i++) {
|
for (int i=0; i<N; i++) {
|
||||||
sp<AaptDir> d = dirs.itemAt(i);
|
sp<AaptDir> d = dirs.itemAt(i);
|
||||||
NOISY(printf("Collecting dir #%d %p: %s, leaf %s\n", i, d.get(), d->getPath().string(),
|
if (kIsDebug) {
|
||||||
d->getLeaf().string()));
|
printf("Collecting dir #%d %p: %s, leaf %s\n", i, d.get(), d->getPath().string(),
|
||||||
|
d->getLeaf().string());
|
||||||
|
}
|
||||||
collect_files(d, resources);
|
collect_files(d, resources);
|
||||||
|
|
||||||
// don't try to include the res dir
|
// don't try to include the res dir
|
||||||
NOISY(printf("Removing dir leaf %s\n", d->getLeaf().string()));
|
if (kIsDebug) {
|
||||||
|
printf("Removing dir leaf %s\n", d->getLeaf().string());
|
||||||
|
}
|
||||||
ass->removeDir(d->getLeaf());
|
ass->removeDir(d->getLeaf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -595,11 +615,11 @@ static bool applyFileOverlay(Bundle *bundle,
|
|||||||
if (bundle->getVerbose()) {
|
if (bundle->getVerbose()) {
|
||||||
printf("trying overlaySet Key=%s\n",overlaySet->keyAt(overlayIndex).string());
|
printf("trying overlaySet Key=%s\n",overlaySet->keyAt(overlayIndex).string());
|
||||||
}
|
}
|
||||||
size_t baseIndex = UNKNOWN_ERROR;
|
ssize_t baseIndex = UNKNOWN_ERROR;
|
||||||
if (baseSet->get() != NULL) {
|
if (baseSet->get() != NULL) {
|
||||||
baseIndex = (*baseSet)->indexOfKey(overlaySet->keyAt(overlayIndex));
|
baseIndex = (*baseSet)->indexOfKey(overlaySet->keyAt(overlayIndex));
|
||||||
}
|
}
|
||||||
if (baseIndex < UNKNOWN_ERROR) {
|
if (baseIndex >= 0) {
|
||||||
// look for same flavor. For a given file (strings.xml, for example)
|
// look for same flavor. For a given file (strings.xml, for example)
|
||||||
// there may be a locale specific or other flavors - we want to match
|
// there may be a locale specific or other flavors - we want to match
|
||||||
// the same flavor.
|
// the same flavor.
|
||||||
@@ -625,10 +645,10 @@ static bool applyFileOverlay(Bundle *bundle,
|
|||||||
for (size_t overlayGroupIndex = 0;
|
for (size_t overlayGroupIndex = 0;
|
||||||
overlayGroupIndex<overlayGroupSize;
|
overlayGroupIndex<overlayGroupSize;
|
||||||
overlayGroupIndex++) {
|
overlayGroupIndex++) {
|
||||||
size_t baseFileIndex =
|
ssize_t baseFileIndex =
|
||||||
baseGroup->getFiles().indexOfKey(overlayFiles.
|
baseGroup->getFiles().indexOfKey(overlayFiles.
|
||||||
keyAt(overlayGroupIndex));
|
keyAt(overlayGroupIndex));
|
||||||
if (baseFileIndex < UNKNOWN_ERROR) {
|
if (baseFileIndex >= 0) {
|
||||||
if (bundle->getVerbose()) {
|
if (bundle->getVerbose()) {
|
||||||
printf("found a match (" ZD ") for overlay file %s, for flavor %s\n",
|
printf("found a match (" ZD ") for overlay file %s, for flavor %s\n",
|
||||||
(ZD_TYPE) baseFileIndex,
|
(ZD_TYPE) baseFileIndex,
|
||||||
@@ -734,7 +754,9 @@ static void fullyQualifyClassName(const String8& package, sp<XMLNode> node,
|
|||||||
} else {
|
} else {
|
||||||
className += name;
|
className += name;
|
||||||
}
|
}
|
||||||
NOISY(printf("Qualifying class '%s' to '%s'", name.string(), className.string()));
|
if (kIsDebug) {
|
||||||
|
printf("Qualifying class '%s' to '%s'", name.string(), className.string());
|
||||||
|
}
|
||||||
attr->string.setTo(String16(className));
|
attr->string.setTo(String16(className));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -802,7 +824,10 @@ status_t massageManifest(Bundle* bundle, sp<XMLNode> root)
|
|||||||
}
|
}
|
||||||
String8 origPackage(attr->string);
|
String8 origPackage(attr->string);
|
||||||
attr->string.setTo(String16(manifestPackageNameOverride));
|
attr->string.setTo(String16(manifestPackageNameOverride));
|
||||||
NOISY(printf("Overriding package '%s' to be '%s'\n", origPackage.string(), manifestPackageNameOverride));
|
if (kIsDebug) {
|
||||||
|
printf("Overriding package '%s' to be '%s'\n", origPackage.string(),
|
||||||
|
manifestPackageNameOverride);
|
||||||
|
}
|
||||||
|
|
||||||
// Make class names fully qualified
|
// Make class names fully qualified
|
||||||
sp<XMLNode> application = root->getChildElement(String16(), String16("application"));
|
sp<XMLNode> application = root->getChildElement(String16(), String16("application"));
|
||||||
@@ -898,8 +923,9 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("Creating resources for package %s\n",
|
if (kIsDebug) {
|
||||||
assets->getPackage().string()));
|
printf("Creating resources for package %s\n", assets->getPackage().string());
|
||||||
|
}
|
||||||
|
|
||||||
ResourceTable table(bundle, String16(assets->getPackage()));
|
ResourceTable table(bundle, String16(assets->getPackage()));
|
||||||
err = table.addIncludedResources(bundle, assets);
|
err = table.addIncludedResources(bundle, assets);
|
||||||
@@ -907,7 +933,9 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("Found %d included resource packages\n", (int)table.size()));
|
if (kIsDebug) {
|
||||||
|
printf("Found %d included resource packages\n", (int)table.size());
|
||||||
|
}
|
||||||
|
|
||||||
// Standard flags for compiled XML and optional UTF-8 encoding
|
// Standard flags for compiled XML and optional UTF-8 encoding
|
||||||
int xmlFlags = XML_COMPILE_STANDARD_RESOURCE;
|
int xmlFlags = XML_COMPILE_STANDARD_RESOURCE;
|
||||||
@@ -1322,12 +1350,6 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
|
|||||||
|
|
||||||
// Read resources back in,
|
// Read resources back in,
|
||||||
finalResTable.add(resFile->getData(), resFile->getSize());
|
finalResTable.add(resFile->getData(), resFile->getSize());
|
||||||
#if 0
|
|
||||||
NOISY(
|
|
||||||
printf("Generated resources:\n");
|
|
||||||
finalResTable.print();
|
|
||||||
)
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform a basic validation of the manifest file. This time we
|
// Perform a basic validation of the manifest file. This time we
|
||||||
@@ -1889,7 +1911,7 @@ static status_t writeLayoutClasses(
|
|||||||
|
|
||||||
indent--;
|
indent--;
|
||||||
fprintf(fp, "%s};\n", getIndentSpace(indent));
|
fprintf(fp, "%s};\n", getIndentSpace(indent));
|
||||||
return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
|
return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static status_t writeTextLayoutClasses(
|
static status_t writeTextLayoutClasses(
|
||||||
@@ -1975,7 +1997,7 @@ static status_t writeTextLayoutClasses(
|
|||||||
package16.string(), package16.size(), &typeSpecFlags);
|
package16.string(), package16.size(), &typeSpecFlags);
|
||||||
//printf("%s:%s/%s: 0x%08x\n", String8(package16).string(),
|
//printf("%s:%s/%s: 0x%08x\n", String8(package16).string(),
|
||||||
// String8(attr16).string(), String8(name16).string(), typeSpecFlags);
|
// String8(attr16).string(), String8(name16).string(), typeSpecFlags);
|
||||||
const bool pub = (typeSpecFlags&ResTable_typeSpec::SPEC_PUBLIC) != 0;
|
//const bool pub = (typeSpecFlags&ResTable_typeSpec::SPEC_PUBLIC) != 0;
|
||||||
|
|
||||||
fprintf(fp,
|
fprintf(fp,
|
||||||
"int styleable %s_%s %d\n",
|
"int styleable %s_%s %d\n",
|
||||||
@@ -1985,7 +2007,7 @@ static status_t writeTextLayoutClasses(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
|
return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static status_t writeSymbolClass(
|
static status_t writeSymbolClass(
|
||||||
@@ -2318,7 +2340,7 @@ addProguardKeepRule(ProguardKeepSet* keep, const String8& inClassName,
|
|||||||
|
|
||||||
void
|
void
|
||||||
addProguardKeepMethodRule(ProguardKeepSet* keep, const String8& memberName,
|
addProguardKeepMethodRule(ProguardKeepSet* keep, const String8& memberName,
|
||||||
const char* pkg, const String8& srcName, int line)
|
const char* /* pkg */, const String8& srcName, int line)
|
||||||
{
|
{
|
||||||
String8 rule("-keepclassmembers class * { *** ");
|
String8 rule("-keepclassmembers class * { *** ");
|
||||||
rule += memberName;
|
rule += memberName;
|
||||||
@@ -2640,7 +2662,7 @@ status_t writePathsToFile(const sp<FilePathStore>& files, FILE* fp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
writeDependencyPreReqs(Bundle* bundle, const sp<AaptAssets>& assets, FILE* fp, bool includeRaw)
|
writeDependencyPreReqs(Bundle* /* bundle */, const sp<AaptAssets>& assets, FILE* fp, bool includeRaw)
|
||||||
{
|
{
|
||||||
status_t deps = -1;
|
status_t deps = -1;
|
||||||
deps += writePathsToFile(assets->getFullResPaths(), fp);
|
deps += writePathsToFile(assets->getFullResPaths(), fp);
|
||||||
|
|||||||
@@ -97,10 +97,10 @@ uint32_t ResourceIdCache::store(const android::String16& package,
|
|||||||
|
|
||||||
void ResourceIdCache::dump() {
|
void ResourceIdCache::dump() {
|
||||||
printf("ResourceIdCache dump:\n");
|
printf("ResourceIdCache dump:\n");
|
||||||
printf("Size: %ld\n", mIdMap.size());
|
printf("Size: %zu\n", mIdMap.size());
|
||||||
printf("Hits: %ld\n", mHits);
|
printf("Hits: %zu\n", mHits);
|
||||||
printf("Misses: %ld\n", mMisses);
|
printf("Misses: %zu\n", mMisses);
|
||||||
printf("(Collisions: %ld)\n", mCollisions);
|
printf("(Collisions: %zu)\n", mCollisions);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,24 @@
|
|||||||
#include <utils/ByteOrder.h>
|
#include <utils/ByteOrder.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define NOISY(x) //x
|
// SSIZE: mingw does not have signed size_t == ssize_t.
|
||||||
|
// STATUST: mingw does seem to redefine UNKNOWN_ERROR from our enum value, so a cast is necessary.
|
||||||
|
#if HAVE_PRINTF_ZD
|
||||||
|
# define SSIZE(x) x
|
||||||
|
# define STATUST(x) x
|
||||||
|
#else
|
||||||
|
# define SSIZE(x) (signed size_t)x
|
||||||
|
# define STATUST(x) (status_t)x
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Set to true for noisy debug output.
|
||||||
|
static const bool kIsDebug = false;
|
||||||
|
|
||||||
|
#if PRINT_STRING_METRICS
|
||||||
|
static const bool kPrintStringMetrics = true;
|
||||||
|
#else
|
||||||
|
static const bool kPrintStringMetrics = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
status_t compileXmlFile(const sp<AaptAssets>& assets,
|
status_t compileXmlFile(const sp<AaptAssets>& assets,
|
||||||
const sp<AaptFile>& target,
|
const sp<AaptFile>& target,
|
||||||
@@ -76,9 +93,11 @@ status_t compileXmlFile(const sp<AaptAssets>& assets,
|
|||||||
if (hasErrors) {
|
if (hasErrors) {
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("Input XML Resource:\n"));
|
if (kIsDebug) {
|
||||||
NOISY(root->print());
|
printf("Input XML Resource:\n");
|
||||||
|
root->print();
|
||||||
|
}
|
||||||
err = root->flatten(target,
|
err = root->flatten(target,
|
||||||
(options&XML_COMPILE_STRIP_COMMENTS) != 0,
|
(options&XML_COMPILE_STRIP_COMMENTS) != 0,
|
||||||
(options&XML_COMPILE_STRIP_RAW_VALUES) != 0);
|
(options&XML_COMPILE_STRIP_RAW_VALUES) != 0);
|
||||||
@@ -86,19 +105,18 @@ status_t compileXmlFile(const sp<AaptAssets>& assets,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("Output XML Resource:\n"));
|
if (kIsDebug) {
|
||||||
NOISY(ResXMLTree tree;
|
printf("Output XML Resource:\n");
|
||||||
|
ResXMLTree tree;
|
||||||
tree.setTo(target->getData(), target->getSize());
|
tree.setTo(target->getData(), target->getSize());
|
||||||
printXMLBlock(&tree));
|
printXMLBlock(&tree);
|
||||||
|
}
|
||||||
|
|
||||||
target->setCompressionMethod(ZipEntry::kCompressDeflated);
|
target->setCompressionMethod(ZipEntry::kCompressDeflated);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef NOISY
|
|
||||||
#define NOISY(x) //x
|
|
||||||
|
|
||||||
struct flag_entry
|
struct flag_entry
|
||||||
{
|
{
|
||||||
const char16_t* name;
|
const char16_t* name;
|
||||||
@@ -576,7 +594,7 @@ status_t parseAndAddBag(Bundle* bundle,
|
|||||||
const String16& itemIdent,
|
const String16& itemIdent,
|
||||||
int32_t curFormat,
|
int32_t curFormat,
|
||||||
bool isFormatted,
|
bool isFormatted,
|
||||||
const String16& product,
|
const String16& /* product */,
|
||||||
PseudolocalizationMethod pseudolocalize,
|
PseudolocalizationMethod pseudolocalize,
|
||||||
const bool overwrite,
|
const bool overwrite,
|
||||||
ResourceTable* outTable)
|
ResourceTable* outTable)
|
||||||
@@ -592,16 +610,18 @@ status_t parseAndAddBag(Bundle* bundle,
|
|||||||
if (err != NO_ERROR) {
|
if (err != NO_ERROR) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("Adding resource bag entry l=%c%c c=%c%c orien=%d d=%d "
|
if (kIsDebug) {
|
||||||
" pid=%s, bag=%s, id=%s: %s\n",
|
printf("Adding resource bag entry l=%c%c c=%c%c orien=%d d=%d "
|
||||||
config.language[0], config.language[1],
|
" pid=%s, bag=%s, id=%s: %s\n",
|
||||||
config.country[0], config.country[1],
|
config.language[0], config.language[1],
|
||||||
config.orientation, config.density,
|
config.country[0], config.country[1],
|
||||||
String8(parentIdent).string(),
|
config.orientation, config.density,
|
||||||
String8(ident).string(),
|
String8(parentIdent).string(),
|
||||||
String8(itemIdent).string(),
|
String8(ident).string(),
|
||||||
String8(str).string()));
|
String8(itemIdent).string(),
|
||||||
|
String8(str).string());
|
||||||
|
}
|
||||||
|
|
||||||
err = outTable->addBag(SourcePos(in->getPrintableSource(), block->getLineNumber()),
|
err = outTable->addBag(SourcePos(in->getPrintableSource(), block->getLineNumber()),
|
||||||
myPackage, curType, ident, parentIdent, itemIdent, str,
|
myPackage, curType, ident, parentIdent, itemIdent, str,
|
||||||
@@ -737,11 +757,13 @@ status_t parseAndAddEntry(Bundle* bundle,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("Adding resource entry l=%c%c c=%c%c orien=%d d=%d id=%s: %s\n",
|
if (kIsDebug) {
|
||||||
config.language[0], config.language[1],
|
printf("Adding resource entry l=%c%c c=%c%c orien=%d d=%d id=%s: %s\n",
|
||||||
config.country[0], config.country[1],
|
config.language[0], config.language[1],
|
||||||
config.orientation, config.density,
|
config.country[0], config.country[1],
|
||||||
String8(ident).string(), String8(str).string()));
|
config.orientation, config.density,
|
||||||
|
String8(ident).string(), String8(str).string());
|
||||||
|
}
|
||||||
|
|
||||||
err = outTable->addEntry(SourcePos(in->getPrintableSource(), block->getLineNumber()),
|
err = outTable->addEntry(SourcePos(in->getPrintableSource(), block->getLineNumber()),
|
||||||
myPackage, curType, ident, str, &spans, &config,
|
myPackage, curType, ident, str, &spans, &config,
|
||||||
@@ -1710,7 +1732,7 @@ status_t compileResourceFile(Bundle* bundle,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
|
return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceTable::ResourceTable(Bundle* bundle, const String16& assetsPackage)
|
ResourceTable::ResourceTable(Bundle* bundle, const String16& assetsPackage)
|
||||||
@@ -1764,8 +1786,9 @@ status_t ResourceTable::addIncludedResources(Bundle* bundle, const sp<AaptAssets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (id != 0) {
|
if (id != 0) {
|
||||||
NOISY(printf("Including package %s with ID=%d\n",
|
if (kIsDebug) {
|
||||||
String8(name).string(), id));
|
printf("Including package %s with ID=%d\n", String8(name).string(), id);
|
||||||
|
}
|
||||||
sp<Package> p = new Package(name, id);
|
sp<Package> p = new Package(name, id);
|
||||||
mPackages.add(name, p);
|
mPackages.add(name, p);
|
||||||
mOrderedPackages.add(p);
|
mOrderedPackages.add(p);
|
||||||
@@ -1856,7 +1879,7 @@ status_t ResourceTable::startBag(const SourcePos& sourcePos,
|
|||||||
const String16& bagParent,
|
const String16& bagParent,
|
||||||
const ResTable_config* params,
|
const ResTable_config* params,
|
||||||
bool overlay,
|
bool overlay,
|
||||||
bool replace, bool isId)
|
bool replace, bool /* isId */)
|
||||||
{
|
{
|
||||||
status_t result = NO_ERROR;
|
status_t result = NO_ERROR;
|
||||||
|
|
||||||
@@ -2163,22 +2186,25 @@ uint32_t ResourceTable::getResId(const String16& ref,
|
|||||||
ref.string(), ref.size(), &package, &type, &name,
|
ref.string(), ref.size(), &package, &type, &name,
|
||||||
defType, defPackage ? defPackage:&mAssetsPackage,
|
defType, defPackage ? defPackage:&mAssetsPackage,
|
||||||
outErrorMsg, &refOnlyPublic)) {
|
outErrorMsg, &refOnlyPublic)) {
|
||||||
NOISY(printf("Expanding resource: ref=%s\n",
|
if (kIsDebug) {
|
||||||
String8(ref).string()));
|
printf("Expanding resource: ref=%s\n", String8(ref).string());
|
||||||
NOISY(printf("Expanding resource: defType=%s\n",
|
printf("Expanding resource: defType=%s\n",
|
||||||
defType ? String8(*defType).string() : "NULL"));
|
defType ? String8(*defType).string() : "NULL");
|
||||||
NOISY(printf("Expanding resource: defPackage=%s\n",
|
printf("Expanding resource: defPackage=%s\n",
|
||||||
defPackage ? String8(*defPackage).string() : "NULL"));
|
defPackage ? String8(*defPackage).string() : "NULL");
|
||||||
NOISY(printf("Expanding resource: ref=%s\n", String8(ref).string()));
|
printf("Expanding resource: ref=%s\n", String8(ref).string());
|
||||||
NOISY(printf("Expanded resource: p=%s, t=%s, n=%s, res=0\n",
|
printf("Expanded resource: p=%s, t=%s, n=%s, res=0\n",
|
||||||
String8(package).string(), String8(type).string(),
|
String8(package).string(), String8(type).string(),
|
||||||
String8(name).string()));
|
String8(name).string());
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uint32_t res = getResId(package, type, name, onlyPublic && refOnlyPublic);
|
uint32_t res = getResId(package, type, name, onlyPublic && refOnlyPublic);
|
||||||
NOISY(printf("Expanded resource: p=%s, t=%s, n=%s, res=%d\n",
|
if (kIsDebug) {
|
||||||
String8(package).string(), String8(type).string(),
|
printf("Expanded resource: p=%s, t=%s, n=%s, res=%d\n",
|
||||||
String8(name).string(), res));
|
String8(package).string(), String8(type).string(),
|
||||||
|
String8(name).string(), res);
|
||||||
|
}
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
if (outErrorMsg)
|
if (outErrorMsg)
|
||||||
*outErrorMsg = "No resource found that matches the given name";
|
*outErrorMsg = "No resource found that matches the given name";
|
||||||
@@ -2245,9 +2271,11 @@ bool ResourceTable::stringToValue(Res_value* outValue, StringPool* pool,
|
|||||||
} else {
|
} else {
|
||||||
configStr = "(null)";
|
configStr = "(null)";
|
||||||
}
|
}
|
||||||
NOISY(printf("Adding to pool string style #%d config %s: %s\n",
|
if (kIsDebug) {
|
||||||
style != NULL ? style->size() : 0,
|
printf("Adding to pool string style #%zu config %s: %s\n",
|
||||||
configStr.string(), String8(finalStr).string()));
|
style != NULL ? style->size() : 0U,
|
||||||
|
configStr.string(), String8(finalStr).string());
|
||||||
|
}
|
||||||
if (style != NULL && style->size() > 0) {
|
if (style != NULL && style->size() > 0) {
|
||||||
outValue->data = pool->add(finalStr, *style, configTypeName, config);
|
outValue->data = pool->add(finalStr, *style, configTypeName, config);
|
||||||
} else {
|
} else {
|
||||||
@@ -2851,9 +2879,9 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
|||||||
const size_t typeStringsStart = data->getSize();
|
const size_t typeStringsStart = data->getSize();
|
||||||
sp<AaptFile> strFile = p->getTypeStringsData();
|
sp<AaptFile> strFile = p->getTypeStringsData();
|
||||||
ssize_t amt = data->writeData(strFile->getData(), strFile->getSize());
|
ssize_t amt = data->writeData(strFile->getData(), strFile->getSize());
|
||||||
#if PRINT_STRING_METRICS
|
if (kPrintStringMetrics) {
|
||||||
fprintf(stderr, "**** type strings: %d\n", amt);
|
fprintf(stderr, "**** type strings: %zd\n", SSIZE(amt));
|
||||||
#endif
|
}
|
||||||
strAmt += amt;
|
strAmt += amt;
|
||||||
if (amt < 0) {
|
if (amt < 0) {
|
||||||
return amt;
|
return amt;
|
||||||
@@ -2861,9 +2889,9 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
|||||||
const size_t keyStringsStart = data->getSize();
|
const size_t keyStringsStart = data->getSize();
|
||||||
strFile = p->getKeyStringsData();
|
strFile = p->getKeyStringsData();
|
||||||
amt = data->writeData(strFile->getData(), strFile->getSize());
|
amt = data->writeData(strFile->getData(), strFile->getSize());
|
||||||
#if PRINT_STRING_METRICS
|
if (kPrintStringMetrics) {
|
||||||
fprintf(stderr, "**** key strings: %d\n", amt);
|
fprintf(stderr, "**** key strings: %zd\n", SSIZE(amt));
|
||||||
#endif
|
}
|
||||||
strAmt += amt;
|
strAmt += amt;
|
||||||
if (amt < 0) {
|
if (amt < 0) {
|
||||||
return amt;
|
return amt;
|
||||||
@@ -2942,29 +2970,31 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
|||||||
for (size_t ci=0; ci<NC; ci++) {
|
for (size_t ci=0; ci<NC; ci++) {
|
||||||
ConfigDescription config = t->getUniqueConfigs().itemAt(ci);
|
ConfigDescription config = t->getUniqueConfigs().itemAt(ci);
|
||||||
|
|
||||||
NOISY(printf("Writing config %d config: imsi:%d/%d lang:%c%c cnt:%c%c "
|
if (kIsDebug) {
|
||||||
"orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
|
printf("Writing config %zu config: imsi:%d/%d lang:%c%c cnt:%c%c "
|
||||||
"sw%ddp w%ddp h%ddp dir:%d\n",
|
"orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
|
||||||
ti+1,
|
"sw%ddp w%ddp h%ddp layout:%d\n",
|
||||||
config.mcc, config.mnc,
|
ti + 1,
|
||||||
config.language[0] ? config.language[0] : '-',
|
config.mcc, config.mnc,
|
||||||
config.language[1] ? config.language[1] : '-',
|
config.language[0] ? config.language[0] : '-',
|
||||||
config.country[0] ? config.country[0] : '-',
|
config.language[1] ? config.language[1] : '-',
|
||||||
config.country[1] ? config.country[1] : '-',
|
config.country[0] ? config.country[0] : '-',
|
||||||
config.orientation,
|
config.country[1] ? config.country[1] : '-',
|
||||||
config.uiMode,
|
config.orientation,
|
||||||
config.touchscreen,
|
config.uiMode,
|
||||||
config.density,
|
config.touchscreen,
|
||||||
config.keyboard,
|
config.density,
|
||||||
config.inputFlags,
|
config.keyboard,
|
||||||
config.navigation,
|
config.inputFlags,
|
||||||
config.screenWidth,
|
config.navigation,
|
||||||
config.screenHeight,
|
config.screenWidth,
|
||||||
config.smallestScreenWidthDp,
|
config.screenHeight,
|
||||||
config.screenWidthDp,
|
config.smallestScreenWidthDp,
|
||||||
config.screenHeightDp,
|
config.screenWidthDp,
|
||||||
config.layoutDirection));
|
config.screenHeightDp,
|
||||||
|
config.screenLayout);
|
||||||
|
}
|
||||||
|
|
||||||
if (filterable && !filter.match(config)) {
|
if (filterable && !filter.match(config)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -2985,28 +3015,30 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
|||||||
tHeader->entryCount = htodl(N);
|
tHeader->entryCount = htodl(N);
|
||||||
tHeader->entriesStart = htodl(typeSize);
|
tHeader->entriesStart = htodl(typeSize);
|
||||||
tHeader->config = config;
|
tHeader->config = config;
|
||||||
NOISY(printf("Writing type %d config: imsi:%d/%d lang:%c%c cnt:%c%c "
|
if (kIsDebug) {
|
||||||
"orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
|
printf("Writing type %zu config: imsi:%d/%d lang:%c%c cnt:%c%c "
|
||||||
"sw%ddp w%ddp h%ddp dir:%d\n",
|
"orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
|
||||||
ti+1,
|
"sw%ddp w%ddp h%ddp layout:%d\n",
|
||||||
tHeader->config.mcc, tHeader->config.mnc,
|
ti + 1,
|
||||||
tHeader->config.language[0] ? tHeader->config.language[0] : '-',
|
tHeader->config.mcc, tHeader->config.mnc,
|
||||||
tHeader->config.language[1] ? tHeader->config.language[1] : '-',
|
tHeader->config.language[0] ? tHeader->config.language[0] : '-',
|
||||||
tHeader->config.country[0] ? tHeader->config.country[0] : '-',
|
tHeader->config.language[1] ? tHeader->config.language[1] : '-',
|
||||||
tHeader->config.country[1] ? tHeader->config.country[1] : '-',
|
tHeader->config.country[0] ? tHeader->config.country[0] : '-',
|
||||||
tHeader->config.orientation,
|
tHeader->config.country[1] ? tHeader->config.country[1] : '-',
|
||||||
tHeader->config.uiMode,
|
tHeader->config.orientation,
|
||||||
tHeader->config.touchscreen,
|
tHeader->config.uiMode,
|
||||||
tHeader->config.density,
|
tHeader->config.touchscreen,
|
||||||
tHeader->config.keyboard,
|
tHeader->config.density,
|
||||||
tHeader->config.inputFlags,
|
tHeader->config.keyboard,
|
||||||
tHeader->config.navigation,
|
tHeader->config.inputFlags,
|
||||||
tHeader->config.screenWidth,
|
tHeader->config.navigation,
|
||||||
tHeader->config.screenHeight,
|
tHeader->config.screenWidth,
|
||||||
tHeader->config.smallestScreenWidthDp,
|
tHeader->config.screenHeight,
|
||||||
tHeader->config.screenWidthDp,
|
tHeader->config.smallestScreenWidthDp,
|
||||||
tHeader->config.screenHeightDp,
|
tHeader->config.screenWidthDp,
|
||||||
tHeader->config.layoutDirection));
|
tHeader->config.screenHeightDp,
|
||||||
|
tHeader->config.screenLayout);
|
||||||
|
}
|
||||||
tHeader->config.swapHtoD();
|
tHeader->config.swapHtoD();
|
||||||
|
|
||||||
// Build the entries inside of this type.
|
// Build the entries inside of this type.
|
||||||
@@ -3083,10 +3115,10 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
|||||||
|
|
||||||
ssize_t amt = (dest->getSize()-strStart);
|
ssize_t amt = (dest->getSize()-strStart);
|
||||||
strAmt += amt;
|
strAmt += amt;
|
||||||
#if PRINT_STRING_METRICS
|
if (kPrintStringMetrics) {
|
||||||
fprintf(stderr, "**** value strings: %d\n", amt);
|
fprintf(stderr, "**** value strings: %zd\n", SSIZE(amt));
|
||||||
fprintf(stderr, "**** total strings: %d\n", strAmt);
|
fprintf(stderr, "**** total strings: %zd\n", SSIZE(strAmt));
|
||||||
#endif
|
}
|
||||||
|
|
||||||
for (pi=0; pi<flatPackages.size(); pi++) {
|
for (pi=0; pi<flatPackages.size(); pi++) {
|
||||||
err = dest->writeData(flatPackages[pi]->getData(),
|
err = dest->writeData(flatPackages[pi]->getData(),
|
||||||
@@ -3101,13 +3133,10 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
|||||||
(((uint8_t*)dest->getData()) + dataStart);
|
(((uint8_t*)dest->getData()) + dataStart);
|
||||||
header->header.size = htodl(dest->getSize() - dataStart);
|
header->header.size = htodl(dest->getSize() - dataStart);
|
||||||
|
|
||||||
NOISY(aout << "Resource table:"
|
if (kPrintStringMetrics) {
|
||||||
<< HexDump(dest->getData(), dest->getSize()) << endl);
|
fprintf(stderr, "**** total resource table size: %zu / %zu%% strings\n",
|
||||||
|
dest->getSize(), (size_t)(strAmt*100)/dest->getSize());
|
||||||
#if PRINT_STRING_METRICS
|
}
|
||||||
fprintf(stderr, "**** total resource table size: %d / %d%% strings\n",
|
|
||||||
dest->getSize(), (strAmt*100)/dest->getSize());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
@@ -3339,7 +3368,7 @@ status_t ResourceTable::Entry::generateAttributes(ResourceTable* table,
|
|||||||
}
|
}
|
||||||
|
|
||||||
status_t ResourceTable::Entry::assignResourceIds(ResourceTable* table,
|
status_t ResourceTable::Entry::assignResourceIds(ResourceTable* table,
|
||||||
const String16& package)
|
const String16& /* package */)
|
||||||
{
|
{
|
||||||
bool hasErrors = false;
|
bool hasErrors = false;
|
||||||
|
|
||||||
@@ -3372,7 +3401,7 @@ status_t ResourceTable::Entry::assignResourceIds(ResourceTable* table,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
|
return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t ResourceTable::Entry::prepareFlatten(StringPool* strings, ResourceTable* table,
|
status_t ResourceTable::Entry::prepareFlatten(StringPool* strings, ResourceTable* table,
|
||||||
@@ -3431,22 +3460,20 @@ status_t ResourceTable::Entry::remapStringValue(StringPool* strings)
|
|||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ResourceTable::Entry::flatten(Bundle* bundle, const sp<AaptFile>& data, bool isPublic)
|
ssize_t ResourceTable::Entry::flatten(Bundle* /* bundle */, const sp<AaptFile>& data, bool isPublic)
|
||||||
{
|
{
|
||||||
size_t amt = 0;
|
size_t amt = 0;
|
||||||
ResTable_entry header;
|
ResTable_entry header;
|
||||||
memset(&header, 0, sizeof(header));
|
memset(&header, 0, sizeof(header));
|
||||||
header.size = htods(sizeof(header));
|
header.size = htods(sizeof(header));
|
||||||
const type ty = this != NULL ? mType : TYPE_ITEM;
|
const type ty = mType;
|
||||||
if (this != NULL) {
|
if (ty == TYPE_BAG) {
|
||||||
if (ty == TYPE_BAG) {
|
header.flags |= htods(header.FLAG_COMPLEX);
|
||||||
header.flags |= htods(header.FLAG_COMPLEX);
|
|
||||||
}
|
|
||||||
if (isPublic) {
|
|
||||||
header.flags |= htods(header.FLAG_PUBLIC);
|
|
||||||
}
|
|
||||||
header.key.index = htodl(mNameIndex);
|
|
||||||
}
|
}
|
||||||
|
if (isPublic) {
|
||||||
|
header.flags |= htods(header.FLAG_PUBLIC);
|
||||||
|
}
|
||||||
|
header.key.index = htodl(mNameIndex);
|
||||||
if (ty != TYPE_BAG) {
|
if (ty != TYPE_BAG) {
|
||||||
status_t err = data->writeData(&header, sizeof(header));
|
status_t err = data->writeData(&header, sizeof(header));
|
||||||
if (err != NO_ERROR) {
|
if (err != NO_ERROR) {
|
||||||
@@ -3621,10 +3648,11 @@ sp<ResourceTable::Entry> ResourceTable::Type::getEntry(const String16& entry,
|
|||||||
|
|
||||||
sp<Entry> e = c->getEntries().valueFor(cdesc);
|
sp<Entry> e = c->getEntries().valueFor(cdesc);
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
if (config != NULL) {
|
if (kIsDebug) {
|
||||||
NOISY(printf("New entry at %s:%d: imsi:%d/%d lang:%c%c cnt:%c%c "
|
if (config != NULL) {
|
||||||
|
printf("New entry at %s:%d: imsi:%d/%d lang:%c%c cnt:%c%c "
|
||||||
"orien:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
|
"orien:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
|
||||||
"sw%ddp w%ddp h%ddp dir:%d\n",
|
"sw%ddp w%ddp h%ddp layout:%d\n",
|
||||||
sourcePos.file.string(), sourcePos.line,
|
sourcePos.file.string(), sourcePos.line,
|
||||||
config->mcc, config->mnc,
|
config->mcc, config->mnc,
|
||||||
config->language[0] ? config->language[0] : '-',
|
config->language[0] ? config->language[0] : '-',
|
||||||
@@ -3642,10 +3670,11 @@ sp<ResourceTable::Entry> ResourceTable::Type::getEntry(const String16& entry,
|
|||||||
config->smallestScreenWidthDp,
|
config->smallestScreenWidthDp,
|
||||||
config->screenWidthDp,
|
config->screenWidthDp,
|
||||||
config->screenHeightDp,
|
config->screenHeightDp,
|
||||||
config->layoutDirection));
|
config->screenLayout);
|
||||||
} else {
|
} else {
|
||||||
NOISY(printf("New entry at %s:%d: NULL config\n",
|
printf("New entry at %s:%d: NULL config\n",
|
||||||
sourcePos.file.string(), sourcePos.line));
|
sourcePos.file.string(), sourcePos.line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
e = new Entry(entry, sourcePos);
|
e = new Entry(entry, sourcePos);
|
||||||
c->addEntry(cdesc, e);
|
c->addEntry(cdesc, e);
|
||||||
@@ -3751,7 +3780,7 @@ status_t ResourceTable::Type::applyPublicEntryOrder()
|
|||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasError ? UNKNOWN_ERROR : NO_ERROR;
|
return hasError ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceTable::Package::Package(const String16& name, ssize_t includedId)
|
ResourceTable::Package::Package(const String16& name, ssize_t includedId)
|
||||||
@@ -3807,9 +3836,6 @@ status_t ResourceTable::Package::setStrings(const sp<AaptFile>& data,
|
|||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(aout << "Setting restable string pool: "
|
|
||||||
<< HexDump(data->getData(), data->getSize()) << endl);
|
|
||||||
|
|
||||||
status_t err = strings->setTo(data->getData(), data->getSize());
|
status_t err = strings->setTo(data->getData(), data->getSize());
|
||||||
if (err == NO_ERROR) {
|
if (err == NO_ERROR) {
|
||||||
const size_t N = strings->size();
|
const size_t N = strings->size();
|
||||||
@@ -4017,7 +4043,7 @@ bool ResourceTable::getItemValue(
|
|||||||
}
|
}
|
||||||
item->evaluating = true;
|
item->evaluating = true;
|
||||||
res = stringToValue(outValue, NULL, item->value, false, false, item->bagKeyId);
|
res = stringToValue(outValue, NULL, item->value, false, false, item->bagKeyId);
|
||||||
NOISY(
|
if (kIsDebug) {
|
||||||
if (res) {
|
if (res) {
|
||||||
printf("getItemValue of #%08x[#%08x] (%s): type=#%08x, data=#%08x\n",
|
printf("getItemValue of #%08x[#%08x] (%s): type=#%08x, data=#%08x\n",
|
||||||
resID, attrID, String8(getEntry(resID)->getName()).string(),
|
resID, attrID, String8(getEntry(resID)->getName()).string(),
|
||||||
@@ -4026,7 +4052,7 @@ bool ResourceTable::getItemValue(
|
|||||||
printf("getItemValue of #%08x[#%08x]: failed\n",
|
printf("getItemValue of #%08x[#%08x]: failed\n",
|
||||||
resID, attrID);
|
resID, attrID);
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
item->evaluating = false;
|
item->evaluating = false;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
//
|
//
|
||||||
// Build resource files from raw assets.
|
// Build resource files from raw assets.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "StringPool.h"
|
#include "StringPool.h"
|
||||||
|
|
||||||
#include <utils/ByteOrder.h>
|
#include <utils/ByteOrder.h>
|
||||||
@@ -13,15 +12,19 @@
|
|||||||
|
|
||||||
#include "ResourceTable.h"
|
#include "ResourceTable.h"
|
||||||
|
|
||||||
|
// SSIZE: mingw does not have signed size_t == ssize_t.
|
||||||
#if HAVE_PRINTF_ZD
|
#if HAVE_PRINTF_ZD
|
||||||
# define ZD "%zd"
|
# define ZD "%zd"
|
||||||
# define ZD_TYPE ssize_t
|
# define ZD_TYPE ssize_t
|
||||||
|
# define SSIZE(x) x
|
||||||
#else
|
#else
|
||||||
# define ZD "%ld"
|
# define ZD "%ld"
|
||||||
# define ZD_TYPE long
|
# define ZD_TYPE long
|
||||||
|
# define SSIZE(x) (signed size_t)x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NOISY(x) //x
|
// Set to true for noisy debug output.
|
||||||
|
static const bool kIsDebug = false;
|
||||||
|
|
||||||
void strcpy16_htod(char16_t* dst, const char16_t* src)
|
void strcpy16_htod(char16_t* dst, const char16_t* src)
|
||||||
{
|
{
|
||||||
@@ -134,8 +137,10 @@ ssize_t StringPool::add(const String16& value,
|
|||||||
|
|
||||||
if (configTypeName != NULL) {
|
if (configTypeName != NULL) {
|
||||||
entry& ent = mEntries.editItemAt(eidx);
|
entry& ent = mEntries.editItemAt(eidx);
|
||||||
NOISY(printf("*** adding config type name %s, was %s\n",
|
if (kIsDebug) {
|
||||||
configTypeName->string(), ent.configTypeName.string()));
|
printf("*** adding config type name %s, was %s\n",
|
||||||
|
configTypeName->string(), ent.configTypeName.string());
|
||||||
|
}
|
||||||
if (ent.configTypeName.size() <= 0) {
|
if (ent.configTypeName.size() <= 0) {
|
||||||
ent.configTypeName = *configTypeName;
|
ent.configTypeName = *configTypeName;
|
||||||
} else if (ent.configTypeName != *configTypeName) {
|
} else if (ent.configTypeName != *configTypeName) {
|
||||||
@@ -151,14 +156,18 @@ ssize_t StringPool::add(const String16& value,
|
|||||||
int cmp = ent.configs.itemAt(addPos).compareLogical(*config);
|
int cmp = ent.configs.itemAt(addPos).compareLogical(*config);
|
||||||
if (cmp >= 0) {
|
if (cmp >= 0) {
|
||||||
if (cmp > 0) {
|
if (cmp > 0) {
|
||||||
NOISY(printf("*** inserting config: %s\n", config->toString().string()));
|
if (kIsDebug) {
|
||||||
|
printf("*** inserting config: %s\n", config->toString().string());
|
||||||
|
}
|
||||||
ent.configs.insertAt(*config, addPos);
|
ent.configs.insertAt(*config, addPos);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (addPos >= ent.configs.size()) {
|
if (addPos >= ent.configs.size()) {
|
||||||
NOISY(printf("*** adding config: %s\n", config->toString().string()));
|
if (kIsDebug) {
|
||||||
|
printf("*** adding config: %s\n", config->toString().string());
|
||||||
|
}
|
||||||
ent.configs.add(*config);
|
ent.configs.add(*config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,9 +184,11 @@ ssize_t StringPool::add(const String16& value,
|
|||||||
ent.indices.add(pos);
|
ent.indices.add(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("Adding string %s to pool: pos=%d eidx=%d vidx=%d\n",
|
if (kIsDebug) {
|
||||||
String8(value).string(), pos, eidx, vidx));
|
printf("Adding string %s to pool: pos=%zd eidx=%zd vidx=%zd\n",
|
||||||
|
String8(value).string(), SSIZE(pos), SSIZE(eidx), SSIZE(vidx));
|
||||||
|
}
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,10 +255,14 @@ void StringPool::sortByConfig()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort the array.
|
// Sort the array.
|
||||||
NOISY(printf("SORTING STRINGS BY CONFIGURATION...\n"));
|
if (kIsDebug) {
|
||||||
|
printf("SORTING STRINGS BY CONFIGURATION...\n");
|
||||||
|
}
|
||||||
ConfigSorter sorter(*this);
|
ConfigSorter sorter(*this);
|
||||||
std::sort(newPosToOriginalPos.begin(), newPosToOriginalPos.end(), sorter);
|
std::sort(newPosToOriginalPos.begin(), newPosToOriginalPos.end(), sorter);
|
||||||
NOISY(printf("DONE SORTING STRINGS BY CONFIGURATION.\n"));
|
if (kIsDebug) {
|
||||||
|
printf("DONE SORTING STRINGS BY CONFIGURATION.\n");
|
||||||
|
}
|
||||||
|
|
||||||
// Create the reverse mapping from the original position in the array
|
// Create the reverse mapping from the original position in the array
|
||||||
// to the new position where it appears in the sorted array. This is
|
// to the new position where it appears in the sorted array. This is
|
||||||
@@ -544,9 +559,13 @@ status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
|
|||||||
for (i=0; i<ENTRIES; i++) {
|
for (i=0; i<ENTRIES; i++) {
|
||||||
entry& ent = mEntries.editItemAt(mEntryArray[i]);
|
entry& ent = mEntries.editItemAt(mEntryArray[i]);
|
||||||
*index++ = htodl(ent.offset);
|
*index++ = htodl(ent.offset);
|
||||||
NOISY(printf("Writing entry #%d: \"%s\" ent=%d off=%d\n", i,
|
if (kIsDebug) {
|
||||||
String8(ent.value).string(),
|
printf("Writing entry #%zu: \"%s\" ent=%zu off=%zu\n",
|
||||||
mEntryArray[i], ent.offset));
|
i,
|
||||||
|
String8(ent.value).string(),
|
||||||
|
mEntryArray[i],
|
||||||
|
ent.offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write style index array.
|
// Write style index array.
|
||||||
@@ -562,8 +581,10 @@ ssize_t StringPool::offsetForString(const String16& val) const
|
|||||||
{
|
{
|
||||||
const Vector<size_t>* indices = offsetsForString(val);
|
const Vector<size_t>* indices = offsetsForString(val);
|
||||||
ssize_t res = indices != NULL && indices->size() > 0 ? indices->itemAt(0) : -1;
|
ssize_t res = indices != NULL && indices->size() > 0 ? indices->itemAt(0) : -1;
|
||||||
NOISY(printf("Offset for string %s: %d (%s)\n", String8(val).string(), res,
|
if (kIsDebug) {
|
||||||
res >= 0 ? String8(mEntries[mEntryArray[res]].value).string() : String8()));
|
printf("Offset for string %s: %zd (%s)\n", String8(val).string(), SSIZE(res),
|
||||||
|
res >= 0 ? String8(mEntries[mEntryArray[res]].value).string() : String8());
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,26 @@
|
|||||||
#define O_BINARY 0
|
#define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NOISY(x) //x
|
// SSIZE: mingw does not have signed size_t == ssize_t.
|
||||||
#define NOISY_PARSE(x) //x
|
// STATUST: mingw does seem to redefine UNKNOWN_ERROR from our enum value, so a cast is necessary.
|
||||||
|
#if HAVE_PRINTF_ZD
|
||||||
|
# define SSIZE(x) x
|
||||||
|
# define STATUST(x) x
|
||||||
|
#else
|
||||||
|
# define SSIZE(x) (signed size_t)x
|
||||||
|
# define STATUST(x) (status_t)x
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Set to true for noisy debug output.
|
||||||
|
static const bool kIsDebug = false;
|
||||||
|
// Set to true for noisy debug output of parsing.
|
||||||
|
static const bool kIsDebugParse = false;
|
||||||
|
|
||||||
|
#if PRINT_STRING_METRICS
|
||||||
|
static const bool kPrintStringMetrics = true;
|
||||||
|
#else
|
||||||
|
static const bool kPrintStringMetrics = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
const char* const RESOURCES_ROOT_NAMESPACE = "http://schemas.android.com/apk/res/";
|
const char* const RESOURCES_ROOT_NAMESPACE = "http://schemas.android.com/apk/res/";
|
||||||
const char* const RESOURCES_ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android";
|
const char* const RESOURCES_ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android";
|
||||||
@@ -56,7 +74,10 @@ String16 getNamespaceResourcePackage(String16 appPackage, String16 namespaceUri,
|
|||||||
size_t prefixSize;
|
size_t prefixSize;
|
||||||
bool isPublic = true;
|
bool isPublic = true;
|
||||||
if(namespaceUri.startsWith(RESOURCES_PREFIX_AUTO_PACKAGE)) {
|
if(namespaceUri.startsWith(RESOURCES_PREFIX_AUTO_PACKAGE)) {
|
||||||
NOISY(printf("Using default application package: %s -> %s\n", String8(namespaceUri).string(), String8(appPackage).string()));
|
if (kIsDebug) {
|
||||||
|
printf("Using default application package: %s -> %s\n", String8(namespaceUri).string(),
|
||||||
|
String8(appPackage).string());
|
||||||
|
}
|
||||||
isPublic = true;
|
isPublic = true;
|
||||||
return appPackage;
|
return appPackage;
|
||||||
} else if (namespaceUri.startsWith(RESOURCES_PREFIX)) {
|
} else if (namespaceUri.startsWith(RESOURCES_PREFIX)) {
|
||||||
@@ -180,7 +201,7 @@ status_t hasSubstitutionErrors(const char* fileName,
|
|||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t parseStyledString(Bundle* bundle,
|
status_t parseStyledString(Bundle* /* bundle */,
|
||||||
const char* fileName,
|
const char* fileName,
|
||||||
ResXMLTree* inXml,
|
ResXMLTree* inXml,
|
||||||
const String16& endTag,
|
const String16& endTag,
|
||||||
@@ -557,8 +578,10 @@ status_t parseXMLResource(const sp<AaptFile>& file, ResXMLTree* outTree,
|
|||||||
}
|
}
|
||||||
root->removeWhitespace(stripAll, cDataTags);
|
root->removeWhitespace(stripAll, cDataTags);
|
||||||
|
|
||||||
NOISY(printf("Input XML from %s:\n", (const char*)file->getPrintableSource()));
|
if (kIsDebug) {
|
||||||
NOISY(root->print());
|
printf("Input XML from %s:\n", (const char*)file->getPrintableSource());
|
||||||
|
root->print();
|
||||||
|
}
|
||||||
sp<AaptFile> rsc = new AaptFile(String8(), AaptGroupEntry(), String8());
|
sp<AaptFile> rsc = new AaptFile(String8(), AaptGroupEntry(), String8());
|
||||||
status_t err = root->flatten(rsc, !keepComments, false);
|
status_t err = root->flatten(rsc, !keepComments, false);
|
||||||
if (err != NO_ERROR) {
|
if (err != NO_ERROR) {
|
||||||
@@ -569,8 +592,10 @@ status_t parseXMLResource(const sp<AaptFile>& file, ResXMLTree* outTree,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOISY(printf("Output XML:\n"));
|
if (kIsDebug) {
|
||||||
NOISY(printXMLBlock(outTree));
|
printf("Output XML:\n");
|
||||||
|
printXMLBlock(outTree);
|
||||||
|
}
|
||||||
|
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
@@ -818,11 +843,13 @@ void XMLNode::setAttributeResID(size_t attrIdx, uint32_t resId)
|
|||||||
} else {
|
} else {
|
||||||
mAttributeOrder.removeItem(e.index);
|
mAttributeOrder.removeItem(e.index);
|
||||||
}
|
}
|
||||||
NOISY(printf("Elem %s %s=\"%s\": set res id = 0x%08x\n",
|
if (kIsDebug) {
|
||||||
String8(getElementName()).string(),
|
printf("Elem %s %s=\"%s\": set res id = 0x%08x\n",
|
||||||
String8(mAttributes.itemAt(attrIdx).name).string(),
|
String8(getElementName()).string(),
|
||||||
String8(mAttributes.itemAt(attrIdx).string).string(),
|
String8(mAttributes.itemAt(attrIdx).name).string(),
|
||||||
resId));
|
String8(mAttributes.itemAt(attrIdx).string).string(),
|
||||||
|
resId);
|
||||||
|
}
|
||||||
mAttributes.editItemAt(attrIdx).nameResId = resId;
|
mAttributes.editItemAt(attrIdx).nameResId = resId;
|
||||||
mAttributeOrder.add(resId, attrIdx);
|
mAttributeOrder.add(resId, attrIdx);
|
||||||
}
|
}
|
||||||
@@ -933,9 +960,11 @@ status_t XMLNode::parseValues(const sp<AaptAssets>& assets,
|
|||||||
e.nameResId, NULL, &defPackage, table, &ac)) {
|
e.nameResId, NULL, &defPackage, table, &ac)) {
|
||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
}
|
}
|
||||||
NOISY(printf("Attr %s: type=0x%x, str=%s\n",
|
if (kIsDebug) {
|
||||||
String8(e.name).string(), e.value.dataType,
|
printf("Attr %s: type=0x%x, str=%s\n",
|
||||||
String8(e.string).string()));
|
String8(e.name).string(), e.value.dataType,
|
||||||
|
String8(e.string).string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const size_t N = mChildren.size();
|
const size_t N = mChildren.size();
|
||||||
@@ -945,7 +974,7 @@ status_t XMLNode::parseValues(const sp<AaptAssets>& assets,
|
|||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
|
return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
|
status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
|
||||||
@@ -962,13 +991,15 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
|
|||||||
if (e.ns.size() <= 0) continue;
|
if (e.ns.size() <= 0) continue;
|
||||||
bool nsIsPublic;
|
bool nsIsPublic;
|
||||||
String16 pkg(getNamespaceResourcePackage(String16(assets->getPackage()), e.ns, &nsIsPublic));
|
String16 pkg(getNamespaceResourcePackage(String16(assets->getPackage()), e.ns, &nsIsPublic));
|
||||||
NOISY(printf("Elem %s %s=\"%s\": namespace(%s) %s ===> %s\n",
|
if (kIsDebug) {
|
||||||
String8(getElementName()).string(),
|
printf("Elem %s %s=\"%s\": namespace(%s) %s ===> %s\n",
|
||||||
String8(e.name).string(),
|
String8(getElementName()).string(),
|
||||||
String8(e.string).string(),
|
String8(e.name).string(),
|
||||||
String8(e.ns).string(),
|
String8(e.string).string(),
|
||||||
(nsIsPublic) ? "public" : "private",
|
String8(e.ns).string(),
|
||||||
String8(pkg).string()));
|
(nsIsPublic) ? "public" : "private",
|
||||||
|
String8(pkg).string());
|
||||||
|
}
|
||||||
if (pkg.size() <= 0) continue;
|
if (pkg.size() <= 0) continue;
|
||||||
uint32_t res = table != NULL
|
uint32_t res = table != NULL
|
||||||
? table->getResId(e.name, &attr, &pkg, &errorMsg, nsIsPublic)
|
? table->getResId(e.name, &attr, &pkg, &errorMsg, nsIsPublic)
|
||||||
@@ -977,8 +1008,10 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
|
|||||||
attr.string(), attr.size(),
|
attr.string(), attr.size(),
|
||||||
pkg.string(), pkg.size());
|
pkg.string(), pkg.size());
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
NOISY(printf("XML attribute name %s: resid=0x%08x\n",
|
if (kIsDebug) {
|
||||||
String8(e.name).string(), res));
|
printf("XML attribute name %s: resid=0x%08x\n",
|
||||||
|
String8(e.name).string(), res);
|
||||||
|
}
|
||||||
setAttributeResID(i, res);
|
setAttributeResID(i, res);
|
||||||
} else {
|
} else {
|
||||||
SourcePos(mFilename, getStartLineNumber()).error(
|
SourcePos(mFilename, getStartLineNumber()).error(
|
||||||
@@ -996,7 +1029,7 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
|
return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t XMLNode::flatten(const sp<AaptFile>& dest,
|
status_t XMLNode::flatten(const sp<AaptFile>& dest,
|
||||||
@@ -1014,18 +1047,7 @@ status_t XMLNode::flatten(const sp<AaptFile>& dest,
|
|||||||
// Next collect all remainibng strings.
|
// Next collect all remainibng strings.
|
||||||
collect_strings(&strings, &resids, stripComments, stripRawValues);
|
collect_strings(&strings, &resids, stripComments, stripRawValues);
|
||||||
|
|
||||||
#if 0 // No longer compiles
|
|
||||||
NOISY(printf("Found strings:\n");
|
|
||||||
const size_t N = strings.size();
|
|
||||||
for (size_t i=0; i<N; i++) {
|
|
||||||
printf("%s\n", String8(strings.entryAt(i).string).string());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sp<AaptFile> stringPool = strings.createStringBlock();
|
sp<AaptFile> stringPool = strings.createStringBlock();
|
||||||
NOISY(aout << "String pool:"
|
|
||||||
<< HexDump(stringPool->getData(), stringPool->getSize()) << endl);
|
|
||||||
|
|
||||||
ResXMLTree_header header;
|
ResXMLTree_header header;
|
||||||
memset(&header, 0, sizeof(header));
|
memset(&header, 0, sizeof(header));
|
||||||
@@ -1056,17 +1078,13 @@ status_t XMLNode::flatten(const sp<AaptFile>& dest,
|
|||||||
|
|
||||||
void* data = dest->editData();
|
void* data = dest->editData();
|
||||||
ResXMLTree_header* hd = (ResXMLTree_header*)(((uint8_t*)data)+basePos);
|
ResXMLTree_header* hd = (ResXMLTree_header*)(((uint8_t*)data)+basePos);
|
||||||
size_t size = dest->getSize()-basePos;
|
|
||||||
hd->header.size = htodl(dest->getSize()-basePos);
|
hd->header.size = htodl(dest->getSize()-basePos);
|
||||||
|
|
||||||
NOISY(aout << "XML resource:"
|
if (kPrintStringMetrics) {
|
||||||
<< HexDump(dest->getData(), dest->getSize()) << endl);
|
fprintf(stderr, "**** total xml size: %zu / %zu%% strings (in %s)\n",
|
||||||
|
dest->getSize(), (stringPool->getSize()*100)/dest->getSize(),
|
||||||
#if PRINT_STRING_METRICS
|
dest->getPath().string());
|
||||||
fprintf(stderr, "**** total xml size: %d / %d%% strings (in %s)\n",
|
}
|
||||||
dest->getSize(), (stringPool->getSize()*100)/dest->getSize(),
|
|
||||||
dest->getPath().string());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
@@ -1139,7 +1157,9 @@ static void splitName(const char* name, String16* outNs, String16* outName)
|
|||||||
void XMLCALL
|
void XMLCALL
|
||||||
XMLNode::startNamespace(void *userData, const char *prefix, const char *uri)
|
XMLNode::startNamespace(void *userData, const char *prefix, const char *uri)
|
||||||
{
|
{
|
||||||
NOISY_PARSE(printf("Start Namespace: %s %s\n", prefix, uri));
|
if (kIsDebugParse) {
|
||||||
|
printf("Start Namespace: %s %s\n", prefix, uri);
|
||||||
|
}
|
||||||
ParseState* st = (ParseState*)userData;
|
ParseState* st = (ParseState*)userData;
|
||||||
sp<XMLNode> node = XMLNode::newNamespace(st->filename,
|
sp<XMLNode> node = XMLNode::newNamespace(st->filename,
|
||||||
String16(prefix != NULL ? prefix : ""), String16(uri));
|
String16(prefix != NULL ? prefix : ""), String16(uri));
|
||||||
@@ -1155,7 +1175,9 @@ XMLNode::startNamespace(void *userData, const char *prefix, const char *uri)
|
|||||||
void XMLCALL
|
void XMLCALL
|
||||||
XMLNode::startElement(void *userData, const char *name, const char **atts)
|
XMLNode::startElement(void *userData, const char *name, const char **atts)
|
||||||
{
|
{
|
||||||
NOISY_PARSE(printf("Start Element: %s\n", name));
|
if (kIsDebugParse) {
|
||||||
|
printf("Start Element: %s\n", name);
|
||||||
|
}
|
||||||
ParseState* st = (ParseState*)userData;
|
ParseState* st = (ParseState*)userData;
|
||||||
String16 ns16, name16;
|
String16 ns16, name16;
|
||||||
splitName(name, &ns16, &name16);
|
splitName(name, &ns16, &name16);
|
||||||
@@ -1181,7 +1203,9 @@ XMLNode::startElement(void *userData, const char *name, const char **atts)
|
|||||||
void XMLCALL
|
void XMLCALL
|
||||||
XMLNode::characterData(void *userData, const XML_Char *s, int len)
|
XMLNode::characterData(void *userData, const XML_Char *s, int len)
|
||||||
{
|
{
|
||||||
NOISY_PARSE(printf("CDATA: \"%s\"\n", String8(s, len).string()));
|
if (kIsDebugParse) {
|
||||||
|
printf("CDATA: \"%s\"\n", String8(s, len).string());
|
||||||
|
}
|
||||||
ParseState* st = (ParseState*)userData;
|
ParseState* st = (ParseState*)userData;
|
||||||
sp<XMLNode> node = NULL;
|
sp<XMLNode> node = NULL;
|
||||||
if (st->stack.size() == 0) {
|
if (st->stack.size() == 0) {
|
||||||
@@ -1208,7 +1232,9 @@ XMLNode::characterData(void *userData, const XML_Char *s, int len)
|
|||||||
void XMLCALL
|
void XMLCALL
|
||||||
XMLNode::endElement(void *userData, const char *name)
|
XMLNode::endElement(void *userData, const char *name)
|
||||||
{
|
{
|
||||||
NOISY_PARSE(printf("End Element: %s\n", name));
|
if (kIsDebugParse) {
|
||||||
|
printf("End Element: %s\n", name);
|
||||||
|
}
|
||||||
ParseState* st = (ParseState*)userData;
|
ParseState* st = (ParseState*)userData;
|
||||||
sp<XMLNode> node = st->stack.itemAt(st->stack.size()-1);
|
sp<XMLNode> node = st->stack.itemAt(st->stack.size()-1);
|
||||||
node->setEndLineNumber(XML_GetCurrentLineNumber(st->parser));
|
node->setEndLineNumber(XML_GetCurrentLineNumber(st->parser));
|
||||||
@@ -1228,7 +1254,9 @@ void XMLCALL
|
|||||||
XMLNode::endNamespace(void *userData, const char *prefix)
|
XMLNode::endNamespace(void *userData, const char *prefix)
|
||||||
{
|
{
|
||||||
const char* nonNullPrefix = prefix != NULL ? prefix : "";
|
const char* nonNullPrefix = prefix != NULL ? prefix : "";
|
||||||
NOISY_PARSE(printf("End Namespace: %s\n", prefix));
|
if (kIsDebugParse) {
|
||||||
|
printf("End Namespace: %s\n", prefix);
|
||||||
|
}
|
||||||
ParseState* st = (ParseState*)userData;
|
ParseState* st = (ParseState*)userData;
|
||||||
sp<XMLNode> node = st->stack.itemAt(st->stack.size()-1);
|
sp<XMLNode> node = st->stack.itemAt(st->stack.size()-1);
|
||||||
node->setEndLineNumber(XML_GetCurrentLineNumber(st->parser));
|
node->setEndLineNumber(XML_GetCurrentLineNumber(st->parser));
|
||||||
@@ -1240,7 +1268,9 @@ XMLNode::endNamespace(void *userData, const char *prefix)
|
|||||||
void XMLCALL
|
void XMLCALL
|
||||||
XMLNode::commentData(void *userData, const char *comment)
|
XMLNode::commentData(void *userData, const char *comment)
|
||||||
{
|
{
|
||||||
NOISY_PARSE(printf("Comment: %s\n", comment));
|
if (kIsDebugParse) {
|
||||||
|
printf("Comment: %s\n", comment);
|
||||||
|
}
|
||||||
ParseState* st = (ParseState*)userData;
|
ParseState* st = (ParseState*)userData;
|
||||||
if (st->pendingComment.size() > 0) {
|
if (st->pendingComment.size() > 0) {
|
||||||
st->pendingComment.append(String16("\n"));
|
st->pendingComment.append(String16("\n"));
|
||||||
@@ -1337,8 +1367,10 @@ status_t XMLNode::collect_attr_strings(StringPool* outPool,
|
|||||||
}
|
}
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
idx = outPool->add(attr.name);
|
idx = outPool->add(attr.name);
|
||||||
NOISY(printf("Adding attr %s (resid 0x%08x) to pool: idx=%d\n",
|
if (kIsDebug) {
|
||||||
String8(attr.name).string(), id, idx));
|
printf("Adding attr %s (resid 0x%08x) to pool: idx=%zd\n",
|
||||||
|
String8(attr.name).string(), id, SSIZE(idx));
|
||||||
|
}
|
||||||
if (id != 0) {
|
if (id != 0) {
|
||||||
while ((ssize_t)outResIds->size() <= idx) {
|
while ((ssize_t)outResIds->size() <= idx) {
|
||||||
outResIds->add(0);
|
outResIds->add(0);
|
||||||
@@ -1347,8 +1379,9 @@ status_t XMLNode::collect_attr_strings(StringPool* outPool,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
attr.namePoolIdx = idx;
|
attr.namePoolIdx = idx;
|
||||||
NOISY(printf("String %s offset=0x%08x\n",
|
if (kIsDebug) {
|
||||||
String8(attr.name).string(), idx));
|
printf("String %s offset=0x%08zd\n", String8(attr.name).string(), SSIZE(idx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,33 +141,15 @@ void ZipEntry::initNew(const char* fileName, const char* comment)
|
|||||||
*
|
*
|
||||||
* Initializes the CDE and the LFH.
|
* Initializes the CDE and the LFH.
|
||||||
*/
|
*/
|
||||||
status_t ZipEntry::initFromExternal(const ZipFile* pZipFile,
|
status_t ZipEntry::initFromExternal(const ZipFile* /* pZipFile */,
|
||||||
const ZipEntry* pEntry)
|
const ZipEntry* pEntry)
|
||||||
{
|
{
|
||||||
/*
|
mCDE = pEntry->mCDE;
|
||||||
* Copy everything in the CDE over, then fix up the hairy bits.
|
// Check whether we got all the memory needed.
|
||||||
*/
|
if ((mCDE.mFileNameLength > 0 && mCDE.mFileName == NULL) ||
|
||||||
memcpy(&mCDE, &pEntry->mCDE, sizeof(mCDE));
|
(mCDE.mFileCommentLength > 0 && mCDE.mFileComment == NULL) ||
|
||||||
|
(mCDE.mExtraFieldLength > 0 && mCDE.mExtraField == NULL)) {
|
||||||
if (mCDE.mFileNameLength > 0) {
|
return NO_MEMORY;
|
||||||
mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
|
|
||||||
if (mCDE.mFileName == NULL)
|
|
||||||
return NO_MEMORY;
|
|
||||||
strcpy((char*) mCDE.mFileName, (char*)pEntry->mCDE.mFileName);
|
|
||||||
}
|
|
||||||
if (mCDE.mFileCommentLength > 0) {
|
|
||||||
mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
|
|
||||||
if (mCDE.mFileComment == NULL)
|
|
||||||
return NO_MEMORY;
|
|
||||||
strcpy((char*) mCDE.mFileComment, (char*)pEntry->mCDE.mFileComment);
|
|
||||||
}
|
|
||||||
if (mCDE.mExtraFieldLength > 0) {
|
|
||||||
/* we null-terminate this, though it may not be a string */
|
|
||||||
mCDE.mExtraField = new unsigned char[mCDE.mExtraFieldLength+1];
|
|
||||||
if (mCDE.mExtraField == NULL)
|
|
||||||
return NO_MEMORY;
|
|
||||||
memcpy(mCDE.mExtraField, pEntry->mCDE.mExtraField,
|
|
||||||
mCDE.mExtraFieldLength+1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* construct the LFH from the CDE */
|
/* construct the LFH from the CDE */
|
||||||
@@ -694,3 +676,60 @@ void ZipEntry::CentralDirEntry::dump(void) const
|
|||||||
ALOGD(" comment: '%s'\n", mFileComment);
|
ALOGD(" comment: '%s'\n", mFileComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy-assignment operator for CentralDirEntry.
|
||||||
|
*/
|
||||||
|
ZipEntry::CentralDirEntry& ZipEntry::CentralDirEntry::operator=(const ZipEntry::CentralDirEntry& src) {
|
||||||
|
if (this == &src) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free up old data.
|
||||||
|
delete[] mFileName;
|
||||||
|
delete[] mExtraField;
|
||||||
|
delete[] mFileComment;
|
||||||
|
|
||||||
|
// Copy scalars.
|
||||||
|
mVersionMadeBy = src.mVersionMadeBy;
|
||||||
|
mVersionToExtract = src.mVersionToExtract;
|
||||||
|
mGPBitFlag = src.mGPBitFlag;
|
||||||
|
mCompressionMethod = src.mCompressionMethod;
|
||||||
|
mLastModFileTime = src.mLastModFileTime;
|
||||||
|
mLastModFileDate = src.mLastModFileDate;
|
||||||
|
mCRC32 = src.mCRC32;
|
||||||
|
mCompressedSize = src.mCompressedSize;
|
||||||
|
mUncompressedSize = src.mUncompressedSize;
|
||||||
|
mFileNameLength = src.mFileNameLength;
|
||||||
|
mExtraFieldLength = src.mExtraFieldLength;
|
||||||
|
mFileCommentLength = src.mFileCommentLength;
|
||||||
|
mDiskNumberStart = src.mDiskNumberStart;
|
||||||
|
mInternalAttrs = src.mInternalAttrs;
|
||||||
|
mExternalAttrs = src.mExternalAttrs;
|
||||||
|
mLocalHeaderRelOffset = src.mLocalHeaderRelOffset;
|
||||||
|
|
||||||
|
// Copy strings, if necessary.
|
||||||
|
if (mFileNameLength > 0) {
|
||||||
|
mFileName = new unsigned char[mFileNameLength + 1];
|
||||||
|
if (mFileName != NULL)
|
||||||
|
strcpy((char*)mFileName, (char*)src.mFileName);
|
||||||
|
} else {
|
||||||
|
mFileName = NULL;
|
||||||
|
}
|
||||||
|
if (mFileCommentLength > 0) {
|
||||||
|
mFileComment = new unsigned char[mFileCommentLength + 1];
|
||||||
|
if (mFileComment != NULL)
|
||||||
|
strcpy((char*)mFileComment, (char*)src.mFileComment);
|
||||||
|
} else {
|
||||||
|
mFileComment = NULL;
|
||||||
|
}
|
||||||
|
if (mExtraFieldLength > 0) {
|
||||||
|
/* we null-terminate this, though it may not be a string */
|
||||||
|
mExtraField = new unsigned char[mExtraFieldLength + 1];
|
||||||
|
if (mExtraField != NULL)
|
||||||
|
memcpy(mExtraField, src.mExtraField, mExtraFieldLength + 1);
|
||||||
|
} else {
|
||||||
|
mExtraField = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|||||||
@@ -298,6 +298,8 @@ private:
|
|||||||
status_t read(FILE* fp);
|
status_t read(FILE* fp);
|
||||||
status_t write(FILE* fp);
|
status_t write(FILE* fp);
|
||||||
|
|
||||||
|
CentralDirEntry& operator=(const CentralDirEntry& src);
|
||||||
|
|
||||||
// unsigned long mSignature;
|
// unsigned long mSignature;
|
||||||
unsigned short mVersionMadeBy;
|
unsigned short mVersionMadeBy;
|
||||||
unsigned short mVersionToExtract;
|
unsigned short mVersionToExtract;
|
||||||
|
|||||||
@@ -676,8 +676,6 @@ status_t ZipFile::copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32)
|
|||||||
status_t ZipFile::copyDataToFp(FILE* dstFp,
|
status_t ZipFile::copyDataToFp(FILE* dstFp,
|
||||||
const void* data, size_t size, unsigned long* pCRC32)
|
const void* data, size_t size, unsigned long* pCRC32)
|
||||||
{
|
{
|
||||||
size_t count;
|
|
||||||
|
|
||||||
*pCRC32 = crc32(0L, Z_NULL, 0);
|
*pCRC32 = crc32(0L, Z_NULL, 0);
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
*pCRC32 = crc32(*pCRC32, (const unsigned char*)data, size);
|
*pCRC32 = crc32(*pCRC32, (const unsigned char*)data, size);
|
||||||
|
|||||||
Reference in New Issue
Block a user