Skip to content

Commit 6c86839

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix issue #6054627: resource matching issue of size qualifiers"
2 parents da8b340 + 5c6dfeb commit 6c86839

File tree

1 file changed

+40
-49
lines changed

1 file changed

+40
-49
lines changed

libs/androidfw/ResourceTypes.cpp

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,9 @@ bool ResTable_config::isBetterThan(const ResTable_config& o,
16871687
// The configuration closest to the actual size is best.
16881688
// We assume that larger configs have already been filtered
16891689
// out at this point. That means we just want the largest one.
1690-
return smallestScreenWidthDp >= o.smallestScreenWidthDp;
1690+
if (smallestScreenWidthDp != o.smallestScreenWidthDp) {
1691+
return smallestScreenWidthDp > o.smallestScreenWidthDp;
1692+
}
16911693
}
16921694

16931695
if (screenSizeDp || o.screenSizeDp) {
@@ -1711,7 +1713,9 @@ bool ResTable_config::isBetterThan(const ResTable_config& o,
17111713
//ALOGI("Comparing this %dx%d to other %dx%d in %dx%d: myDelta=%d otherDelta=%d",
17121714
// screenWidthDp, screenHeightDp, o.screenWidthDp, o.screenHeightDp,
17131715
// requested->screenWidthDp, requested->screenHeightDp, myDelta, otherDelta);
1714-
return (myDelta <= otherDelta);
1716+
if (myDelta != otherDelta) {
1717+
return myDelta < otherDelta;
1718+
}
17151719
}
17161720

17171721
if (screenLayout || o.screenLayout) {
@@ -1738,7 +1742,9 @@ bool ResTable_config::isBetterThan(const ResTable_config& o,
17381742
if (mySL == 0) return false;
17391743
return true;
17401744
}
1741-
return fixedMySL >= fixedOSL;
1745+
if (fixedMySL != fixedOSL) {
1746+
return fixedMySL > fixedOSL;
1747+
}
17421748
}
17431749
if (((screenLayout^o.screenLayout) & MASK_SCREENLONG) != 0
17441750
&& (requested->screenLayout & MASK_SCREENLONG)) {
@@ -1857,7 +1863,9 @@ bool ResTable_config::isBetterThan(const ResTable_config& o,
18571863
myDelta += requested->screenHeight - screenHeight;
18581864
otherDelta += requested->screenHeight - o.screenHeight;
18591865
}
1860-
return (myDelta <= otherDelta);
1866+
if (myDelta != otherDelta) {
1867+
return myDelta < otherDelta;
1868+
}
18611869
}
18621870

18631871
if (version || o.version) {
@@ -2150,7 +2158,7 @@ String8 ResTable_config::toString() const {
21502158
res.append("nodpi");
21512159
break;
21522160
default:
2153-
res.appendFormat("density=%d", dtohs(density));
2161+
res.appendFormat("%ddpi", dtohs(density));
21542162
break;
21552163
}
21562164
}
@@ -2440,7 +2448,7 @@ status_t ResTable::Theme::applyStyle(uint32_t resID, bool force)
24402448
uint32_t bagTypeSpecFlags = 0;
24412449
mTable.lock();
24422450
const ssize_t N = mTable.getBagLocked(resID, &bag, &bagTypeSpecFlags);
2443-
TABLE_NOISY(LOGV("Applying style 0x%08x to theme %p, count=%d", resID, this, N));
2451+
TABLE_NOISY(ALOGV("Applying style 0x%08x to theme %p, count=%d", resID, this, N));
24442452
if (N < 0) {
24452453
mTable.unlock();
24462454
return N;
@@ -2506,7 +2514,7 @@ status_t ResTable::Theme::applyStyle(uint32_t resID, bool force)
25062514
continue;
25072515
}
25082516
theme_entry* curEntry = curEntries + e;
2509-
TABLE_NOISY(LOGV("Attr 0x%08x: type=0x%x, data=0x%08x; curType=0x%x",
2517+
TABLE_NOISY(ALOGV("Attr 0x%08x: type=0x%x, data=0x%08x; curType=0x%x",
25102518
attrRes, bag->map.value.dataType, bag->map.value.data,
25112519
curEntry->value.dataType));
25122520
if (force || curEntry->value.dataType == Res_value::TYPE_NULL) {
@@ -2577,22 +2585,22 @@ ssize_t ResTable::Theme::getAttribute(uint32_t resID, Res_value* outValue,
25772585
const uint32_t t = Res_GETTYPE(resID);
25782586
const uint32_t e = Res_GETENTRY(resID);
25792587

2580-
TABLE_THEME(LOGI("Looking up attr 0x%08x in theme %p", resID, this));
2588+
TABLE_THEME(ALOGI("Looking up attr 0x%08x in theme %p", resID, this));
25812589

25822590
if (p >= 0) {
25832591
const package_info* const pi = mPackages[p];
2584-
TABLE_THEME(LOGI("Found package: %p", pi));
2592+
TABLE_THEME(ALOGI("Found package: %p", pi));
25852593
if (pi != NULL) {
2586-
TABLE_THEME(LOGI("Desired type index is %ld in avail %d", t, pi->numTypes));
2594+
TABLE_THEME(ALOGI("Desired type index is %ld in avail %d", t, pi->numTypes));
25872595
if (t < pi->numTypes) {
25882596
const type_info& ti = pi->types[t];
2589-
TABLE_THEME(LOGI("Desired entry index is %ld in avail %d", e, ti.numEntries));
2597+
TABLE_THEME(ALOGI("Desired entry index is %ld in avail %d", e, ti.numEntries));
25902598
if (e < ti.numEntries) {
25912599
const theme_entry& te = ti.entries[e];
25922600
if (outTypeSpecFlags != NULL) {
25932601
*outTypeSpecFlags |= te.typeSpecFlags;
25942602
}
2595-
TABLE_THEME(LOGI("Theme value: type=0x%x, data=0x%08x",
2603+
TABLE_THEME(ALOGI("Theme value: type=0x%x, data=0x%08x",
25962604
te.value.dataType, te.value.data));
25972605
const uint8_t type = te.value.dataType;
25982606
if (type == Res_value::TYPE_ATTRIBUTE) {
@@ -2627,7 +2635,7 @@ ssize_t ResTable::Theme::resolveAttributeReference(Res_value* inOutValue,
26272635
if (inOutValue->dataType == Res_value::TYPE_ATTRIBUTE) {
26282636
uint32_t newTypeSpecFlags;
26292637
blockIndex = getAttribute(inOutValue->data, inOutValue, &newTypeSpecFlags);
2630-
TABLE_THEME(LOGI("Resolving attr reference: blockIndex=%d, type=0x%x, data=%p\n",
2638+
TABLE_THEME(ALOGI("Resolving attr reference: blockIndex=%d, type=0x%x, data=%p\n",
26312639
(int)blockIndex, (int)inOutValue->dataType, (void*)inOutValue->data));
26322640
if (inoutTypeSpecFlags != NULL) *inoutTypeSpecFlags |= newTypeSpecFlags;
26332641
//printf("Retrieved attribute new type=0x%x\n", inOutValue->dataType);
@@ -2772,7 +2780,7 @@ status_t ResTable::add(const void* data, size_t size, void* cookie,
27722780
header->size = dtohl(header->header->header.size);
27732781
//ALOGI("Got size 0x%x, again size 0x%x, raw size 0x%x\n", header->size,
27742782
// dtohl(header->header->header.size), header->header->header.size);
2775-
LOAD_TABLE_NOISY(LOGV("Loading ResTable @%p:\n", header->header));
2783+
LOAD_TABLE_NOISY(ALOGV("Loading ResTable @%p:\n", header->header));
27762784
LOAD_TABLE_NOISY(printHexData(2, header->header, header->size < 256 ? header->size : 256,
27772785
16, 16, 0, false, printToLogFunc));
27782786
if (dtohs(header->header->header.headerSize) > header->size
@@ -2802,7 +2810,7 @@ status_t ResTable::add(const void* data, size_t size, void* cookie,
28022810
if (err != NO_ERROR) {
28032811
return (mError=err);
28042812
}
2805-
TABLE_NOISY(LOGV("Chunk: type=0x%x, headerSize=0x%x, size=0x%x, pos=%p\n",
2813+
TABLE_NOISY(ALOGV("Chunk: type=0x%x, headerSize=0x%x, size=0x%x, pos=%p\n",
28062814
dtohs(chunk->type), dtohs(chunk->headerSize), dtohl(chunk->size),
28072815
(void*)(((const uint8_t*)chunk) - ((const uint8_t*)header->header))));
28082816
const size_t csize = dtohl(chunk->size);
@@ -2856,7 +2864,7 @@ status_t ResTable::add(const void* data, size_t size, void* cookie,
28562864
ALOGW("No string values found in resource table!");
28572865
}
28582866

2859-
TABLE_NOISY(LOGV("Returning from add with mError=%d\n", mError));
2867+
TABLE_NOISY(ALOGV("Returning from add with mError=%d\n", mError));
28602868
return mError;
28612869
}
28622870

@@ -3127,7 +3135,7 @@ ssize_t ResTable::resolveReference(Res_value* value, ssize_t blockIndex,
31273135
if (newIndex == BAD_INDEX) {
31283136
return BAD_INDEX;
31293137
}
3130-
TABLE_THEME(LOGI("Resolving reference %p: newIndex=%d, type=0x%x, data=%p\n",
3138+
TABLE_THEME(ALOGI("Resolving reference %p: newIndex=%d, type=0x%x, data=%p\n",
31313139
(void*)lastRef, (int)newIndex, (int)value->dataType, (void*)value->data));
31323140
//printf("Getting reference 0x%08x: newIndex=%d\n", value->data, newIndex);
31333141
if (inoutTypeSpecFlags != NULL) *inoutTypeSpecFlags |= newFlags;
@@ -3268,7 +3276,7 @@ ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,
32683276
// This is what we are building.
32693277
bag_set* set = NULL;
32703278

3271-
TABLE_NOISY(LOGI("Building bag: %p\n", (void*)resID));
3279+
TABLE_NOISY(ALOGI("Building bag: %p\n", (void*)resID));
32723280

32733281
ResTable_config bestConfig;
32743282
memset(&bestConfig, 0, sizeof(bestConfig));
@@ -3338,7 +3346,7 @@ ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,
33383346

33393347
size_t N = count;
33403348

3341-
TABLE_NOISY(LOGI("Found map: size=%p parent=%p count=%d\n",
3349+
TABLE_NOISY(ALOGI("Found map: size=%p parent=%p count=%d\n",
33423350
entrySize, parent, count));
33433351

33443352
// If this map inherits from another, we need to start
@@ -3357,9 +3365,9 @@ ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,
33573365
if (NP > 0) {
33583366
memcpy(set+1, parentBag, NP*sizeof(bag_entry));
33593367
set->numAttrs = NP;
3360-
TABLE_NOISY(LOGI("Initialized new bag with %d inherited attributes.\n", NP));
3368+
TABLE_NOISY(ALOGI("Initialized new bag with %d inherited attributes.\n", NP));
33613369
} else {
3362-
TABLE_NOISY(LOGI("Initialized new bag with no inherited attributes.\n"));
3370+
TABLE_NOISY(ALOGI("Initialized new bag with no inherited attributes.\n"));
33633371
set->numAttrs = 0;
33643372
}
33653373
set->availAttrs = NT;
@@ -3386,7 +3394,7 @@ ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,
33863394
bag_entry* entries = (bag_entry*)(set+1);
33873395
size_t curEntry = 0;
33883396
uint32_t pos = 0;
3389-
TABLE_NOISY(LOGI("Starting with set %p, entries=%p, avail=%d\n",
3397+
TABLE_NOISY(ALOGI("Starting with set %p, entries=%p, avail=%d\n",
33903398
set, entries, set->availAttrs));
33913399
while (pos < count) {
33923400
TABLE_NOISY(printf("Now at %p\n", (void*)curOff));
@@ -3465,7 +3473,7 @@ ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,
34653473
*outTypeSpecFlags = set->typeSpecFlags;
34663474
}
34673475
*outBag = (bag_entry*)(set+1);
3468-
TABLE_NOISY(LOGI("Returning %d attrs\n", set->numAttrs));
3476+
TABLE_NOISY(ALOGI("Returning %d attrs\n", set->numAttrs));
34693477
return set->numAttrs;
34703478
}
34713479
return BAD_INDEX;
@@ -3474,27 +3482,10 @@ ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,
34743482
void ResTable::setParameters(const ResTable_config* params)
34753483
{
34763484
mLock.lock();
3477-
TABLE_GETENTRY(LOGI("Setting parameters: imsi:%d/%d lang:%c%c cnt:%c%c "
3478-
"orien:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d sw%ddp w%ddp h%ddp\n",
3479-
params->mcc, params->mnc,
3480-
params->language[0] ? params->language[0] : '-',
3481-
params->language[1] ? params->language[1] : '-',
3482-
params->country[0] ? params->country[0] : '-',
3483-
params->country[1] ? params->country[1] : '-',
3484-
params->orientation,
3485-
params->touchscreen,
3486-
params->density,
3487-
params->keyboard,
3488-
params->inputFlags,
3489-
params->navigation,
3490-
params->screenWidth,
3491-
params->screenHeight,
3492-
params->smallestScreenWidthDp,
3493-
params->screenWidthDp,
3494-
params->screenHeightDp));
3485+
TABLE_GETENTRY(ALOGI("Setting parameters: %s\n", params->toString().string()));
34953486
mParams = *params;
34963487
for (size_t i=0; i<mPackageGroups.size(); i++) {
3497-
TABLE_NOISY(LOGI("CLEARING BAGS FOR GROUP %d!", i));
3488+
TABLE_NOISY(ALOGI("CLEARING BAGS FOR GROUP %d!", i));
34983489
mPackageGroups[i]->clearBagCache();
34993490
}
35003491
mLock.unlock();
@@ -4840,13 +4831,13 @@ ssize_t ResTable::getEntry(
48404831
ResTable_config thisConfig;
48414832
thisConfig.copyFromDtoH(thisType->config);
48424833

4843-
TABLE_GETENTRY(LOGI("Match entry 0x%x in type 0x%x (sz 0x%x): %s\n",
4834+
TABLE_GETENTRY(ALOGI("Match entry 0x%x in type 0x%x (sz 0x%x): %s\n",
48444835
entryIndex, typeIndex+1, dtohl(thisType->config.size),
48454836
thisConfig.toString().string()));
48464837

48474838
// Check to make sure this one is valid for the current parameters.
48484839
if (config && !thisConfig.match(*config)) {
4849-
TABLE_GETENTRY(LOGI("Does not match config!\n"));
4840+
TABLE_GETENTRY(ALOGI("Does not match config!\n"));
48504841
continue;
48514842
}
48524843

@@ -4859,7 +4850,7 @@ ssize_t ResTable::getEntry(
48594850

48604851
uint32_t thisOffset = dtohl(eindex[entryIndex]);
48614852
if (thisOffset == ResTable_type::NO_ENTRY) {
4862-
TABLE_GETENTRY(LOGI("Skipping because it is not defined!\n"));
4853+
TABLE_GETENTRY(ALOGI("Skipping because it is not defined!\n"));
48634854
continue;
48644855
}
48654856

@@ -4868,20 +4859,20 @@ ssize_t ResTable::getEntry(
48684859
// we will skip it. We check starting with things we most care
48694860
// about to those we least care about.
48704861
if (!thisConfig.isBetterThan(bestConfig, config)) {
4871-
TABLE_GETENTRY(LOGI("This config is worse than last!\n"));
4862+
TABLE_GETENTRY(ALOGI("This config is worse than last!\n"));
48724863
continue;
48734864
}
48744865
}
48754866

48764867
type = thisType;
48774868
offset = thisOffset;
48784869
bestConfig = thisConfig;
4879-
TABLE_GETENTRY(LOGI("Best entry so far -- using it!\n"));
4870+
TABLE_GETENTRY(ALOGI("Best entry so far -- using it!\n"));
48804871
if (!config) break;
48814872
}
48824873

48834874
if (type == NULL) {
4884-
TABLE_GETENTRY(LOGI("No value found for requested entry!\n"));
4875+
TABLE_GETENTRY(ALOGI("No value found for requested entry!\n"));
48854876
return BAD_INDEX;
48864877
}
48874878

@@ -5024,7 +5015,7 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg,
50245015
const uint8_t* endPos = ((const uint8_t*)pkg) + dtohs(pkg->header.size);
50255016
while (((const uint8_t*)chunk) <= (endPos-sizeof(ResChunk_header)) &&
50265017
((const uint8_t*)chunk) <= (endPos-dtohl(chunk->size))) {
5027-
TABLE_NOISY(LOGV("PackageChunk: type=0x%x, headerSize=0x%x, size=0x%x, pos=%p\n",
5018+
TABLE_NOISY(ALOGV("PackageChunk: type=0x%x, headerSize=0x%x, size=0x%x, pos=%p\n",
50285019
dtohs(chunk->type), dtohs(chunk->headerSize), dtohl(chunk->size),
50295020
(void*)(((const uint8_t*)chunk) - ((const uint8_t*)header->header))));
50305021
const size_t csize = dtohl(chunk->size);

0 commit comments

Comments
 (0)