Merge "resolved conflicts for merge of 487ae9b8 to lmp-mr1-dev-plus-aosp" into lmp-mr1-dev-plus-aosp

This commit is contained in:
Andreas Gampe
2014-11-07 23:15:28 +00:00
committed by Android (Google) Code Review
11 changed files with 412 additions and 249 deletions

View File

@@ -247,8 +247,8 @@ enum {
#define Res_MAKEINTERNAL(entry) (0x01000000 | (entry&0xFFFF)) #define Res_MAKEINTERNAL(entry) (0x01000000 | (entry&0xFFFF))
#define Res_MAKEARRAY(entry) (0x02000000 | (entry&0xFFFF)) #define Res_MAKEARRAY(entry) (0x02000000 | (entry&0xFFFF))
#define Res_MAXPACKAGE 255 static const size_t Res_MAXPACKAGE = 255;
#define Res_MAXTYPE 255 static const size_t Res_MAXTYPE = 255;
/** /**
* Representation of a value in a resource, supplying type * Representation of a value in a resource, supplying type

View File

@@ -45,6 +45,7 @@ LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
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_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
LOCAL_SRC_FILES:= $(hostSources) LOCAL_SRC_FILES:= $(hostSources)
LOCAL_C_INCLUDES := external/zlib LOCAL_C_INCLUDES := external/zlib
@@ -65,11 +66,13 @@ LOCAL_C_INCLUDES := \
system/core/include system/core/include
LOCAL_STATIC_LIBRARIES := libziparchive LOCAL_STATIC_LIBRARIES := libziparchive
LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \
libbinder \ libbinder \
liblog \ liblog \
libcutils \ libcutils \
libutils \ libutils \
libz libz
LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)

View File

@@ -45,6 +45,8 @@ using namespace android;
# define O_BINARY 0 # define O_BINARY 0
#endif #endif
static const bool kIsDebug = false;
static Mutex gAssetLock; static Mutex gAssetLock;
static int32_t gCount = 0; static int32_t gCount = 0;
static Asset* gHead = NULL; static Asset* gHead = NULL;
@@ -89,7 +91,9 @@ Asset::Asset(void)
gTail->mNext = this; gTail->mNext = this;
gTail = this; gTail = this;
} }
//ALOGI("Creating Asset %p #%d\n", this, gCount); if (kIsDebug) {
ALOGI("Creating Asset %p #%d\n", this, gCount);
}
} }
Asset::~Asset(void) Asset::~Asset(void)
@@ -109,7 +113,9 @@ Asset::~Asset(void)
mPrev->mNext = mNext; mPrev->mNext = mNext;
} }
mNext = mPrev = NULL; mNext = mPrev = NULL;
//ALOGI("Destroying Asset in %p #%d\n", this, gCount); if (kIsDebug) {
ALOGI("Destroying Asset in %p #%d\n", this, gCount);
}
} }
/* /*

View File

@@ -64,6 +64,8 @@
using namespace android; using namespace android;
static const bool kIsDebug = false;
/* /*
* Names for default app, locale, and vendor. We might want to change * Names for default app, locale, and vendor. We might want to change
* these to be an actual locale, e.g. always use en-US as the default. * these to be an actual locale, e.g. always use en-US as the default.
@@ -152,15 +154,19 @@ AssetManager::AssetManager(CacheMode cacheMode)
mResources(NULL), mConfig(new ResTable_config), mResources(NULL), mConfig(new ResTable_config),
mCacheMode(cacheMode), mCacheValid(false) mCacheMode(cacheMode), mCacheValid(false)
{ {
int count = android_atomic_inc(&gCount)+1; int count = android_atomic_inc(&gCount) + 1;
//ALOGI("Creating AssetManager %p #%d\n", this, count); if (kIsDebug) {
ALOGI("Creating AssetManager %p #%d\n", this, count);
}
memset(mConfig, 0, sizeof(ResTable_config)); memset(mConfig, 0, sizeof(ResTable_config));
} }
AssetManager::~AssetManager(void) AssetManager::~AssetManager(void)
{ {
int count = android_atomic_dec(&gCount); int count = android_atomic_dec(&gCount);
//ALOGI("Destroying AssetManager in %p #%d\n", this, count); if (kIsDebug) {
ALOGI("Destroying AssetManager in %p #%d\n", this, count);
}
delete mConfig; delete mConfig;
delete mResources; delete mResources;
@@ -1864,7 +1870,9 @@ AssetManager::SharedZip::SharedZip(const String8& path, time_t modWhen)
: mPath(path), mZipFile(NULL), mModWhen(modWhen), : mPath(path), mZipFile(NULL), mModWhen(modWhen),
mResourceTableAsset(NULL), mResourceTable(NULL) mResourceTableAsset(NULL), mResourceTable(NULL)
{ {
//ALOGI("Creating SharedZip %p %s\n", this, (const char*)mPath); if (kIsDebug) {
ALOGI("Creating SharedZip %p %s\n", this, (const char*)mPath);
}
ALOGV("+++ opening zip '%s'\n", mPath.string()); ALOGV("+++ opening zip '%s'\n", mPath.string());
mZipFile = ZipFileRO::open(mPath.string()); mZipFile = ZipFileRO::open(mPath.string());
if (mZipFile == NULL) { if (mZipFile == NULL) {
@@ -1958,7 +1966,9 @@ bool AssetManager::SharedZip::getOverlay(size_t idx, asset_path* out) const
AssetManager::SharedZip::~SharedZip() AssetManager::SharedZip::~SharedZip()
{ {
//ALOGI("Destroying SharedZip %p %s\n", this, (const char*)mPath); if (kIsDebug) {
ALOGI("Destroying SharedZip %p %s\n", this, (const char*)mPath);
}
if (mResourceTable != NULL) { if (mResourceTable != NULL) {
delete mResourceTable; delete mResourceTable;
} }

View File

@@ -27,7 +27,7 @@
namespace android { namespace android {
static const bool DEBUG = false; static const bool kIsDebug = false;
/* /*
* File Format (v1): * File Format (v1):
@@ -62,7 +62,7 @@ BackupDataWriter::BackupDataWriter(int fd)
m_entityCount(0) m_entityCount(0)
{ {
m_pos = (ssize_t) lseek(fd, 0, SEEK_CUR); m_pos = (ssize_t) lseek(fd, 0, SEEK_CUR);
if (DEBUG) ALOGI("BackupDataWriter(%d) @ %ld", fd, (long)m_pos); if (kIsDebug) ALOGI("BackupDataWriter(%d) @ %ld", fd, (long)m_pos);
} }
BackupDataWriter::~BackupDataWriter() BackupDataWriter::~BackupDataWriter()
@@ -79,7 +79,7 @@ BackupDataWriter::write_padding_for(int n)
paddingSize = padding_extra(n); paddingSize = padding_extra(n);
if (paddingSize > 0) { if (paddingSize > 0) {
uint32_t padding = 0xbcbcbcbc; uint32_t padding = 0xbcbcbcbc;
if (DEBUG) ALOGI("writing %zd padding bytes for %d", paddingSize, n); if (kIsDebug) ALOGI("writing %zd padding bytes for %d", paddingSize, n);
amt = write(m_fd, &padding, paddingSize); amt = write(m_fd, &padding, paddingSize);
if (amt != paddingSize) { if (amt != paddingSize) {
m_status = errno; m_status = errno;
@@ -112,7 +112,7 @@ BackupDataWriter::WriteEntityHeader(const String8& key, size_t dataSize)
} else { } else {
k = key; k = key;
} }
if (DEBUG) { if (kIsDebug) {
ALOGD("Writing header: prefix='%s' key='%s' dataSize=%zu", m_keyPrefix.string(), ALOGD("Writing header: prefix='%s' key='%s' dataSize=%zu", m_keyPrefix.string(),
key.string(), dataSize); key.string(), dataSize);
} }
@@ -126,7 +126,7 @@ BackupDataWriter::WriteEntityHeader(const String8& key, size_t dataSize)
header.keyLen = tolel(keyLen); header.keyLen = tolel(keyLen);
header.dataSize = tolel(dataSize); header.dataSize = tolel(dataSize);
if (DEBUG) ALOGI("writing entity header, %zu bytes", sizeof(entity_header_v1)); if (kIsDebug) ALOGI("writing entity header, %zu bytes", sizeof(entity_header_v1));
amt = write(m_fd, &header, sizeof(entity_header_v1)); amt = write(m_fd, &header, sizeof(entity_header_v1));
if (amt != sizeof(entity_header_v1)) { if (amt != sizeof(entity_header_v1)) {
m_status = errno; m_status = errno;
@@ -134,7 +134,7 @@ BackupDataWriter::WriteEntityHeader(const String8& key, size_t dataSize)
} }
m_pos += amt; m_pos += amt;
if (DEBUG) ALOGI("writing entity header key, %zd bytes", keyLen+1); if (kIsDebug) ALOGI("writing entity header key, %zd bytes", keyLen+1);
amt = write(m_fd, k.string(), keyLen+1); amt = write(m_fd, k.string(), keyLen+1);
if (amt != keyLen+1) { if (amt != keyLen+1) {
m_status = errno; m_status = errno;
@@ -152,10 +152,10 @@ BackupDataWriter::WriteEntityHeader(const String8& key, size_t dataSize)
status_t status_t
BackupDataWriter::WriteEntityData(const void* data, size_t size) BackupDataWriter::WriteEntityData(const void* data, size_t size)
{ {
if (DEBUG) ALOGD("Writing data: size=%lu", (unsigned long) size); if (kIsDebug) ALOGD("Writing data: size=%lu", (unsigned long) size);
if (m_status != NO_ERROR) { if (m_status != NO_ERROR) {
if (DEBUG) { if (kIsDebug) {
ALOGD("Not writing data - stream in error state %d (%s)", m_status, strerror(m_status)); ALOGD("Not writing data - stream in error state %d (%s)", m_status, strerror(m_status));
} }
return m_status; return m_status;
@@ -167,7 +167,7 @@ BackupDataWriter::WriteEntityData(const void* data, size_t size)
ssize_t amt = write(m_fd, data, size); ssize_t amt = write(m_fd, data, size);
if (amt != (ssize_t)size) { if (amt != (ssize_t)size) {
m_status = errno; m_status = errno;
if (DEBUG) ALOGD("write returned error %d (%s)", m_status, strerror(m_status)); if (kIsDebug) ALOGD("write returned error %d (%s)", m_status, strerror(m_status));
return m_status; return m_status;
} }
m_pos += amt; m_pos += amt;
@@ -189,7 +189,7 @@ BackupDataReader::BackupDataReader(int fd)
{ {
memset(&m_header, 0, sizeof(m_header)); memset(&m_header, 0, sizeof(m_header));
m_pos = (ssize_t) lseek(fd, 0, SEEK_CUR); m_pos = (ssize_t) lseek(fd, 0, SEEK_CUR);
if (DEBUG) ALOGI("BackupDataReader(%d) @ %ld", fd, (long)m_pos); if (kIsDebug) ALOGI("BackupDataReader(%d) @ %ld", fd, (long)m_pos);
} }
BackupDataReader::~BackupDataReader() BackupDataReader::~BackupDataReader()
@@ -342,15 +342,19 @@ BackupDataReader::ReadEntityData(void* data, size_t size)
return -1; return -1;
} }
int remaining = m_dataEndPos - m_pos; int remaining = m_dataEndPos - m_pos;
//ALOGD("ReadEntityData size=%d m_pos=0x%x m_dataEndPos=0x%x remaining=%d\n", if (kIsDebug) {
// size, m_pos, m_dataEndPos, remaining); ALOGD("ReadEntityData size=%d m_pos=0x%x m_dataEndPos=0x%x remaining=%d\n",
size, m_pos, m_dataEndPos, remaining);
}
if (remaining <= 0) { if (remaining <= 0) {
return 0; return 0;
} }
if (((int)size) > remaining) { if (((int)size) > remaining) {
size = remaining; size = remaining;
} }
//ALOGD(" reading %d bytes", size); if (kIsDebug) {
ALOGD(" reading %d bytes", size);
}
int amt = read(m_fd, data, size); int amt = read(m_fd, data, size);
if (amt < 0) { if (amt < 0) {
m_status = errno; m_status = errno;

View File

@@ -68,14 +68,11 @@ struct file_metadata_v1 {
const static int CURRENT_METADATA_VERSION = 1; const static int CURRENT_METADATA_VERSION = 1;
#if 1 static const bool kIsDebug = false;
#define LOGP(f, x...)
#else
#if TEST_BACKUP_HELPERS #if TEST_BACKUP_HELPERS
#define LOGP(f, x...) printf(f "\n", x) #define LOGP(f, x...) if (kIsDebug) printf(f "\n", x)
#else #else
#define LOGP(x...) ALOGD(x) #define LOGP(x...) if (kIsDebug) ALOGD(x)
#endif
#endif #endif
const static int ROUND_UP[4] = { 0, 3, 2, 1 }; const static int ROUND_UP[4] = { 0, 3, 2, 1 };
@@ -204,13 +201,6 @@ write_snapshot_file(int fd, const KeyedVector<String8,FileRec>& snapshot)
return 0; return 0;
} }
static int
write_delete_file(BackupDataWriter* dataStream, const String8& key)
{
LOGP("write_delete_file %s\n", key.string());
return dataStream->WriteEntityHeader(key, -1);
}
static int static int
write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8& key, write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8& key,
char const* realFilename) char const* realFilename)
@@ -225,8 +215,6 @@ write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8&
file_metadata_v1 metadata; file_metadata_v1 metadata;
char* buf = (char*)malloc(bufsize); char* buf = (char*)malloc(bufsize);
int crc = crc32(0L, Z_NULL, 0);
fileSize = lseek(fd, 0, SEEK_END); fileSize = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
@@ -442,18 +430,6 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD
return 0; return 0;
} }
// Utility function, equivalent to stpcpy(): perform a strcpy, but instead of
// returning the initial dest, return a pointer to the trailing NUL.
static char* strcpy_ptr(char* dest, const char* str) {
if (dest && str) {
while ((*dest = *str) != 0) {
dest++;
str++;
}
}
return dest;
}
static void calc_tar_checksum(char* buf) { static void calc_tar_checksum(char* buf) {
// [ 148 : 8 ] checksum -- to be calculated with this field as space chars // [ 148 : 8 ] checksum -- to be calculated with this field as space chars
memset(buf + 148, ' ', 8); memset(buf + 148, ' ', 8);
@@ -635,7 +611,6 @@ int write_tarfile(const String8& packageName, const String8& domain,
// construct the pax extended header data block // construct the pax extended header data block
memset(paxData, 0, BUFSIZE - (paxData - buf)); memset(paxData, 0, BUFSIZE - (paxData - buf));
int len;
// size header -- calc len in digits by actually rendering the number // size header -- calc len in digits by actually rendering the number
// to a string - brute force but simple // to a string - brute force but simple
@@ -1200,7 +1175,6 @@ test_read_header_and_entity(BackupDataReader& reader, const char* str)
size_t bufSize = strlen(str)+1; size_t bufSize = strlen(str)+1;
char* buf = (char*)malloc(bufSize); char* buf = (char*)malloc(bufSize);
String8 string; String8 string;
int cookie = 0x11111111;
size_t actualSize; size_t actualSize;
bool done; bool done;
int type; int type;
@@ -1490,7 +1464,6 @@ int
backup_helper_test_null_base() backup_helper_test_null_base()
{ {
int err; int err;
int oldSnapshotFD;
int dataStreamFD; int dataStreamFD;
int newSnapshotFD; int newSnapshotFD;
@@ -1539,7 +1512,6 @@ int
backup_helper_test_missing_file() backup_helper_test_missing_file()
{ {
int err; int err;
int oldSnapshotFD;
int dataStreamFD; int dataStreamFD;
int newSnapshotFD; int newSnapshotFD;

View File

@@ -122,7 +122,7 @@ bool ObbFile::parseObbFile(int fd)
if (fileLength < 0) { if (fileLength < 0) {
ALOGW("error seeking in ObbFile: %s\n", strerror(errno)); ALOGW("error seeking in ObbFile: %s\n", strerror(errno));
} else { } else {
ALOGW("file is only %lld (less than %d minimum)\n", fileLength, kFooterMinSize); ALOGW("file is only %lld (less than %d minimum)\n", (long long int)fileLength, kFooterMinSize);
} }
return false; return false;
} }
@@ -150,8 +150,8 @@ bool ObbFile::parseObbFile(int fd)
footerSize = get4LE((unsigned char*)footer); footerSize = get4LE((unsigned char*)footer);
if (footerSize > (size_t)fileLength - kFooterTagSize if (footerSize > (size_t)fileLength - kFooterTagSize
|| footerSize > kMaxBufSize) { || footerSize > kMaxBufSize) {
ALOGW("claimed footer size is too large (0x%08zx; file size is 0x%08llx)\n", ALOGW("claimed footer size is too large (0x%08zx; file size is 0x%08lld)\n",
footerSize, fileLength); footerSize, (long long int)fileLength);
return false; return false;
} }
@@ -164,7 +164,7 @@ bool ObbFile::parseObbFile(int fd)
off64_t fileOffset = fileLength - footerSize - kFooterTagSize; off64_t fileOffset = fileLength - footerSize - kFooterTagSize;
if (lseek64(fd, fileOffset, SEEK_SET) != fileOffset) { if (lseek64(fd, fileOffset, SEEK_SET) != fileOffset) {
ALOGW("seek %lld failed: %s\n", fileOffset, strerror(errno)); ALOGW("seek %lld failed: %s\n", (long long int)fileOffset, strerror(errno));
return false; return false;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -41,6 +41,8 @@
_rc; }) _rc; })
#endif #endif
static const bool kIsDebug = false;
static inline size_t min_of(size_t a, size_t b) { return (a < b) ? a : b; } static inline size_t min_of(size_t a, size_t b) { return (a < b) ? a : b; }
using namespace android; using namespace android;
@@ -209,7 +211,9 @@ int StreamingZipInflater::readNextChunk() {
size_t toRead = min_of(mInBufSize, mInTotalSize - mInNextChunkOffset); size_t toRead = min_of(mInBufSize, mInTotalSize - mInNextChunkOffset);
if (toRead > 0) { if (toRead > 0) {
ssize_t didRead = TEMP_FAILURE_RETRY(::read(mFd, mInBuf, toRead)); ssize_t didRead = TEMP_FAILURE_RETRY(::read(mFd, mInBuf, toRead));
//ALOGV("Reading input chunk, size %08x didread %08x", toRead, didRead); if (kIsDebug) {
ALOGV("Reading input chunk, size %08zx didread %08zx", toRead, didRead);
}
if (didRead < 0) { if (didRead < 0) {
ALOGE("Error reading asset data: %s", strerror(errno)); ALOGE("Error reading asset data: %s", strerror(errno));
return didRead; return didRead;

View File

@@ -34,14 +34,6 @@
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
/*
* We must open binary files using open(path, ... | O_BINARY) under Windows.
* Otherwise strange read errors will happen.
*/
#ifndef O_BINARY
# define O_BINARY 0
#endif
using namespace android; using namespace android;
class _ZipEntryRO { class _ZipEntryRO {

View File

@@ -37,12 +37,17 @@ testFiles := \
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libandroidfw_tests LOCAL_MODULE := libandroidfw_tests
LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
# gtest is broken.
LOCAL_CFLAGS += -Wno-unnamed-type-template-args
LOCAL_SRC_FILES := $(testFiles) LOCAL_SRC_FILES := $(testFiles)
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
libandroidfw \ libandroidfw \
libutils \ libutils \
libcutils \ libcutils \
liblog liblog
include $(BUILD_HOST_NATIVE_TEST) include $(BUILD_HOST_NATIVE_TEST)
@@ -54,6 +59,11 @@ ifneq ($(SDK_ONLY),true)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libandroidfw_tests LOCAL_MODULE := libandroidfw_tests
LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
# gtest is broken.
LOCAL_CFLAGS += -Wno-unnamed-type-template-args
LOCAL_SRC_FILES := $(testFiles) \ LOCAL_SRC_FILES := $(testFiles) \
BackupData_test.cpp \ BackupData_test.cpp \
ObbFile_test.cpp ObbFile_test.cpp