Skip to content

Commit b2228eb

Browse files
Jean-Baptiste Queruandroid code review
authored andcommitted
Merge "Runtime resource overlay: clean-up."
2 parents 9e3bc3f + 249e3ed commit b2228eb

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

libs/utils/ResourceTypes.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4333,7 +4333,8 @@ status_t ResTable::createIdmap(const ResTable& overlay, uint32_t originalCrc, ui
43334333
const uint32_t pkg_id = pkg->package->id << 24;
43344334

43354335
for (size_t typeIndex = 0; typeIndex < typeCount; ++typeIndex) {
4336-
ssize_t offset = -1;
4336+
ssize_t first = -1;
4337+
ssize_t last = -1;
43374338
const Type* typeConfigs = pkg->getType(typeIndex);
43384339
ssize_t mapIndex = map.add();
43394340
if (mapIndex < 0) {
@@ -4347,6 +4348,8 @@ status_t ResTable::createIdmap(const ResTable& overlay, uint32_t originalCrc, ui
43474348
resource_name resName;
43484349
if (!this->getResourceName(resID, &resName)) {
43494350
ALOGW("idmap: resource 0x%08x has spec but lacks values, skipping\n", resID);
4351+
// add dummy value, or trimming leading/trailing zeroes later will fail
4352+
vector.push(0);
43504353
continue;
43514354
}
43524355

@@ -4360,11 +4363,12 @@ status_t ResTable::createIdmap(const ResTable& overlay, uint32_t originalCrc, ui
43604363
overlayPackage.size());
43614364
if (overlayResID != 0) {
43624365
overlayResID = pkg_id | (0x00ffffff & overlayResID);
4366+
last = Res_GETENTRY(resID);
4367+
if (first == -1) {
4368+
first = Res_GETENTRY(resID);
4369+
}
43634370
}
43644371
vector.push(overlayResID);
4365-
if (overlayResID != 0 && offset == -1) {
4366-
offset = Res_GETENTRY(resID);
4367-
}
43684372
#if 0
43694373
if (overlayResID != 0) {
43704374
ALOGD("%s/%s 0x%08x -> 0x%08x\n",
@@ -4375,13 +4379,16 @@ status_t ResTable::createIdmap(const ResTable& overlay, uint32_t originalCrc, ui
43754379
#endif
43764380
}
43774381

4378-
if (offset != -1) {
4379-
// shave off leading and trailing entries which lack overlay values
4380-
vector.removeItemsAt(0, offset);
4381-
vector.insertAt((uint32_t)offset, 0, 1);
4382-
while (vector.top() == 0) {
4383-
vector.pop();
4382+
if (first != -1) {
4383+
// shave off trailing entries which lack overlay values
4384+
const size_t last_past_one = last + 1;
4385+
if (last_past_one < vector.size()) {
4386+
vector.removeItemsAt(last_past_one, vector.size() - last_past_one);
43844387
}
4388+
// shave off leading entries which lack overlay values
4389+
vector.removeItemsAt(0, first);
4390+
// store offset to first overlaid resource ID of this type
4391+
vector.insertAt((uint32_t)first, 0, 1);
43854392
// reserve space for number and offset of entries, and the actual entries
43864393
*outSize += (2 + vector.size()) * sizeof(uint32_t);
43874394
} else {
@@ -4419,6 +4426,10 @@ status_t ResTable::createIdmap(const ResTable& overlay, uint32_t originalCrc, ui
44194426
if (N == 0) {
44204427
continue;
44214428
}
4429+
if (N == 1) { // vector expected to hold (offset) + (N > 0 entries)
4430+
ALOGW("idmap: type %d supposedly has entries, but no entries found\n", i);
4431+
return UNKNOWN_ERROR;
4432+
}
44224433
*data++ = htodl(N - 1); // do not count the offset (which is vector's first element)
44234434
for (size_t j = 0; j < N; ++j) {
44244435
const uint32_t& overlayResID = vector.itemAt(j);

tools/aapt/ResourceTable.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,6 +2661,12 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
26612661
const bool filterable = (typeName != mipmap16);
26622662

26632663
const size_t N = t != NULL ? t->getOrderedConfigs().size() : 0;
2664+
2665+
// Until a non-NO_ENTRY value has been written for a resource,
2666+
// that resource is invalid; validResources[i] represents
2667+
// the item at t->getOrderedConfigs().itemAt(i).
2668+
Vector<bool> validResources;
2669+
validResources.insertAt(false, 0, N);
26642670

26652671
// First write the typeSpec chunk, containing information about
26662672
// each resource entry in this type.
@@ -2797,6 +2803,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
27972803
if (amt < 0) {
27982804
return amt;
27992805
}
2806+
validResources.editItemAt(ei) = true;
28002807
} else {
28012808
index[ei] = htodl(ResTable_type::NO_ENTRY);
28022809
}
@@ -2807,6 +2814,14 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
28072814
(((uint8_t*)data->editData()) + typeStart);
28082815
tHeader->header.size = htodl(data->getSize()-typeStart);
28092816
}
2817+
2818+
for (size_t i = 0; i < N; ++i) {
2819+
if (!validResources[i]) {
2820+
sp<ConfigList> c = t->getOrderedConfigs().itemAt(i);
2821+
fprintf(stderr, "warning: no entries written for %s/%s\n",
2822+
String8(typeName).string(), String8(c->getName()).string());
2823+
}
2824+
}
28102825
}
28112826

28122827
// Fill in the rest of the package information.

0 commit comments

Comments
 (0)