Search all packages for a given type string when looking up resources by name
Previously we would stop at the first match when looking for a type string, but we should search all packages in case a feature Split added a type with the same name. Bug:17924027 Change-Id: I6bc7ef073324db99448538cd8bdf566658f066ff
This commit is contained in:
@ -4175,57 +4175,61 @@ nope:
|
||||
continue;
|
||||
}
|
||||
|
||||
const ssize_t ti = group->findType16(type, typeLen);
|
||||
if (ti < 0) {
|
||||
TABLE_NOISY(printf("Type not found in package %s\n", String8(group->name).string()));
|
||||
continue;
|
||||
}
|
||||
|
||||
const TypeList& typeList = group->types[ti];
|
||||
if (typeList.isEmpty()) {
|
||||
TABLE_NOISY(printf("Expected type structure not found in package %s for index %d\n",
|
||||
String8(group->name).string(), ti));
|
||||
continue;
|
||||
}
|
||||
|
||||
const size_t typeCount = typeList.size();
|
||||
for (size_t i = 0; i < typeCount; i++) {
|
||||
const Type* t = typeList[i];
|
||||
const ssize_t ei = t->package->keyStrings.indexOfString(name, nameLen);
|
||||
if (ei < 0) {
|
||||
const size_t packageCount = group->packages.size();
|
||||
for (size_t pi = 0; pi < packageCount; pi++) {
|
||||
ssize_t ti = group->packages[pi]->typeStrings.indexOfString(type, typeLen);
|
||||
if (ti < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const size_t configCount = t->configs.size();
|
||||
for (size_t j = 0; j < configCount; j++) {
|
||||
const TypeVariant tv(t->configs[j]);
|
||||
for (TypeVariant::iterator iter = tv.beginEntries();
|
||||
iter != tv.endEntries();
|
||||
iter++) {
|
||||
const ResTable_entry* entry = *iter;
|
||||
if (entry == NULL) {
|
||||
continue;
|
||||
}
|
||||
ti += group->packages[pi]->typeIdOffset;
|
||||
|
||||
if (dtohl(entry->key.index) == (size_t) ei) {
|
||||
uint32_t resId = Res_MAKEID(group->id - 1, ti, iter.index());
|
||||
if (outTypeSpecFlags) {
|
||||
Entry result;
|
||||
if (getEntry(group, ti, iter.index(), NULL, &result) != NO_ERROR) {
|
||||
ALOGW("Failed to find spec flags for %s:%s/%s (0x%08x)",
|
||||
String8(group->name).string(),
|
||||
String8(String16(type, typeLen)).string(),
|
||||
String8(String16(name, nameLen)).string(),
|
||||
resId);
|
||||
return 0;
|
||||
}
|
||||
*outTypeSpecFlags = result.specFlags;
|
||||
const TypeList& typeList = group->types[ti];
|
||||
if (typeList.isEmpty()) {
|
||||
TABLE_NOISY(printf("Expected type structure not found in package %s for index %d\n",
|
||||
String8(group->name).string(), ti));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fakePublic) {
|
||||
*outTypeSpecFlags |= ResTable_typeSpec::SPEC_PUBLIC;
|
||||
}
|
||||
const size_t typeCount = typeList.size();
|
||||
for (size_t i = 0; i < typeCount; i++) {
|
||||
const Type* t = typeList[i];
|
||||
const ssize_t ei = t->package->keyStrings.indexOfString(name, nameLen);
|
||||
if (ei < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const size_t configCount = t->configs.size();
|
||||
for (size_t j = 0; j < configCount; j++) {
|
||||
const TypeVariant tv(t->configs[j]);
|
||||
for (TypeVariant::iterator iter = tv.beginEntries();
|
||||
iter != tv.endEntries();
|
||||
iter++) {
|
||||
const ResTable_entry* entry = *iter;
|
||||
if (entry == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dtohl(entry->key.index) == (size_t) ei) {
|
||||
uint32_t resId = Res_MAKEID(group->id - 1, ti, iter.index());
|
||||
if (outTypeSpecFlags) {
|
||||
Entry result;
|
||||
if (getEntry(group, ti, iter.index(), NULL, &result) != NO_ERROR) {
|
||||
ALOGW("Failed to find spec flags for %s:%s/%s (0x%08x)",
|
||||
String8(group->name).string(),
|
||||
String8(String16(type, typeLen)).string(),
|
||||
String8(String16(name, nameLen)).string(),
|
||||
resId);
|
||||
return 0;
|
||||
}
|
||||
*outTypeSpecFlags = result.specFlags;
|
||||
|
||||
if (fakePublic) {
|
||||
*outTypeSpecFlags |= ResTable_typeSpec::SPEC_PUBLIC;
|
||||
}
|
||||
}
|
||||
return resId;
|
||||
}
|
||||
return resId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ TEST(SplitFeatureTest, TestNewResourceIsAccessible) {
|
||||
EXPECT_EQ(Res_value::TYPE_STRING, val.dataType);
|
||||
}
|
||||
|
||||
TEST(SplitFeatureTest, TestNewResourceIsAccessibleByName) {
|
||||
TEST(SplitFeatureTest, TestNewResourceNameHasCorrectName) {
|
||||
ResTable table;
|
||||
ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len));
|
||||
|
||||
@ -200,4 +200,17 @@ TEST(SplitFeatureTest, TestNewResourceIsAccessibleByName) {
|
||||
String16(name.name, name.nameLen));
|
||||
}
|
||||
|
||||
TEST(SplitFeatureTest, TestNewResourceIsAccessibleByName) {
|
||||
ResTable table;
|
||||
ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len));
|
||||
ASSERT_EQ(NO_ERROR, table.add(feature_arsc, feature_arsc_len));
|
||||
|
||||
const String16 name("test3");
|
||||
const String16 type("string");
|
||||
const String16 package("com.android.test.basic");
|
||||
ASSERT_EQ(base::R::string::test3, table.identifierForName(name.string(), name.size(),
|
||||
type.string(), type.size(),
|
||||
package.string(), package.size()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user