summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author y <rtmitchell@google.com> 2018-04-13 11:25:12 -0700
committer y <rtmitchell@google.com> 2018-04-13 16:15:42 -0700
commit35ecb89a8aa68f24d2e991df5bb9964ad15075dc (patch)
tree4a6694c3430fea5d6ae5b0bd3680aab24a303232
parenta668c663019dcabe62d1f667ec5402806a22b0a8 (diff)
AAPT: Modified StringPool uniqueness detection
b/77862560 detected that when converting an apk to binary using aapt2, all resource ids of attributes that have been replaced with resource identifiers become set to the identifier of the first attribute. This is because the attribute names are all empty because the names are not necessary since the resource ids are present. The empty attribute names all map to the same string pool reference and cause all the ids to be the first empty string into the string pool. Bug: 77862560 Test: Converted apk in listed bug from proto to binary and observed correct resource ids and correct badging. Change-Id: I635c13cd1ad7a395fe40a57198cfe5ec91602d01
-rw-r--r--tools/aapt2/StringPool.cpp7
-rw-r--r--tools/aapt2/StringPool_test.cpp12
2 files changed, 15 insertions, 4 deletions
diff --git a/tools/aapt2/StringPool.cpp b/tools/aapt2/StringPool.cpp
index b0ce9e1ec947..73a8259a3a87 100644
--- a/tools/aapt2/StringPool.cpp
+++ b/tools/aapt2/StringPool.cpp
@@ -172,9 +172,10 @@ StringPool::Ref StringPool::MakeRef(const StringPiece& str, const Context& conte
StringPool::Ref StringPool::MakeRefImpl(const StringPiece& str, const Context& context,
bool unique) {
if (unique) {
- auto iter = indexed_strings_.find(str);
- if (iter != std::end(indexed_strings_)) {
- return Ref(iter->second);
+ for (auto& indexed_str : indexed_strings_) {
+ if (str == indexed_str.first && context.priority == indexed_str.second->context.priority) {
+ return Ref(indexed_str.second);
+ }
}
}
diff --git a/tools/aapt2/StringPool_test.cpp b/tools/aapt2/StringPool_test.cpp
index 58a03de60f93..5f7d3d6b1d03 100644
--- a/tools/aapt2/StringPool_test.cpp
+++ b/tools/aapt2/StringPool_test.cpp
@@ -61,6 +61,17 @@ TEST(StringPoolTest, DoNotInsertNewDuplicateString) {
EXPECT_THAT(pool.size(), Eq(1u));
}
+TEST(StringPoolTest, DoNotDedupeSameStringDifferentPriority) {
+ StringPool pool;
+
+ StringPool::Ref ref_a = pool.MakeRef("wut", StringPool::Context(1));
+ StringPool::Ref ref_b = pool.MakeRef("wut", StringPool::Context(2));
+
+ EXPECT_THAT(*ref_a, Eq("wut"));
+ EXPECT_THAT(*ref_b, Eq("wut"));
+ EXPECT_THAT(pool.size(), Eq(2u));
+}
+
TEST(StringPoolTest, MaintainInsertionOrderIndex) {
StringPool pool;
@@ -292,7 +303,6 @@ TEST(StringPoolTest, Flatten) {
}
}
-
TEST(StringPoolTest, MaxEncodingLength) {
StdErrDiagnostics diag;
using namespace android; // For NO_ERROR on Windows.