AAPT2: Modified StringPool uniqueness detection #2

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.

The ag/3897499 approach to fix the specified bug was extremely inefficient
and caused hour long builds. This change takes advantage of the multimap
data structure to do lookups efficiently.

Bug: 77862560
Test: Converted apk in listed bug from proto to binary and observed
correct resource ids and correct badging. Also built the Android tree to
check for regressions in build time.

Change-Id: I27a9ee4ffbed8b9ff6f238ad315cdf87b588947c
diff --git a/tools/aapt2/StringPool_test.cpp b/tools/aapt2/StringPool_test.cpp
index 58a03de..4b3afe2 100644
--- a/tools/aapt2/StringPool_test.cpp
+++ b/tools/aapt2/StringPool_test.cpp
@@ -61,6 +61,17 @@
   EXPECT_THAT(pool.size(), Eq(1u));
 }
 
+TEST(StringPoolTest, DoNotDedupeSameStringDifferentPriority) {
+  StringPool pool;
+
+  StringPool::Ref ref_a = pool.MakeRef("wut", StringPool::Context(0x81010001));
+  StringPool::Ref ref_b = pool.MakeRef("wut", StringPool::Context(0x81010002));
+
+  EXPECT_THAT(*ref_a, Eq("wut"));
+  EXPECT_THAT(*ref_b, Eq("wut"));
+  EXPECT_THAT(pool.size(), Eq(2u));
+}
+
 TEST(StringPoolTest, MaintainInsertionOrderIndex) {
   StringPool pool;