Loading include/androidfw/AttributeFinder.h +8 −3 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ private: void jumpToClosestAttribute(uint32_t packageId); void markCurrentPackageId(uint32_t packageId); bool mFirstTime; Iterator mBegin; Iterator mEnd; Iterator mCurrent; Loading @@ -81,7 +82,8 @@ private: template <typename Derived, typename Iterator> inline BackTrackingAttributeFinder<Derived, Iterator>::BackTrackingAttributeFinder(const Iterator& begin, const Iterator& end) : mBegin(begin) : mFirstTime(true) , mBegin(begin) , mEnd(end) , mCurrent(begin) , mLargest(begin) Loading Loading @@ -145,8 +147,11 @@ Iterator BackTrackingAttributeFinder<Derived, Iterator>::find(uint32_t attr) { return mEnd; } if (mCurrentAttr == 0) { // One-time initialization. if (mFirstTime) { // One-time initialization. We do this here instead of the constructor // because the derived class we access in getAttribute() may not be // fully constructed. mFirstTime = false; mCurrentAttr = static_cast<const Derived*>(this)->getAttribute(mBegin); mLastPackageId = getPackage(mCurrentAttr); markCurrentPackageId(mLastPackageId); Loading libs/androidfw/tests/AttributeFinder_test.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ static const uint32_t packageUnsortedAttributes[] = { 0x01010002, 0x01010004, 0x7f010001 }; static const uint32_t singlePackageAttributes[] = { 0x7f010007, 0x7f01000a, 0x7f01000d, 0x00000000 }; TEST(AttributeFinderTest, IteratesSequentially) { const int end = sizeof(sortedAttributes) / sizeof(*sortedAttributes); MockAttributeFinder finder(sortedAttributes, end); Loading Loading @@ -109,3 +113,16 @@ TEST(AttributeFinderTest, FindAttributesInPackageUnsortedAttributeList) { EXPECT_EQ(1, finder.find(0x02010010)); EXPECT_EQ(6, finder.find(0x7f010001)); } TEST(AttributeFinderTest, FindAttributesInSinglePackageAttributeList) { const int end = sizeof(singlePackageAttributes) / sizeof(*singlePackageAttributes); MockAttributeFinder finder(singlePackageAttributes, end); EXPECT_EQ(end, finder.find(0x010100f4)); EXPECT_EQ(end, finder.find(0x010100f5)); EXPECT_EQ(end, finder.find(0x010100f6)); EXPECT_EQ(end, finder.find(0x010100f7)); EXPECT_EQ(end, finder.find(0x010100f8)); EXPECT_EQ(end, finder.find(0x010100fa)); EXPECT_EQ(0, finder.find(0x7f010007)); } Loading
include/androidfw/AttributeFinder.h +8 −3 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ private: void jumpToClosestAttribute(uint32_t packageId); void markCurrentPackageId(uint32_t packageId); bool mFirstTime; Iterator mBegin; Iterator mEnd; Iterator mCurrent; Loading @@ -81,7 +82,8 @@ private: template <typename Derived, typename Iterator> inline BackTrackingAttributeFinder<Derived, Iterator>::BackTrackingAttributeFinder(const Iterator& begin, const Iterator& end) : mBegin(begin) : mFirstTime(true) , mBegin(begin) , mEnd(end) , mCurrent(begin) , mLargest(begin) Loading Loading @@ -145,8 +147,11 @@ Iterator BackTrackingAttributeFinder<Derived, Iterator>::find(uint32_t attr) { return mEnd; } if (mCurrentAttr == 0) { // One-time initialization. if (mFirstTime) { // One-time initialization. We do this here instead of the constructor // because the derived class we access in getAttribute() may not be // fully constructed. mFirstTime = false; mCurrentAttr = static_cast<const Derived*>(this)->getAttribute(mBegin); mLastPackageId = getPackage(mCurrentAttr); markCurrentPackageId(mLastPackageId); Loading
libs/androidfw/tests/AttributeFinder_test.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ static const uint32_t packageUnsortedAttributes[] = { 0x01010002, 0x01010004, 0x7f010001 }; static const uint32_t singlePackageAttributes[] = { 0x7f010007, 0x7f01000a, 0x7f01000d, 0x00000000 }; TEST(AttributeFinderTest, IteratesSequentially) { const int end = sizeof(sortedAttributes) / sizeof(*sortedAttributes); MockAttributeFinder finder(sortedAttributes, end); Loading Loading @@ -109,3 +113,16 @@ TEST(AttributeFinderTest, FindAttributesInPackageUnsortedAttributeList) { EXPECT_EQ(1, finder.find(0x02010010)); EXPECT_EQ(6, finder.find(0x7f010001)); } TEST(AttributeFinderTest, FindAttributesInSinglePackageAttributeList) { const int end = sizeof(singlePackageAttributes) / sizeof(*singlePackageAttributes); MockAttributeFinder finder(singlePackageAttributes, end); EXPECT_EQ(end, finder.find(0x010100f4)); EXPECT_EQ(end, finder.find(0x010100f5)); EXPECT_EQ(end, finder.find(0x010100f6)); EXPECT_EQ(end, finder.find(0x010100f7)); EXPECT_EQ(end, finder.find(0x010100f8)); EXPECT_EQ(end, finder.find(0x010100fa)); EXPECT_EQ(0, finder.find(0x7f010007)); }