Merge "Fix issues that will be present in C++11" into lmp-mr1-dev

This commit is contained in:
Adam Lesinski
2014-11-03 23:38:42 +00:00
committed by Android (Google) Code Review
14 changed files with 131 additions and 131 deletions

View File

@@ -36,6 +36,17 @@
namespace android { namespace android {
/**
* In C++11, char16_t is defined as *at least* 16 bits. We do a lot of
* casting on raw data and expect char16_t to be exactly 16 bits.
*/
#if __cplusplus >= 201103L
struct __assertChar16Size {
static_assert(sizeof(char16_t) == sizeof(uint16_t), "char16_t is not 16 bits");
static_assert(alignof(char16_t) == alignof(uint16_t), "char16_t is not 16-bit aligned");
};
#endif
/** ******************************************************************** /** ********************************************************************
* PNG Extensions * PNG Extensions
* *
@@ -702,25 +713,25 @@ public:
// These are available for all nodes: // These are available for all nodes:
int32_t getCommentID() const; int32_t getCommentID() const;
const uint16_t* getComment(size_t* outLen) const; const char16_t* getComment(size_t* outLen) const;
uint32_t getLineNumber() const; uint32_t getLineNumber() const;
// This is available for TEXT: // This is available for TEXT:
int32_t getTextID() const; int32_t getTextID() const;
const uint16_t* getText(size_t* outLen) const; const char16_t* getText(size_t* outLen) const;
ssize_t getTextValue(Res_value* outValue) const; ssize_t getTextValue(Res_value* outValue) const;
// These are available for START_NAMESPACE and END_NAMESPACE: // These are available for START_NAMESPACE and END_NAMESPACE:
int32_t getNamespacePrefixID() const; int32_t getNamespacePrefixID() const;
const uint16_t* getNamespacePrefix(size_t* outLen) const; const char16_t* getNamespacePrefix(size_t* outLen) const;
int32_t getNamespaceUriID() const; int32_t getNamespaceUriID() const;
const uint16_t* getNamespaceUri(size_t* outLen) const; const char16_t* getNamespaceUri(size_t* outLen) const;
// These are available for START_TAG and END_TAG: // These are available for START_TAG and END_TAG:
int32_t getElementNamespaceID() const; int32_t getElementNamespaceID() const;
const uint16_t* getElementNamespace(size_t* outLen) const; const char16_t* getElementNamespace(size_t* outLen) const;
int32_t getElementNameID() const; int32_t getElementNameID() const;
const uint16_t* getElementName(size_t* outLen) const; const char16_t* getElementName(size_t* outLen) const;
// Remaining methods are for retrieving information about attributes // Remaining methods are for retrieving information about attributes
// associated with a START_TAG: // associated with a START_TAG:
@@ -729,10 +740,10 @@ public:
// Returns -1 if no namespace, -2 if idx out of range. // Returns -1 if no namespace, -2 if idx out of range.
int32_t getAttributeNamespaceID(size_t idx) const; int32_t getAttributeNamespaceID(size_t idx) const;
const uint16_t* getAttributeNamespace(size_t idx, size_t* outLen) const; const char16_t* getAttributeNamespace(size_t idx, size_t* outLen) const;
int32_t getAttributeNameID(size_t idx) const; int32_t getAttributeNameID(size_t idx) const;
const uint16_t* getAttributeName(size_t idx, size_t* outLen) const; const char16_t* getAttributeName(size_t idx, size_t* outLen) const;
uint32_t getAttributeNameResID(size_t idx) const; uint32_t getAttributeNameResID(size_t idx) const;
// These will work only if the underlying string pool is UTF-8. // These will work only if the underlying string pool is UTF-8.
@@ -740,7 +751,7 @@ public:
const char* getAttributeName8(size_t idx, size_t* outLen) const; const char* getAttributeName8(size_t idx, size_t* outLen) const;
int32_t getAttributeValueStringID(size_t idx) const; int32_t getAttributeValueStringID(size_t idx) const;
const uint16_t* getAttributeStringValue(size_t idx, size_t* outLen) const; const char16_t* getAttributeStringValue(size_t idx, size_t* outLen) const;
int32_t getAttributeDataType(size_t idx) const; int32_t getAttributeDataType(size_t idx) const;
int32_t getAttributeData(size_t idx) const; int32_t getAttributeData(size_t idx) const;
@@ -845,7 +856,7 @@ struct ResTable_package
uint32_t id; uint32_t id;
// Actual name of this package, \0-terminated. // Actual name of this package, \0-terminated.
char16_t name[128]; uint16_t name[128];
// Offset to a ResStringPool_header defining the resource // Offset to a ResStringPool_header defining the resource
// type symbol table. If zero, this package is inheriting from // type symbol table. If zero, this package is inheriting from
@@ -1450,7 +1461,7 @@ struct ResTable_lib_entry
uint32_t packageId; uint32_t packageId;
// The package name of the shared library. \0 terminated. // The package name of the shared library. \0 terminated.
char16_t packageName[128]; uint16_t packageName[128];
}; };
/** /**
@@ -1681,7 +1692,7 @@ public:
size_t defPackageLen = 0, size_t defPackageLen = 0,
uint32_t* outTypeSpecFlags = NULL) const; uint32_t* outTypeSpecFlags = NULL) const;
static bool expandResourceRef(const uint16_t* refStr, size_t refLen, static bool expandResourceRef(const char16_t* refStr, size_t refLen,
String16* outPackage, String16* outPackage,
String16* outType, String16* outType,
String16* outName, String16* outName,

View File

@@ -14,7 +14,7 @@
LOCAL_PATH:= $(call my-dir) LOCAL_PATH:= $(call my-dir)
# libandroidfw is partially built for the host (used by obbtool and others) # libandroidfw is partially built for the host (used by obbtool, aapt, and others)
# These files are common to host and target builds. # These files are common to host and target builds.
commonSources := \ commonSources := \
@@ -35,26 +35,17 @@ deviceSources := \
BackupHelpers.cpp \ BackupHelpers.cpp \
CursorWindow.cpp CursorWindow.cpp
hostSources := \ hostSources := $(commonSources)
$(commonSources)
# For the host # For the host
# ===================================================== # =====================================================
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_SRC_FILES:= $(hostSources)
LOCAL_MODULE:= libandroidfw LOCAL_MODULE:= libandroidfw
LOCAL_MODULE_TAGS := optional LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -DSTATIC_ANDROIDFW_FOR_TOOLS LOCAL_CFLAGS += -DSTATIC_ANDROIDFW_FOR_TOOLS
LOCAL_SRC_FILES:= $(hostSources)
LOCAL_C_INCLUDES := \ LOCAL_C_INCLUDES := external/zlib
external/zlib
LOCAL_STATIC_LIBRARIES := liblog libziparchive-host libutils
include $(BUILD_HOST_STATIC_LIBRARY) include $(BUILD_HOST_STATIC_LIBRARY)
@@ -64,8 +55,13 @@ include $(BUILD_HOST_STATIC_LIBRARY)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE:= libandroidfw
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES:= $(deviceSources) LOCAL_SRC_FILES:= $(deviceSources)
LOCAL_C_INCLUDES := \
external/zlib \
system/core/include
LOCAL_STATIC_LIBRARIES := libziparchive
LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \
libbinder \ libbinder \
liblog \ liblog \
@@ -73,16 +69,6 @@ LOCAL_SHARED_LIBRARIES := \
libutils \ libutils \
libz libz
LOCAL_STATIC_LIBRARIES := libziparchive
LOCAL_C_INCLUDES := \
external/zlib \
system/core/include
LOCAL_MODULE:= libandroidfw
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)

View File

@@ -87,11 +87,11 @@ inline static T max(T a, T b) {
// range checked; guaranteed to NUL-terminate within the stated number of available slots // range checked; guaranteed to NUL-terminate within the stated number of available slots
// NOTE: if this truncates the dst string due to running out of space, no attempt is // NOTE: if this truncates the dst string due to running out of space, no attempt is
// made to avoid splitting surrogate pairs. // made to avoid splitting surrogate pairs.
static void strcpy16_dtoh(uint16_t* dst, const uint16_t* src, size_t avail) static void strcpy16_dtoh(char16_t* dst, const uint16_t* src, size_t avail)
{ {
uint16_t* last = dst + avail - 1; char16_t* last = dst + avail - 1;
while (*src && (dst < last)) { while (*src && (dst < last)) {
char16_t s = dtohs(*src); char16_t s = dtohs(static_cast<char16_t>(*src));
*dst++ = s; *dst++ = s;
src++; src++;
} }
@@ -501,7 +501,7 @@ status_t ResStringPool::setTo(const void* data, size_t size, bool copyData)
if (mHeader->flags&ResStringPool_header::UTF8_FLAG) { if (mHeader->flags&ResStringPool_header::UTF8_FLAG) {
charSize = sizeof(uint8_t); charSize = sizeof(uint8_t);
} else { } else {
charSize = sizeof(char16_t); charSize = sizeof(uint16_t);
} }
// There should be at least space for the smallest string // There should be at least space for the smallest string
@@ -547,8 +547,8 @@ status_t ResStringPool::setTo(const void* data, size_t size, bool copyData)
e[i] = dtohl(mEntries[i]); e[i] = dtohl(mEntries[i]);
} }
if (!(mHeader->flags&ResStringPool_header::UTF8_FLAG)) { if (!(mHeader->flags&ResStringPool_header::UTF8_FLAG)) {
const char16_t* strings = (const char16_t*)mStrings; const uint16_t* strings = (const uint16_t*)mStrings;
char16_t* s = const_cast<char16_t*>(strings); uint16_t* s = const_cast<uint16_t*>(strings);
for (i=0; i<mStringPoolSize; i++) { for (i=0; i<mStringPoolSize; i++) {
s[i] = dtohs(strings[i]); s[i] = dtohs(strings[i]);
} }
@@ -558,7 +558,7 @@ status_t ResStringPool::setTo(const void* data, size_t size, bool copyData)
if ((mHeader->flags&ResStringPool_header::UTF8_FLAG && if ((mHeader->flags&ResStringPool_header::UTF8_FLAG &&
((uint8_t*)mStrings)[mStringPoolSize-1] != 0) || ((uint8_t*)mStrings)[mStringPoolSize-1] != 0) ||
(!mHeader->flags&ResStringPool_header::UTF8_FLAG && (!mHeader->flags&ResStringPool_header::UTF8_FLAG &&
((char16_t*)mStrings)[mStringPoolSize-1] != 0)) { ((uint16_t*)mStrings)[mStringPoolSize-1] != 0)) {
ALOGW("Bad string block: last string is not 0-terminated\n"); ALOGW("Bad string block: last string is not 0-terminated\n");
return (mError=BAD_TYPE); return (mError=BAD_TYPE);
} }
@@ -656,7 +656,7 @@ void ResStringPool::uninit()
* add it together with the next character. * add it together with the next character.
*/ */
static inline size_t static inline size_t
decodeLength(const char16_t** str) decodeLength(const uint16_t** str)
{ {
size_t len = **str; size_t len = **str;
if ((len & 0x8000) != 0) { if ((len & 0x8000) != 0) {
@@ -689,19 +689,19 @@ decodeLength(const uint8_t** str)
return len; return len;
} }
const uint16_t* ResStringPool::stringAt(size_t idx, size_t* u16len) const const char16_t* ResStringPool::stringAt(size_t idx, size_t* u16len) const
{ {
if (mError == NO_ERROR && idx < mHeader->stringCount) { if (mError == NO_ERROR && idx < mHeader->stringCount) {
const bool isUTF8 = (mHeader->flags&ResStringPool_header::UTF8_FLAG) != 0; const bool isUTF8 = (mHeader->flags&ResStringPool_header::UTF8_FLAG) != 0;
const uint32_t off = mEntries[idx]/(isUTF8?sizeof(char):sizeof(char16_t)); const uint32_t off = mEntries[idx]/(isUTF8?sizeof(uint8_t):sizeof(uint16_t));
if (off < (mStringPoolSize-1)) { if (off < (mStringPoolSize-1)) {
if (!isUTF8) { if (!isUTF8) {
const char16_t* strings = (char16_t*)mStrings; const uint16_t* strings = (uint16_t*)mStrings;
const char16_t* str = strings+off; const uint16_t* str = strings+off;
*u16len = decodeLength(&str); *u16len = decodeLength(&str);
if ((uint32_t)(str+*u16len-strings) < mStringPoolSize) { if ((uint32_t)(str+*u16len-strings) < mStringPoolSize) {
return str; return reinterpret_cast<const char16_t*>(str);
} else { } else {
ALOGW("Bad string block: string #%d extends to %d, past end at %d\n", ALOGW("Bad string block: string #%d extends to %d, past end at %d\n",
(int)idx, (int)(str+*u16len-strings), (int)mStringPoolSize); (int)idx, (int)(str+*u16len-strings), (int)mStringPoolSize);
@@ -1013,7 +1013,7 @@ int32_t ResXMLParser::getCommentID() const
return mCurNode != NULL ? dtohl(mCurNode->comment.index) : -1; return mCurNode != NULL ? dtohl(mCurNode->comment.index) : -1;
} }
const uint16_t* ResXMLParser::getComment(size_t* outLen) const const char16_t* ResXMLParser::getComment(size_t* outLen) const
{ {
int32_t id = getCommentID(); int32_t id = getCommentID();
return id >= 0 ? mTree.mStrings.stringAt(id, outLen) : NULL; return id >= 0 ? mTree.mStrings.stringAt(id, outLen) : NULL;
@@ -1032,7 +1032,7 @@ int32_t ResXMLParser::getTextID() const
return -1; return -1;
} }
const uint16_t* ResXMLParser::getText(size_t* outLen) const const char16_t* ResXMLParser::getText(size_t* outLen) const
{ {
int32_t id = getTextID(); int32_t id = getTextID();
return id >= 0 ? mTree.mStrings.stringAt(id, outLen) : NULL; return id >= 0 ? mTree.mStrings.stringAt(id, outLen) : NULL;
@@ -1055,7 +1055,7 @@ int32_t ResXMLParser::getNamespacePrefixID() const
return -1; return -1;
} }
const uint16_t* ResXMLParser::getNamespacePrefix(size_t* outLen) const const char16_t* ResXMLParser::getNamespacePrefix(size_t* outLen) const
{ {
int32_t id = getNamespacePrefixID(); int32_t id = getNamespacePrefixID();
//printf("prefix=%d event=%p\n", id, mEventCode); //printf("prefix=%d event=%p\n", id, mEventCode);
@@ -1070,7 +1070,7 @@ int32_t ResXMLParser::getNamespaceUriID() const
return -1; return -1;
} }
const uint16_t* ResXMLParser::getNamespaceUri(size_t* outLen) const const char16_t* ResXMLParser::getNamespaceUri(size_t* outLen) const
{ {
int32_t id = getNamespaceUriID(); int32_t id = getNamespaceUriID();
//printf("uri=%d event=%p\n", id, mEventCode); //printf("uri=%d event=%p\n", id, mEventCode);
@@ -1088,7 +1088,7 @@ int32_t ResXMLParser::getElementNamespaceID() const
return -1; return -1;
} }
const uint16_t* ResXMLParser::getElementNamespace(size_t* outLen) const const char16_t* ResXMLParser::getElementNamespace(size_t* outLen) const
{ {
int32_t id = getElementNamespaceID(); int32_t id = getElementNamespaceID();
return id >= 0 ? mTree.mStrings.stringAt(id, outLen) : NULL; return id >= 0 ? mTree.mStrings.stringAt(id, outLen) : NULL;
@@ -1105,7 +1105,7 @@ int32_t ResXMLParser::getElementNameID() const
return -1; return -1;
} }
const uint16_t* ResXMLParser::getElementName(size_t* outLen) const const char16_t* ResXMLParser::getElementName(size_t* outLen) const
{ {
int32_t id = getElementNameID(); int32_t id = getElementNameID();
return id >= 0 ? mTree.mStrings.stringAt(id, outLen) : NULL; return id >= 0 ? mTree.mStrings.stringAt(id, outLen) : NULL;
@@ -1134,7 +1134,7 @@ int32_t ResXMLParser::getAttributeNamespaceID(size_t idx) const
return -2; return -2;
} }
const uint16_t* ResXMLParser::getAttributeNamespace(size_t idx, size_t* outLen) const const char16_t* ResXMLParser::getAttributeNamespace(size_t idx, size_t* outLen) const
{ {
int32_t id = getAttributeNamespaceID(idx); int32_t id = getAttributeNamespaceID(idx);
//printf("attribute namespace=%d idx=%d event=%p\n", id, idx, mEventCode); //printf("attribute namespace=%d idx=%d event=%p\n", id, idx, mEventCode);
@@ -1165,7 +1165,7 @@ int32_t ResXMLParser::getAttributeNameID(size_t idx) const
return -1; return -1;
} }
const uint16_t* ResXMLParser::getAttributeName(size_t idx, size_t* outLen) const const char16_t* ResXMLParser::getAttributeName(size_t idx, size_t* outLen) const
{ {
int32_t id = getAttributeNameID(idx); int32_t id = getAttributeNameID(idx);
//printf("attribute name=%d idx=%d event=%p\n", id, idx, mEventCode); //printf("attribute name=%d idx=%d event=%p\n", id, idx, mEventCode);
@@ -1205,7 +1205,7 @@ int32_t ResXMLParser::getAttributeValueStringID(size_t idx) const
return -1; return -1;
} }
const uint16_t* ResXMLParser::getAttributeStringValue(size_t idx, size_t* outLen) const const char16_t* ResXMLParser::getAttributeStringValue(size_t idx, size_t* outLen) const
{ {
int32_t id = getAttributeValueStringID(idx); int32_t id = getAttributeValueStringID(idx);
//XML_NOISY(printf("getAttributeValue 0x%x=0x%x\n", idx, id)); //XML_NOISY(printf("getAttributeValue 0x%x=0x%x\n", idx, id));
@@ -4239,7 +4239,7 @@ nope:
return 0; return 0;
} }
bool ResTable::expandResourceRef(const uint16_t* refStr, size_t refLen, bool ResTable::expandResourceRef(const char16_t* refStr, size_t refLen,
String16* outPackage, String16* outPackage,
String16* outType, String16* outType,
String16* outName, String16* outName,
@@ -5665,8 +5665,8 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg,
if (idx == 0) { if (idx == 0) {
idx = mPackageGroups.size() + 1; idx = mPackageGroups.size() + 1;
char16_t tmpName[sizeof(pkg->name)/sizeof(char16_t)]; char16_t tmpName[sizeof(pkg->name)/sizeof(pkg->name[0])];
strcpy16_dtoh(tmpName, pkg->name, sizeof(pkg->name)/sizeof(char16_t)); strcpy16_dtoh(tmpName, pkg->name, sizeof(pkg->name)/sizeof(pkg->name[0]));
group = new PackageGroup(this, String16(tmpName), id); group = new PackageGroup(this, String16(tmpName), id);
if (group == NULL) { if (group == NULL) {
delete package; delete package;
@@ -6036,7 +6036,10 @@ status_t ResTable::createIdmap(const ResTable& overlay,
*outSize += 2 * sizeof(uint16_t); *outSize += 2 * sizeof(uint16_t);
// overlay packages are assumed to contain only one package group // overlay packages are assumed to contain only one package group
const String16 overlayPackage(overlay.mPackageGroups[0]->packages[0]->package->name); const ResTable_package* overlayPackageStruct = overlay.mPackageGroups[0]->packages[0]->package;
char16_t tmpName[sizeof(overlayPackageStruct->name)/sizeof(overlayPackageStruct->name[0])];
strcpy16_dtoh(tmpName, overlayPackageStruct->name, sizeof(overlayPackageStruct->name)/sizeof(overlayPackageStruct->name[0]));
const String16 overlayPackage(tmpName);
for (size_t typeIndex = 0; typeIndex < pg->types.size(); ++typeIndex) { for (size_t typeIndex = 0; typeIndex < pg->types.size(); ++typeIndex) {
const TypeList& typeList = pg->types[typeIndex]; const TypeList& typeList = pg->types[typeIndex];
@@ -6345,8 +6348,10 @@ void ResTable::print(bool inclValues) const
// Use a package's real ID, since the ID may have been assigned // Use a package's real ID, since the ID may have been assigned
// if this package is a shared library. // if this package is a shared library.
packageId = pkg->package->id; packageId = pkg->package->id;
char16_t tmpName[sizeof(pkg->package->name)/sizeof(pkg->package->name[0])];
strcpy16_dtoh(tmpName, pkg->package->name, sizeof(pkg->package->name)/sizeof(pkg->package->name[0]));
printf(" Package %d id=0x%02x name=%s\n", (int)pkgIndex, printf(" Package %d id=0x%02x name=%s\n", (int)pkgIndex,
pkg->package->id, String8(String16(pkg->package->name)).string()); pkg->package->id, String8(tmpName).string());
} }
for (size_t typeIndex=0; typeIndex < pg->types.size(); typeIndex++) { for (size_t typeIndex=0; typeIndex < pg->types.size(); typeIndex++) {

View File

@@ -22,9 +22,9 @@
#include <androidfw/misc.h> #include <androidfw/misc.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <cstring>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <cstdio>
using namespace android; using namespace android;

View File

@@ -37,7 +37,6 @@ testFiles := \
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libandroidfw_tests LOCAL_MODULE := libandroidfw_tests
LOCAL_SRC_FILES := $(testFiles) LOCAL_SRC_FILES := $(testFiles)
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
libandroidfw \ libandroidfw \
@@ -55,11 +54,9 @@ ifneq ($(SDK_ONLY),true)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libandroidfw_tests LOCAL_MODULE := libandroidfw_tests
LOCAL_SRC_FILES := $(testFiles) \ LOCAL_SRC_FILES := $(testFiles) \
BackupData_test.cpp \ BackupData_test.cpp \
ObbFile_test.cpp ObbFile_test.cpp
LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \
libandroidfw \ libandroidfw \
libcutils \ libcutils \

View File

@@ -41,7 +41,7 @@ static String8 getStringAttributeAtIndex(const ResXMLTree& tree, ssize_t attrInd
} }
size_t len; size_t len;
const uint16_t* str = tree.getAttributeStringValue(attrIndex, &len); const char16_t* str = tree.getAttributeStringValue(attrIndex, &len);
return str ? String8(str, len) : String8(); return str ? String8(str, len) : String8();
} }
@@ -103,7 +103,7 @@ String8 getResolvedAttribute(const ResTable& resTable, const ResXMLTree& tree,
if (tree.getAttributeValue(idx, &value) != NO_ERROR) { if (tree.getAttributeValue(idx, &value) != NO_ERROR) {
if (value.dataType == Res_value::TYPE_STRING) { if (value.dataType == Res_value::TYPE_STRING) {
size_t len; size_t len;
const uint16_t* str = tree.getAttributeStringValue(idx, &len); const char16_t* str = tree.getAttributeStringValue(idx, &len);
return str ? String8(str, len) : String8(); return str ? String8(str, len) : String8();
} }
resTable.resolveReference(&value, 0); resTable.resolveReference(&value, 0);

View File

@@ -33,20 +33,20 @@ aaptSources := \
Command.cpp \ Command.cpp \
CrunchCache.cpp \ CrunchCache.cpp \
FileFinder.cpp \ FileFinder.cpp \
Images.cpp \
Package.cpp \ Package.cpp \
StringPool.cpp \ pseudolocalize.cpp \
XMLNode.cpp \ qsort_r_compat.c \
Resource.cpp \
ResourceFilter.cpp \ ResourceFilter.cpp \
ResourceIdCache.cpp \ ResourceIdCache.cpp \
ResourceTable.cpp \ ResourceTable.cpp \
Images.cpp \
Resource.cpp \
pseudolocalize.cpp \
SourcePos.cpp \ SourcePos.cpp \
StringPool.cpp \
WorkQueue.cpp \ WorkQueue.cpp \
XMLNode.cpp \
ZipEntry.cpp \ ZipEntry.cpp \
ZipFile.cpp \ ZipFile.cpp
qsort_r_compat.c
aaptTests := \ aaptTests := \
tests/AaptConfig_test.cpp \ tests/AaptConfig_test.cpp \
@@ -88,16 +88,13 @@ endif
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libaapt LOCAL_MODULE := libaapt
LOCAL_CFLAGS += -Wno-format-y2k -DSTATIC_ANDROIDFW_FOR_TOOLS $(aaptCFlags)
LOCAL_SRC_FILES := $(aaptSources) LOCAL_CPPFLAGS += $(aaptCppFlags)
LOCAL_C_INCLUDES += $(aaptCIncludes)
LOCAL_CFLAGS += -Wno-format-y2k
LOCAL_CFLAGS += -DSTATIC_ANDROIDFW_FOR_TOOLS
LOCAL_CFLAGS += $(aaptCFlags)
ifeq (darwin,$(HOST_OS)) ifeq (darwin,$(HOST_OS))
LOCAL_CFLAGS += -D_DARWIN_UNLIMITED_STREAMS LOCAL_CFLAGS += -D_DARWIN_UNLIMITED_STREAMS
endif endif
LOCAL_C_INCLUDES += $(aaptCIncludes)
LOCAL_SRC_FILES := $(aaptSources)
include $(BUILD_HOST_STATIC_LIBRARY) include $(BUILD_HOST_STATIC_LIBRARY)
@@ -108,15 +105,11 @@ include $(BUILD_HOST_STATIC_LIBRARY)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := aapt LOCAL_MODULE := aapt
LOCAL_SRC_FILES := $(aaptMain)
LOCAL_STATIC_LIBRARIES += \
libaapt \
$(aaptHostStaticLibs)
LOCAL_LDLIBS += $(aaptHostLdLibs)
LOCAL_CFLAGS += $(aaptCFlags) LOCAL_CFLAGS += $(aaptCFlags)
LOCAL_CPPFLAGS += $(aaptCppFlags)
LOCAL_LDLIBS += $(aaptHostLdLibs)
LOCAL_SRC_FILES := $(aaptMain)
LOCAL_STATIC_LIBRARIES += libaapt $(aaptHostStaticLibs)
include $(BUILD_HOST_EXECUTABLE) include $(BUILD_HOST_EXECUTABLE)
@@ -127,16 +120,12 @@ include $(BUILD_HOST_EXECUTABLE)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libaapt_tests LOCAL_MODULE := libaapt_tests
LOCAL_CFLAGS += $(aaptCFlags)
LOCAL_CPPFLAGS += $(aaptCppFlags)
LOCAL_LDLIBS += $(aaptHostLdLibs)
LOCAL_SRC_FILES += $(aaptTests) LOCAL_SRC_FILES += $(aaptTests)
LOCAL_C_INCLUDES += $(LOCAL_PATH) LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES += libaapt $(aaptHostStaticLibs)
LOCAL_STATIC_LIBRARIES += \
libaapt \
$(aaptHostStaticLibs)
LOCAL_LDLIBS += $(aaptHostLdLibs)
LOCAL_CFLAGS += $(aaptCFlags)
include $(BUILD_HOST_NATIVE_TEST) include $(BUILD_HOST_NATIVE_TEST)
@@ -148,13 +137,12 @@ ifneq ($(SDK_ONLY),true)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := aapt LOCAL_MODULE := aapt
LOCAL_CFLAGS += $(aaptCFlags)
LOCAL_SRC_FILES := $(aaptSources) $(aaptMain) LOCAL_SRC_FILES := $(aaptSources) $(aaptMain)
LOCAL_C_INCLUDES += \ LOCAL_C_INCLUDES += \
$(aaptCIncludes) \ $(aaptCIncludes) \
bionic \ bionic \
external/stlport/stlport external/stlport/stlport
LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \
libandroidfw \ libandroidfw \
libutils \ libutils \
@@ -162,14 +150,10 @@ LOCAL_SHARED_LIBRARIES := \
libpng \ libpng \
liblog \ liblog \
libz libz
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
libstlport_static \ libstlport_static \
libexpat_static libexpat_static
LOCAL_CFLAGS += $(aaptCFlags)
LOCAL_CPPFLAGS += -Wno-non-virtual-dtor
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
endif # Not SDK_ONLY endif # Not SDK_ONLY

View File

@@ -30,6 +30,8 @@ using namespace android;
*/ */
class CacheUpdater { class CacheUpdater {
public: public:
virtual ~CacheUpdater() {}
// Make sure all the directories along this path exist // Make sure all the directories along this path exist
virtual void ensureDirectoriesExist(String8 path) = 0; virtual void ensureDirectoriesExist(String8 path) = 0;
@@ -107,4 +109,4 @@ private:
Bundle* bundle; Bundle* bundle;
}; };
#endif // CACHE_UPDATER_H #endif // CACHE_UPDATER_H

View File

@@ -11,9 +11,9 @@
#include <utils/List.h> #include <utils/List.h>
#include <utils/Errors.h> #include <utils/Errors.h>
#include <stdlib.h> #include <cstdlib>
#include <getopt.h> #include <getopt.h>
#include <assert.h> #include <cassert>
using namespace android; using namespace android;

View File

@@ -261,7 +261,7 @@ static status_t parsePackage(Bundle* bundle, const sp<AaptAssets>& assets,
ssize_t minSdkIndex = block.indexOfAttribute(RESOURCES_ANDROID_NAMESPACE, ssize_t minSdkIndex = block.indexOfAttribute(RESOURCES_ANDROID_NAMESPACE,
"minSdkVersion"); "minSdkVersion");
if (minSdkIndex >= 0) { if (minSdkIndex >= 0) {
const uint16_t* minSdk16 = block.getAttributeStringValue(minSdkIndex, &len); const char16_t* minSdk16 = block.getAttributeStringValue(minSdkIndex, &len);
const char* minSdk8 = strdup(String8(minSdk16).string()); const char* minSdk8 = strdup(String8(minSdk16).string());
bundle->setManifestMinSdkVersion(minSdk8); bundle->setManifestMinSdkVersion(minSdk8);
} }
@@ -450,7 +450,7 @@ static int validateAttr(const String8& path, const ResTable& table,
size_t len; size_t len;
ssize_t index = parser.indexOfAttribute(ns, attr); ssize_t index = parser.indexOfAttribute(ns, attr);
const uint16_t* str; const char16_t* str;
Res_value value; Res_value value;
if (index >= 0 && parser.getAttributeValue(index, &value) >= 0) { if (index >= 0 && parser.getAttributeValue(index, &value) >= 0) {
const ResStringPool* pool = &parser.getStrings(); const ResStringPool* pool = &parser.getStrings();
@@ -503,7 +503,7 @@ static int validateAttr(const String8& path, const ResTable& table,
} }
if (validChars) { if (validChars) {
for (size_t i=0; i<len; i++) { for (size_t i=0; i<len; i++) {
uint16_t c = str[i]; char16_t c = str[i];
const char* p = validChars; const char* p = validChars;
bool okay = false; bool okay = false;
while (*p) { while (*p) {
@@ -1710,7 +1710,7 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets, sp<ApkBuil
} }
size_t len; size_t len;
ssize_t index = block.indexOfAttribute(RESOURCES_ANDROID_NAMESPACE, "name"); ssize_t index = block.indexOfAttribute(RESOURCES_ANDROID_NAMESPACE, "name");
const uint16_t* id = block.getAttributeStringValue(index, &len); const char16_t* id = block.getAttributeStringValue(index, &len);
if (id == NULL) { if (id == NULL) {
fprintf(stderr, "%s:%d: missing name attribute in element <%s>.\n", fprintf(stderr, "%s:%d: missing name attribute in element <%s>.\n",
manifestPath.string(), block.getLineNumber(), manifestPath.string(), block.getLineNumber(),
@@ -1753,7 +1753,7 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets, sp<ApkBuil
hasErrors = true; hasErrors = true;
} }
syms->addStringSymbol(String8(e), idStr, srcPos); syms->addStringSymbol(String8(e), idStr, srcPos);
const uint16_t* cmt = block.getComment(&len); const char16_t* cmt = block.getComment(&len);
if (cmt != NULL && *cmt != 0) { if (cmt != NULL && *cmt != 0) {
//printf("Comment of %s: %s\n", String8(e).string(), //printf("Comment of %s: %s\n", String8(e).string(),
// String8(cmt).string()); // String8(cmt).string());

View File

@@ -399,7 +399,7 @@ static status_t compileAttribute(const sp<AaptFile>& in,
ssize_t l10nIdx = block.indexOfAttribute(NULL, "localization"); ssize_t l10nIdx = block.indexOfAttribute(NULL, "localization");
if (l10nIdx >= 0) { if (l10nIdx >= 0) {
const uint16_t* str = block.getAttributeStringValue(l10nIdx, &len); const char16_t* str = block.getAttributeStringValue(l10nIdx, &len);
bool error; bool error;
uint32_t l10n_required = parse_flags(str, len, l10nRequiredFlags, &error); uint32_t l10n_required = parse_flags(str, len, l10nRequiredFlags, &error);
if (error) { if (error) {
@@ -1325,7 +1325,7 @@ status_t compileResourceFile(Bundle* bundle,
size_t n = block.getAttributeCount(); size_t n = block.getAttributeCount();
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
size_t length; size_t length;
const uint16_t* attr = block.getAttributeName(i, &length); const char16_t* attr = block.getAttributeName(i, &length);
if (strcmp16(attr, name16.string()) == 0) { if (strcmp16(attr, name16.string()) == 0) {
name.setTo(block.getAttributeStringValue(i, &length)); name.setTo(block.getAttributeStringValue(i, &length));
} else if (strcmp16(attr, translatable16.string()) == 0) { } else if (strcmp16(attr, translatable16.string()) == 0) {
@@ -1441,14 +1441,14 @@ status_t compileResourceFile(Bundle* bundle,
// translatable. // translatable.
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
size_t length; size_t length;
const uint16_t* attr = block.getAttributeName(i, &length); const char16_t* attr = block.getAttributeName(i, &length);
if (strcmp16(attr, formatted16.string()) == 0) { if (strcmp16(attr, formatted16.string()) == 0) {
const uint16_t* value = block.getAttributeStringValue(i, &length); const char16_t* value = block.getAttributeStringValue(i, &length);
if (strcmp16(value, false16.string()) == 0) { if (strcmp16(value, false16.string()) == 0) {
curIsFormatted = false; curIsFormatted = false;
} }
} else if (strcmp16(attr, translatable16.string()) == 0) { } else if (strcmp16(attr, translatable16.string()) == 0) {
const uint16_t* value = block.getAttributeStringValue(i, &length); const char16_t* value = block.getAttributeStringValue(i, &length);
if (strcmp16(value, false16.string()) == 0) { if (strcmp16(value, false16.string()) == 0) {
isTranslatable = false; isTranslatable = false;
} }

View File

@@ -21,7 +21,8 @@
#define NOISY(x) //x #define NOISY(x) //x
void strcpy16_htod(uint16_t* dst, const uint16_t* src) #if __cplusplus >= 201103L
void strcpy16_htod(char16_t* dst, const char16_t* src)
{ {
while (*src) { while (*src) {
char16_t s = htods(*src); char16_t s = htods(*src);
@@ -30,6 +31,17 @@ void strcpy16_htod(uint16_t* dst, const uint16_t* src)
} }
*dst = 0; *dst = 0;
} }
#endif
void strcpy16_htod(uint16_t* dst, const char16_t* src)
{
while (*src) {
uint16_t s = htods(static_cast<uint16_t>(*src));
*dst++ = s;
src++;
}
*dst = 0;
}
void printStringPool(const ResStringPool* pool) void printStringPool(const ResStringPool* pool)
{ {
@@ -416,7 +428,7 @@ status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
return NO_MEMORY; return NO_MEMORY;
} }
const size_t charSize = mUTF8 ? sizeof(uint8_t) : sizeof(char16_t); const size_t charSize = mUTF8 ? sizeof(uint8_t) : sizeof(uint16_t);
size_t strPos = 0; size_t strPos = 0;
for (i=0; i<STRINGS; i++) { for (i=0; i<STRINGS; i++) {

View File

@@ -26,7 +26,10 @@ using namespace android;
#define PRINT_STRING_METRICS 0 #define PRINT_STRING_METRICS 0
void strcpy16_htod(uint16_t* dst, const uint16_t* src); #if __cplusplus >= 201103L
void strcpy16_htod(char16_t* dst, const char16_t* src);
#endif
void strcpy16_htod(uint16_t* dst, const char16_t* src);
void printStringPool(const ResStringPool* pool); void printStringPool(const ResStringPool* pool);

View File

@@ -234,9 +234,9 @@ status_t parseStyledString(Bundle* bundle,
const String8 element8(element16); const String8 element8(element16);
size_t nslen; size_t nslen;
const uint16_t* ns = inXml->getElementNamespace(&nslen); const char16_t* ns = inXml->getElementNamespace(&nslen);
if (ns == NULL) { if (ns == NULL) {
ns = (const uint16_t*)"\0\0"; ns = (const char16_t*)"\0\0";
nslen = 0; nslen = 0;
} }
const String8 nspace(String16(ns, nslen)); const String8 nspace(String16(ns, nslen));
@@ -291,9 +291,9 @@ moveon:
} else if (code == ResXMLTree::END_TAG) { } else if (code == ResXMLTree::END_TAG) {
size_t nslen; size_t nslen;
const uint16_t* ns = inXml->getElementNamespace(&nslen); const char16_t* ns = inXml->getElementNamespace(&nslen);
if (ns == NULL) { if (ns == NULL) {
ns = (const uint16_t*)"\0\0"; ns = (const char16_t*)"\0\0";
nslen = 0; nslen = 0;
} }
const String8 nspace(String16(ns, nslen)); const String8 nspace(String16(ns, nslen));
@@ -422,7 +422,7 @@ static String8 make_prefix(int depth)
} }
static String8 build_namespace(const Vector<namespace_entry>& namespaces, static String8 build_namespace(const Vector<namespace_entry>& namespaces,
const uint16_t* ns) const char16_t* ns)
{ {
String8 str; String8 str;
if (ns != NULL) { if (ns != NULL) {
@@ -453,9 +453,9 @@ void printXMLBlock(ResXMLTree* block)
int i; int i;
if (code == ResXMLTree::START_TAG) { if (code == ResXMLTree::START_TAG) {
size_t len; size_t len;
const uint16_t* ns16 = block->getElementNamespace(&len); const char16_t* ns16 = block->getElementNamespace(&len);
String8 elemNs = build_namespace(namespaces, ns16); String8 elemNs = build_namespace(namespaces, ns16);
const uint16_t* com16 = block->getComment(&len); const char16_t* com16 = block->getComment(&len);
if (com16) { if (com16) {
printf("%s <!-- %s -->\n", prefix.string(), String8(com16).string()); printf("%s <!-- %s -->\n", prefix.string(), String8(com16).string());
} }
@@ -503,7 +503,7 @@ void printXMLBlock(ResXMLTree* block)
} else if (code == ResXMLTree::START_NAMESPACE) { } else if (code == ResXMLTree::START_NAMESPACE) {
namespace_entry ns; namespace_entry ns;
size_t len; size_t len;
const uint16_t* prefix16 = block->getNamespacePrefix(&len); const char16_t* prefix16 = block->getNamespacePrefix(&len);
if (prefix16) { if (prefix16) {
ns.prefix = String8(prefix16); ns.prefix = String8(prefix16);
} else { } else {
@@ -518,7 +518,7 @@ void printXMLBlock(ResXMLTree* block)
depth--; depth--;
const namespace_entry& ns = namespaces.top(); const namespace_entry& ns = namespaces.top();
size_t len; size_t len;
const uint16_t* prefix16 = block->getNamespacePrefix(&len); const char16_t* prefix16 = block->getNamespacePrefix(&len);
String8 pr; String8 pr;
if (prefix16) { if (prefix16) {
pr = String8(prefix16); pr = String8(prefix16);