summaryrefslogtreecommitdiff
path: root/tools/aapt/ResourceTable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt/ResourceTable.cpp')
-rw-r--r--tools/aapt/ResourceTable.cpp106
1 files changed, 82 insertions, 24 deletions
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index cf271a9e1ac8..efbba40f950d 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -1715,7 +1715,7 @@ status_t compileResourceFile(Bundle* bundle,
ResourceTable::ResourceTable(Bundle* bundle, const String16& assetsPackage)
: mAssetsPackage(assetsPackage), mNextPackageId(1), mHaveAppPackage(false),
- mIsAppPackage(!bundle->getExtending()),
+ mIsAppPackage(!bundle->getExtending()), mIsSharedLibrary(bundle->getBuildSharedLibrary()),
mNumLocal(0),
mBundle(bundle)
{
@@ -1737,8 +1737,9 @@ status_t ResourceTable::addIncludedResources(Bundle* bundle, const sp<AaptAssets
const size_t N = incl.getBasePackageCount();
for (size_t phase=0; phase<2; phase++) {
for (size_t i=0; i<N; i++) {
- String16 name(incl.getBasePackageName(i));
+ const String16 name = incl.getBasePackageName(i);
uint32_t id = incl.getBasePackageId(i);
+
// First time through: only add base packages (id
// is not 0); second time through add the other
// packages.
@@ -1764,7 +1765,7 @@ status_t ResourceTable::addIncludedResources(Bundle* bundle, const sp<AaptAssets
}
}
if (id != 0) {
- NOISY(printf("Including package %s with ID=%d\n",
+ NOISY(fprintf(stderr, "Including package %s with ID=%d\n",
String8(name).string(), id));
sp<Package> p = new Package(name, id);
mPackages.add(name, p);
@@ -2094,10 +2095,10 @@ bool ResourceTable::hasResources() const {
return mNumLocal > 0;
}
-sp<AaptFile> ResourceTable::flatten(Bundle* bundle)
+sp<AaptFile> ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>& filter)
{
sp<AaptFile> data = new AaptFile(String8(), AaptGroupEntry(), String8());
- status_t err = flatten(bundle, data);
+ status_t err = flatten(bundle, filter, data);
return err == NO_ERROR ? data : NULL;
}
@@ -2657,8 +2658,8 @@ ResourceTable::validateLocalizations(void)
}
// Check that all requested localizations are present for this string
- if (mBundle->getConfigurations() != NULL && mBundle->getRequireLocalization()) {
- const char* allConfigs = mBundle->getConfigurations();
+ if (mBundle->getConfigurations().size() > 0 && mBundle->getRequireLocalization()) {
+ const char* allConfigs = mBundle->getConfigurations().string();
const char* start = allConfigs;
const char* comma;
@@ -2712,14 +2713,8 @@ ResourceTable::validateLocalizations(void)
return err;
}
-status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
+status_t ResourceTable::flatten(Bundle* bundle, const sp<const ResourceFilter>& filter, const sp<AaptFile>& dest)
{
- ResourceFilter filter;
- status_t err = filter.parse(bundle->getConfigurations());
- if (err != NO_ERROR) {
- return err;
- }
-
const ConfigDescription nullConfig;
const size_t N = mOrderedPackages.size();
@@ -2729,6 +2724,9 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
bool useUTF8 = !bundle->getUTF16StringsOption();
+ // The libraries this table references.
+ Vector<sp<Package> > libraryPackages;
+
// Iterate through all data, collecting all values (strings,
// references, etc).
StringPool valueStrings(useUTF8);
@@ -2736,8 +2734,22 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
for (pi=0; pi<N; pi++) {
sp<Package> p = mOrderedPackages.itemAt(pi);
if (p->getTypes().size() == 0) {
- // Empty, skip!
+ // Empty, this is an imported package being used as
+ // a shared library. We do not flatten this package.
+ if (p->getAssignedId() != 0x01 && p->getName() != String16("android")) {
+ // This is not the base Android package, and it is a library
+ // so we must add a reference to the library when flattening.
+ libraryPackages.add(p);
+ }
continue;
+ } else if (p->getAssignedId() == 0x00) {
+ if (!bundle->getBuildSharedLibrary()) {
+ fprintf(stderr, "ERROR: Package %s can not have ID=0x00 unless building a shared library.",
+ String8(p->getName()).string());
+ return UNKNOWN_ERROR;
+ }
+ // If this is a shared library, we also include ourselves as an entry.
+ libraryPackages.add(p);
}
StringPool typeStrings(useUTF8);
@@ -2777,7 +2789,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
const size_t N = c->getEntries().size();
for (size_t ei=0; ei<N; ei++) {
ConfigDescription config = c->getEntries().keyAt(ei);
- if (filterable && !filter.match(config)) {
+ if (filterable && !filter->match(config)) {
continue;
}
sp<Entry> e = c->getEntries().valueAt(ei);
@@ -2820,7 +2832,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
}
ssize_t strAmt = 0;
-
+
// Now build the array of package chunks.
Vector<sp<AaptFile> > flatPackages;
for (pi=0; pi<N; pi++) {
@@ -2869,6 +2881,12 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
return amt;
}
+ status_t err = flattenLibraryTable(data, libraryPackages);
+ if (err != NO_ERROR) {
+ fprintf(stderr, "ERROR: failed to write library table\n");
+ return err;
+ }
+
// Build the type chunks inside of this package.
for (size_t ti=0; ti<N; ti++) {
// Retrieve them in the same order as the type string block.
@@ -2919,11 +2937,11 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
}
const size_t CN = cl->getEntries().size();
for (size_t ci=0; ci<CN; ci++) {
- if (filterable && !filter.match(cl->getEntries().keyAt(ci))) {
+ if (filterable && !filter->match(cl->getEntries().keyAt(ci))) {
continue;
}
for (size_t cj=ci+1; cj<CN; cj++) {
- if (filterable && !filter.match(cl->getEntries().keyAt(cj))) {
+ if (filterable && !filter->match(cl->getEntries().keyAt(cj))) {
continue;
}
typeSpecFlags[ei] |= htodl(
@@ -2965,7 +2983,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
config.screenHeightDp,
config.layoutDirection));
- if (filterable && !filter.match(config)) {
+ if (filterable && !filter->match(config)) {
continue;
}
@@ -3038,13 +3056,21 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
tHeader->header.size = htodl(data->getSize()-typeStart);
}
+ bool missing_entry = false;
+ const char* log_prefix = bundle->getErrorOnMissingConfigEntry() ?
+ "error" : "warning";
for (size_t i = 0; i < N; ++i) {
if (!validResources[i]) {
sp<ConfigList> c = t->getOrderedConfigs().itemAt(i);
- fprintf(stderr, "warning: no entries written for %s/%s\n",
+ fprintf(stderr, "%s: no entries written for %s/%s\n", log_prefix,
String8(typeName).string(), String8(c->getName()).string());
+ missing_entry = true;
}
}
+ if (bundle->getErrorOnMissingConfigEntry() && missing_entry) {
+ fprintf(stderr, "Error: Missing entries, quit!\n");
+ return NOT_ENOUGH_DATA;
+ }
}
// Fill in the rest of the package information.
@@ -3076,7 +3102,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
}
ssize_t strStart = dest->getSize();
- err = valueStrings.writeStringBlock(dest);
+ status_t err = valueStrings.writeStringBlock(dest);
if (err != NO_ERROR) {
return err;
}
@@ -3087,7 +3113,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
fprintf(stderr, "**** value strings: %d\n", amt);
fprintf(stderr, "**** total strings: %d\n", strAmt);
#endif
-
+
for (pi=0; pi<flatPackages.size(); pi++) {
err = dest->writeData(flatPackages[pi]->getData(),
flatPackages[pi]->getSize());
@@ -3112,6 +3138,38 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
return NO_ERROR;
}
+status_t ResourceTable::flattenLibraryTable(const sp<AaptFile>& dest, const Vector<sp<Package> >& libs) {
+ // Write out the library table if necessary
+ if (libs.size() > 0) {
+ NOISY(fprintf(stderr, "Writing library reference table\n"));
+
+ const size_t libStart = dest->getSize();
+ const size_t count = libs.size();
+ ResTable_lib_header* libHeader = (ResTable_lib_header*) dest->editDataInRange(libStart, sizeof(ResTable_lib_header));
+
+ memset(libHeader, 0, sizeof(*libHeader));
+ libHeader->header.type = htods(RES_TABLE_LIBRARY_TYPE);
+ libHeader->header.headerSize = htods(sizeof(*libHeader));
+ libHeader->header.size = htodl(sizeof(*libHeader) + (sizeof(ResTable_lib_entry) * count));
+ libHeader->count = htodl(count);
+
+ // Write the library entries
+ for (size_t i = 0; i < count; i++) {
+ const size_t entryStart = dest->getSize();
+ sp<Package> libPackage = libs[i];
+ NOISY(fprintf(stderr, " Entry %s -> 0x%02x\n",
+ String8(libPackage->getName()).string(),
+ (uint8_t)libPackage->getAssignedId()));
+
+ ResTable_lib_entry* entry = (ResTable_lib_entry*) dest->editDataInRange(entryStart, sizeof(ResTable_lib_entry));
+ memset(entry, 0, sizeof(*entry));
+ entry->packageId = htodl(libPackage->getAssignedId());
+ strcpy16_htod(entry->packageName, libPackage->getName().string());
+ }
+ }
+ return NO_ERROR;
+}
+
void ResourceTable::writePublicDefinitions(const String16& package, FILE* fp)
{
fprintf(fp,
@@ -3881,7 +3939,7 @@ sp<ResourceTable::Package> ResourceTable::getPackage(const String16& package)
return NULL;
}
mHaveAppPackage = true;
- p = new Package(package, 127);
+ p = new Package(package, mIsSharedLibrary ? 0 : 127);
} else {
p = new Package(package, mNextPackageId);
}