From beb9e33bfb79847c25aac98e39f3ea620a953ef7 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Fri, 14 Aug 2015 13:16:18 -0700 Subject: 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 --- tools/aapt/ResourceTable.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'tools/aapt/ResourceTable.cpp') 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& configList, - const ConfigDescription& sourceConfig, - const int sdkVersionToGenerate) { +bool ResourceTable::shouldGenerateVersionedResource( + const sp& configList, + const ConfigDescription& sourceConfig, + const int sdkVersionToGenerate) { assert(sdkVersionToGenerate > sourceConfig.sdkVersion); const DefaultKeyedVector>& entries = configList->getEntries(); @@ -4477,24 +4478,24 @@ static bool shouldGenerateVersionedResource(const sp& // The source config came from this list, so it should be here. assert(idx >= 0); - idx += 1; - if (static_cast(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(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; } /** -- cgit v1.2.3-59-g8ed1b