Add per-named-item overlay ability in res xml.
Fixes 1899451. Also errors out if you add a bag via an overlay (which would renumber resources). Note that you can still add elements within the bag as they are not issued resource IDs. So for example you can now modify the framework themes.xml file without copying the entire file. All bag types are now modifable except non-named bag types (how would you address which element to replace?): array string_array integer_array
This commit is contained in:
@ -729,6 +729,7 @@ status_t compileResourceFile(Bundle* bundle,
|
|||||||
String16 curType;
|
String16 curType;
|
||||||
int32_t curFormat = ResTable_map::TYPE_ANY;
|
int32_t curFormat = ResTable_map::TYPE_ANY;
|
||||||
bool curIsBag = false;
|
bool curIsBag = false;
|
||||||
|
bool curIsBagReplaceOnOverwrite = false;
|
||||||
bool curIsStyled = false;
|
bool curIsStyled = false;
|
||||||
bool curIsPseudolocalizable = false;
|
bool curIsPseudolocalizable = false;
|
||||||
bool localHasErrors = false;
|
bool localHasErrors = false;
|
||||||
@ -1171,6 +1172,7 @@ status_t compileResourceFile(Bundle* bundle,
|
|||||||
curTag = &array16;
|
curTag = &array16;
|
||||||
curType = array16;
|
curType = array16;
|
||||||
curIsBag = true;
|
curIsBag = true;
|
||||||
|
curIsBagReplaceOnOverwrite = true;
|
||||||
ssize_t formatIdx = block.indexOfAttribute(NULL, "format");
|
ssize_t formatIdx = block.indexOfAttribute(NULL, "format");
|
||||||
if (formatIdx >= 0) {
|
if (formatIdx >= 0) {
|
||||||
String16 formatStr = String16(block.getAttributeStringValue(
|
String16 formatStr = String16(block.getAttributeStringValue(
|
||||||
@ -1189,12 +1191,14 @@ status_t compileResourceFile(Bundle* bundle,
|
|||||||
curType = array16;
|
curType = array16;
|
||||||
curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_STRING;
|
curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_STRING;
|
||||||
curIsBag = true;
|
curIsBag = true;
|
||||||
|
curIsBagReplaceOnOverwrite = true;
|
||||||
curIsPseudolocalizable = true;
|
curIsPseudolocalizable = true;
|
||||||
} else if (strcmp16(block.getElementName(&len), integer_array16.string()) == 0) {
|
} else if (strcmp16(block.getElementName(&len), integer_array16.string()) == 0) {
|
||||||
curTag = &integer_array16;
|
curTag = &integer_array16;
|
||||||
curType = array16;
|
curType = array16;
|
||||||
curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_INTEGER;
|
curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_INTEGER;
|
||||||
curIsBag = true;
|
curIsBag = true;
|
||||||
|
curIsBagReplaceOnOverwrite = true;
|
||||||
} else {
|
} else {
|
||||||
SourcePos(in->getPrintableSource(), block.getLineNumber()).error(
|
SourcePos(in->getPrintableSource(), block.getLineNumber()).error(
|
||||||
"Found tag %s where item is expected\n",
|
"Found tag %s where item is expected\n",
|
||||||
@ -1229,9 +1233,10 @@ status_t compileResourceFile(Bundle* bundle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!localHasErrors) {
|
if (!localHasErrors) {
|
||||||
err = outTable->startBag(SourcePos(in->getPrintableSource(), block.getLineNumber()),
|
err = outTable->startBag(SourcePos(in->getPrintableSource(),
|
||||||
myPackage, curType, ident, parentIdent, &curParams,
|
block.getLineNumber()), myPackage, curType, ident,
|
||||||
overwrite);
|
parentIdent, &curParams,
|
||||||
|
overwrite, curIsBagReplaceOnOverwrite);
|
||||||
if (err != NO_ERROR) {
|
if (err != NO_ERROR) {
|
||||||
hasErrors = localHasErrors = true;
|
hasErrors = localHasErrors = true;
|
||||||
}
|
}
|
||||||
@ -1529,6 +1534,7 @@ status_t ResourceTable::startBag(const SourcePos& sourcePos,
|
|||||||
const String16& name,
|
const String16& name,
|
||||||
const String16& bagParent,
|
const String16& bagParent,
|
||||||
const ResTable_config* params,
|
const ResTable_config* params,
|
||||||
|
bool overlay,
|
||||||
bool replace, bool isId)
|
bool replace, bool isId)
|
||||||
{
|
{
|
||||||
status_t result = NO_ERROR;
|
status_t result = NO_ERROR;
|
||||||
@ -1549,7 +1555,12 @@ status_t ResourceTable::startBag(const SourcePos& sourcePos,
|
|||||||
sourcePos.file.striing(), sourcePos.line, String8(type).string());
|
sourcePos.file.striing(), sourcePos.line, String8(type).string());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (overlay && !hasBagOrEntry(package, type, name)) {
|
||||||
|
sourcePos.error("Can't add new bags in an overlay. See '%s'\n",
|
||||||
|
String8(name).string());
|
||||||
|
return UNKNOWN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
sp<Entry> e = getEntry(package, type, name, sourcePos, params);
|
sp<Entry> e = getEntry(package, type, name, sourcePos, params);
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
@ -1571,7 +1582,7 @@ status_t ResourceTable::startBag(const SourcePos& sourcePos,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (replace) {
|
if (overlay && replace) {
|
||||||
return e->emptyBag(sourcePos);
|
return e->emptyBag(sourcePos);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -96,6 +96,7 @@ public:
|
|||||||
const String16& name,
|
const String16& name,
|
||||||
const String16& bagParent,
|
const String16& bagParent,
|
||||||
const ResTable_config* params = NULL,
|
const ResTable_config* params = NULL,
|
||||||
|
bool overlay = false,
|
||||||
bool replace = false,
|
bool replace = false,
|
||||||
bool isId = false);
|
bool isId = false);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user