summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-06-30 15:59:39 +0100
committerNarayan Kamath <narayan@google.com>2014-06-30 16:20:27 +0100
commitb2975916224caecfc2fbb84e71ebd625ce6eeb1c (patch)
treef60365e0cd6f2b4f2b508d2b3ed11099338827d8 /libs
parent7165bd6d7496159b426f072bdf13adfffc917a24 (diff)
downloadframeworks_base-b2975916224caecfc2fbb84e71ebd625ce6eeb1c.zip
frameworks_base-b2975916224caecfc2fbb84e71ebd625ce6eeb1c.tar.gz
frameworks_base-b2975916224caecfc2fbb84e71ebd625ce6eeb1c.tar.bz2
Fix packing of values at offset 16.
Our bitmask for setting the highest bit to 0 for 0b11100000 (0xef) instead of 0b01111111 (0x7f) so we would end up setting bit 5 of each offset to zero. Fix this and expand test coverage by adding a fake language (tgp) that has this bit set in both its bytes. This issue was discovered while adding CTS tests for "tgl". Change-Id: Ibb6de03000951c907c252049771039ab7466187a
Diffstat (limited to 'libs')
-rw-r--r--libs/androidfw/ResourceTypes.cpp6
-rw-r--r--libs/androidfw/tests/ResourceTypes_test.cpp24
2 files changed, 27 insertions, 3 deletions
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index 2c828c1..2f3b1f7 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -1597,9 +1597,9 @@ void ResTable_config::copyFromDeviceNoSwap(const ResTable_config& o) {
out[0] = in[0];
out[1] = in[1];
} else {
- uint8_t first = (in[0] - base) & 0x00ef;
- uint8_t second = (in[1] - base) & 0x00ef;
- uint8_t third = (in[2] - base) & 0x00ef;
+ uint8_t first = (in[0] - base) & 0x007f;
+ uint8_t second = (in[1] - base) & 0x007f;
+ uint8_t third = (in[2] - base) & 0x007f;
out[0] = (0x80 | (third << 2) | (second >> 3));
out[1] = ((second << 5) | first);
diff --git a/libs/androidfw/tests/ResourceTypes_test.cpp b/libs/androidfw/tests/ResourceTypes_test.cpp
index 4888b4a..139f868 100644
--- a/libs/androidfw/tests/ResourceTypes_test.cpp
+++ b/libs/androidfw/tests/ResourceTypes_test.cpp
@@ -75,6 +75,30 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguage) {
EXPECT_EQ(0, out[3]);
}
+TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguageAtOffset16) {
+ ResTable_config config;
+ config.packLanguage("tgp");
+
+ // We had a bug where we would accidentally mask
+ // the 5th bit of both bytes
+ //
+ // packed[0] = 1011 1100
+ // packed[1] = 1101 0011
+ //
+ // which is equivalent to:
+ // 1 [0] [1] [2]
+ // 1-01111-00110-10011
+ EXPECT_EQ(0xbc, config.language[0]);
+ EXPECT_EQ(0xd3, config.language[1]);
+
+ char out[4] = { 1, 1, 1, 1};
+ config.unpackLanguage(out);
+ EXPECT_EQ('t', out[0]);
+ EXPECT_EQ('g', out[1]);
+ EXPECT_EQ('p', out[2]);
+ EXPECT_EQ(0, out[3]);
+}
+
TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterRegion) {
ResTable_config config;
config.packRegion("419");