summaryrefslogtreecommitdiff
path: root/tools/aapt/ResourceTable.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2015-08-14 13:16:18 -0700
committerAdam Lesinski <adamlesinski@google.com>2015-08-14 13:41:46 -0700
commitbeb9e33bfb79847c25aac98e39f3ea620a953ef7 (patch)
tree4f795b9e4b2cdf95f1dd6b43fdf02eb9fc438b0e /tools/aapt/ResourceTable.cpp
parent81eeef589386483722c21572d9ab6d3f95dd26be (diff)
AAPT: Fix regression in resource versioning
With a set of resources with the following configurations: () (land) the regression caused any resources that needed to be versioned in configuration () to be lost. Bug:23038206 Change-Id: I2f1b0313fb780ac241e7aaa487cb37dfb79c36aa
Diffstat (limited to 'tools/aapt/ResourceTable.cpp')
-rw-r--r--tools/aapt/ResourceTable.cpp37
1 files changed, 19 insertions, 18 deletions
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index 81642fa4392c..d5a09d817b1e 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -4466,9 +4466,10 @@ static int getMinSdkVersion(const Bundle* bundle) {
return 0;
}
-static bool shouldGenerateVersionedResource(const sp<ResourceTable::ConfigList>& configList,
- const ConfigDescription& sourceConfig,
- const int sdkVersionToGenerate) {
+bool ResourceTable::shouldGenerateVersionedResource(
+ const sp<ResourceTable::ConfigList>& configList,
+ const ConfigDescription& sourceConfig,
+ const int sdkVersionToGenerate) {
assert(sdkVersionToGenerate > sourceConfig.sdkVersion);
const DefaultKeyedVector<ConfigDescription, sp<ResourceTable::Entry>>& entries
= configList->getEntries();
@@ -4477,24 +4478,24 @@ static bool shouldGenerateVersionedResource(const sp<ResourceTable::ConfigList>&
// The source config came from this list, so it should be here.
assert(idx >= 0);
- idx += 1;
- if (static_cast<size_t>(idx) >= entries.size()) {
- // This is the last configuration, so we should generate a versioned resource.
- return true;
- }
+ // The next configuration either only varies in sdkVersion, or it is completely different
+ // and therefore incompatible. If it is incompatible, we must generate the versioned resource.
- const ConfigDescription& nextConfig = entries.keyAt(idx);
-
- // Build a configuration that is the same as the source config,
- // but with the SDK level of the next config. If they are the same,
- // then they only differ in SDK level. If the next configs SDK level is
- // higher than the one we want to generate, we must generate it.
+ // NOTE: The ordering of configurations takes sdkVersion as higher precedence than other
+ // qualifiers, so we need to iterate through the entire list to be sure there
+ // are no higher sdk level versions of this resource.
ConfigDescription tempConfig(sourceConfig);
- tempConfig.sdkVersion = nextConfig.sdkVersion;
- if (nextConfig == tempConfig) {
- return sdkVersionToGenerate < nextConfig.sdkVersion;
+ for (size_t i = static_cast<size_t>(idx) + 1; i < entries.size(); i++) {
+ const ConfigDescription& nextConfig = entries.keyAt(i);
+ tempConfig.sdkVersion = nextConfig.sdkVersion;
+ if (tempConfig == nextConfig) {
+ // The two configs are the same, check the sdk version.
+ return sdkVersionToGenerate < nextConfig.sdkVersion;
+ }
}
- return false;
+
+ // No match was found, so we should generate the versioned resource.
+ return true;
}
/**