summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceParser_test.cpp
AgeCommit message (Collapse)Author
2021-04-28Add <macro> tag to aapt2Ryan Mitchell
AAPT2 Macros are compile-time resources definitions that are expanded when referenced during the link phase. A macro must be defined in the res/values.xml directory. A macro definition for a macro named "foo" looks like the following: <macro name="foo">contents</macro> When "@macro/foo" is used in the res/values directory or in a compiled XML file, the contents of the macro replace the macro reference and then the substituted contents are compiled and linked. If the macro contents reference xml namespaces from its original definition, the namespaces of the original macro definition will be used to determine which package is being referenced. Macros can be used anywhere resources can be referenced using the @package:type/entry syntax. Macros are not included in the final resource table or the R.java since they are not actual resources. Bug: 175616308 Test: aapt2_tests Change-Id: I48b29ab6564357b32b4b4e32bff7ef06036382bc
2021-03-29Add staging-public-group to aapt2Ryan Mitchell
staging-public-group is a tag for putting resources that have been added during platform development, but have not yet been finalized, into a separate resource id namespace. R.java fields of staged resources are non-final, so when the SDK is finalized, applications using the android R.java will automatically use the new finalized resource id without having to recompile. Staged resources can exist either in the same type id as the type's non-staged counterpart or in a separate type id. Multiple staging-public-group tags each with a different type id can exist simultaneously, which allows for multiple versions of the platform to be developed at once. Bug: 183411093 Test: aapt2_tests Change-Id: Ibb6c84c3626751e33c6097f35a03e306bb85616a
2021-03-29Refactor aapt2 tests ResourceTable changesRyan Mitchell
This changes refactors tests to use the NewResourceBuilder class that makes it easier to construct resource entries. Bug: 183102797 Test: aapt2_tests Change-Id: I851f9fb99a003769f8df8c1876997eee0864822a
2020-02-26Actor signature overlayable policyWinson
There are cases where an app can ship overlays for itself, but the "signature" policy as described would open up a vulnerability by allowing the system actor to create and sign any arbitrary overlay that will apply to the target. To prevent this, redefine "signature" as target package only, and introduce "actor" for checking against the actor signature. Any app that wishes to use both can include both policies. Bug: 130563563 Test: m aapt2_tests idmapt2_tests and run from host test output Test: atest libandroidfw_tests Change-Id: I1c583a5b37f4abbeb18fc6a35c502377d8977a41
2020-02-26Refactor overlayable policyWinson
To make it easier to add the actor policy in a follow up CL, move most of the policy handling to a central location. The strings and transformation between strings and flags is now handled in libidmap2policies, with libandroidfw containing the single source of policy flags. This also extracts all the test resource IDs into an R.h so they can be swapped without having to edit a dozen files each time. Bug: 130563563 Test: m aapt2_tests idmapt2_tests and run from host test output Test: atest libandroidfw_tests Change-Id: Ie533c9cebf938215df7586f00c38763ae467e606
2020-01-07Add option to avoid clobbering visibility of <declare-styleable>Donald Chai
"aapt2 compile" marks styleables as public instead of preserving information from <public/> or --visibility options. This behavior can now be disabled via --preserve-visibility-of-styleables. Bug: 146649511 Change-Id: Ifb8ab396573d1393df737a59625e79e9cf2494a7 Tested: aapt2_tests
2019-06-06Retain parsed attribute typeRyan Mitchell
If the value of an attribute enum is defined as a hexadecimal integer, flatten uses of the attribute as with the android::Res_value::TYPE_INT_HEX type. This change adds a "type" field to pb::Attribute::Symbol, which if left unset, will have a default value of android::Res_value::TYPE_INT_DEC when deserialized by aapt2. Bug: 124474141 Test: aapt2_tests and manual compilation of files and inspection using `aapt2 dump chunks` Change-Id: Ibf12394284fdbe3a8047f7ecf4fe68517dfc3abb
2019-04-23No new attributes in declare-styleables when format is not providedRyan Mitchell
AAPT does not allow for attributes declared in declare-styleables that do not have a format to create new attribute resources. AAPT2 does and should not. Bug: 131100106 Test: aapt2_tests Change-Id: Id00884dc9ed939672df90f670a7915d4b6d232c1
2019-04-17Add odm and oem policiesRyan Mitchell
This change adds parsing, encoding, and validating of odm and oem overlayable policies to aapt2, libandroidfw, and idmap2. Bug: 121033532 Test: aapt2_tests, idmap2_tests Change-Id: Ifc0d4b6c9f9c37e06b2988abade69dbb277c50c2
2019-03-29Fix aapt2 pseudo-translating donottranslate* filesMihai Nita
Bug: 126423638 Test: After building android doing this in the 'out' folder: Test: Test: ./soong/host/linux-x86/bin/aapt d --values resources \ Test: ./target/product/sailfish/system/product/priv-app/SystemUIGoogle/SystemUIGoogle.apk \ Test: | less Test: Test: search for `system_ui_aod_date_pattern` in the output, found this: Test: (string8) "[éééḾḾḾð one two]" Test: (string8) "<U+200F><U+202E>eeeMMMd<U+202C><U+200F>" Test: (the en-XA and ar-XB pseudo-translated versions of the string) Test: Test: After the fix and rebuild the dump only finds the original English string ("eeeMMMd") Test: Also flashed the image, switched to en-XA, and left the phone around for more than 24 hours. Change-Id: I2fb7c5b5ee7d3d3200410593346682ed16559056
2019-03-11Do not convert whitespace chars above max char to regular spaceRyan Mitchell
Using isspace and iswspace on characters above the maximum char value is undefined. This change makes aapt2 use isspace like aapt and only trims whitespace characters at or below the maximum char value like aapt2. Bug: 121017795 Test: aapt2_tests Change-Id: I015e4b77f0ff53e409e880fcf9ae104ba3444d1a
2019-03-06Fix aapt2 whitespace diffs from aapt(1)Ryan Mitchell
CDATA blocks were being processed differently in aapt2 so this change fixes aapt2 to not treat cdata blocks differently and still trime whitespace. Also, aapt did not process escapes when compiling xml files. This change removes over-processing of xml text nodes. All test strings are what aapt(1) would output. Test: aapt2_tests Bug: 124470332 Change-Id: I90ee0c1e5e9208f8a5c60cee93e3ba02712c9b2c
2019-02-14Signature policy for overlayable itemsWinson
Add encoding/decoding of new policy for overlays. Signature enforces that an overlay package is signed with the same key as the actor of the target resource, so that an overlay can be installed by the user as a normal app but restricted to those built by the author of the actor (which can be the same as the target). This also enforces that a valid policy is specified. This doesn't implement the actors nor the signature check. Bug: 119402606 Test: ResourceParserTest ParseOverlayablePolicy Test: ProtoSerializerTest SerializeAndDeserializeOverlayable Test: aapt2_tests Change-Id: I8495ad790c2ebd51759bc6eba81149680c209475
2019-01-16Remove RRO policy product_servicesRyan Mitchell
Since Q will no longer have a product_services partition, remove instances of the product_services policy across aapt2, androidfw, and idmap2. Bug:122745343 Test: aapt2_tests and libandroidfw_tests Change-Id: I97c223a0bf5a2eab95811e5f738b44af6335e0ea
2018-12-13Add actor and name parsing for overlayableRyan Mitchell
Add parsing of two overlayable attributes: name : The unnique identifying name of the overlayable set of resources actor: The component responsible for enabling and disabling overlays targeting the specified set of resources Bug: 110869880 Bug: 119390855 Test: m -j aapt2_tests Change-Id: Id42463e2b92b69034fb39cd29bc8606affb61ba7
2018-12-11Refactor policy parsingRyan Mitchell
This change removes the ability for an overlayable resource to be defined in multiple policy blocks within the same overlayable. This change also changes aapt2 to use a bit mask to keep track of the parsed policies. Bug: 110869880 Bug: 120298168 Test: aapt2_tests Change-Id: Ie26cd913f94a16c0b312f222bccfa48f62feceaa
2018-11-06RRO: Added partition policies for overlaysRyan Mitchell
<overlayable> tags can now have policy elements that indicate which partition the overlay apk must reside on in order to be allowed to overlay a resource. This change only adds parsing of <policy> and encoding of policy in the proto ResourceTable. A later change will add the encoding of policy and overlayable in the binary APK. <overlayable> <policy type="system|vendor|product|product_services|public" > <item type="string" name="oof" /> </policy> </overlayable> Bug: 110869880 Test: make aapt2_tests Change-Id: I8d4ed7b0e01f981149c6e3190af1681073b79b03
2018-10-08libandroidfw: move ConfigDescription from aapt2 to libandroidfwMårten Kongstad
This is to allow idmap2 to access ConfigDescription. Test: libandroidfw_tests Test: aapt2_tests Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-06-25Merge "AAPT2: Fix unrecognized CDATA"Ryan Mitchell
2018-06-22AAPT2: Fix unrecognized CDATARyan Mitchell
This change adds support for resources that have CDATA blocks within their values. The blocks should allow any character to occur without being escaped. It also should not effect the current state of quote processing. Bug: 80326349 Test: Created tests in aapt2_tests Change-Id: Ie1a00e50cffc877e2eb5f788f8d7a1bda839c0cf
2018-06-11AAPT2: Fix raw string parsingRyan Mitchell
Trim whitespace of raw strings when parsing xml values. This change trims the whitespace of style items. For example: <item name="viewInflaterClass">com.helloworld.Inflater </item> This will be trimmed to not include a trailing whitespace. Bug: 109666819 Test: aapt2_tests Change-Id: I0c1fbb3abdc7e609316c92e59ccaf0573b07e5a7
2018-05-01AAPT2: Fixed id parsing errorRyan Mitchell
A previous change, editied the logic for parsing ids to allow for ids to reference other ids. This change though caused a regression that made ids in the form '<id name="name" />' cease to parse. This changes fixes that regression. Bug: 78513618 Test: Updated tests in ResourceParser_test.cpp Change-Id: I3608bb764464e951a50910be55e199c6ec575d09
2018-04-18AAPT2: Support id reference chaining from AAPTy
AAPT would allow for ids to be declared in the form: <item name="name" type="id>@id/other</item> @id/name should hold a reference to @id/other. When getResources().getValue() is called on R.id.name with resolveRefs enabled, the resuling reference should be R.id.other. Bug: 69445910 Test: Created tests for correct parsing of id references and correct resolving of deep references Change-Id: Id1feb37b2565c213dc6a19b4c401906260d7fc14
2018-04-04Changed AAPT2 to abide by AAPT resource whitespace triming.Ryan Mitchell
Bug: b/74331008 Test: Created tests in ResourceParser_test.cpp Change-Id: Id7b387692b795774cd77452ca8cf06a8447bf3be (cherry picked from commit a04880771254f5169a1fe460ff40b565d9dceb0d)
2018-02-27AAPT2: Fix styled string whitespace processingAdam Lesinski
Change styled string whitespace processing to be like AAPT's was. Main changes: - whitespace around tags is preserved. - tags start exactly where they are supposed to, not off by one. Bug: 72406283 Test: make aapt2_tests Change-Id: I4d12728c493efd8c978e2e3d2718b56534ff52ef
2017-12-18AAPT2: Propagate SPEC_OVERLAYABLE flag to final APKAdam Lesinski
Resources can be marked as overlayable, which means they can be overlaid by runtime resource overlays. This change propagates this state to the final resource table that is installed on device. Future work: - Have the idmap tool respect the overlayable state and ignore entries that overlay anything else. Bug: 64980941 Test: make aapt2_tests Change-Id: Id45b1e141a281be2ee32a4ac3096fcf1114d523b
2017-10-19AAPT2: Define and Implement AAPT Container FormatAdam Lesinski
AAPT Container Format (.apc) is a simple container that enumerates the various intermediate files that AAPT2 generates during the compile phase. The format is defined in formats.md. For now, continue using the .flat extension for the container file, and keep making use of the .flata zip for storing multiple files. This will allow easier integration with existing build systems and allow the evolution of the APC format to better handle arbitrarily large files. Test: make aapt2_tests Change-Id: Id7216e5b76316bdd683f0fa4eaf2d2da273ba815
2017-08-29AAPT2: Add <overlayable> tag supportAdam Lesinski
This doesn't actually do anything yet, but makes sure it is not a syntax error and allows teams to start marking their resources as overlayable. The syntax form marking a set of resources as overlayable looks like: <overlayable policy="system"> <item type="string" name="foo" /> <item type="style" name="bar" /> </overlayable> Currently, the only supported policy is "system", meaning only the system will be able to overlay the resources. Leaving out the policy attribute defaults to "system". Bug: 64980941 Test: make aapt2_tests Change-Id: Ied7a9ddae87a4a0af6a0f4d1c213bfce8a0ed612
2017-08-23AAPT2: Define intermediate compiled XML protoAdam Lesinski
This proto format is meant to encapsulate more information that is specific to Android and allows for easier validation and manipulation across tools. Test: make aapt2_tests Change-Id: I13bc34a460671fc0a36246be0d287a3d37d244d6
2017-08-03AAPT2: Fix windows unicode path issuesAdam Lesinski
Mingw64 was being difficult, so instead of defining a wmain entrypoint, the command line parameters are parsed manually using built-in Windows methods that support Unicode. The results are converted to UTF8 and handled just like the rest of the linux/mac version of the code. This also removes dependencies on std::istream in favour of a FileInputStream which calls the appropriate unicode version of open to read a file. No speed regressions found on Linux or MacOS. Bug: 62336414 Bug: 63830502 Test: manual Change-Id: I597da51e33729ed1b98bf246e7e773337fd3fee8
2017-07-31AAPT2: Ensure style strings are always first in StringPoolAdam Lesinski
Move the styled strings to a separate section of the StringPool so that sorting can never mess up the order of Styles. Bug: 63570514 Test: make aapt2_tests Change-Id: Id2ce1355b92be1bb31ce0daa7e54ae9b5b6c2ffe
2017-06-29AAPT2: Iterate over UTF-8 string by codepointsAdam Lesinski
Iterating over a UTF-8 string by codepoints ensures that unicode characters do not get sliced. Otherwise the resulting string could contain malformed characters. Bug: 62839202 Test: make aapt2_tests Change-Id: Ia0c44fbceb7dcfa11e77a1a77011da0f5466e342
2017-06-09AAPT2: Clean up tests a bitAdam Lesinski
Since the latest gtest has fixed support for explicit bool operators, remvoe AAPT_ASSERT_* and AAPT_EXPECT_*. Also switch to use NotNull() matchers, which are more legible. Test: make aapt2_tests Change-Id: Idce199ca9d567d70f7aae275fee15e04bb914c9e
2017-06-06AAPT2: Do not interpret %n as a format specifier in string resourcesAdam Lesinski
%n is a special value marking a platform independent newline and is not to be considered a format argument. Bug: 37132275 Test: make aapt2_tests Change-Id: I806521e44afe20004344dee9f18ecee6cc7086ea
2017-06-02AAPT2: Allow undefined resources (placeholders)Adam Lesinski
A resource defined like so: <item type="drawable" name="foo" /> should be assigned the value @null. The only exception is for <string> resources, which are given the empty string value (since <string></string> is ambiguous). The decision to use "" is based off the fact that old AAPT used to assign "" to all undefined resources, even non-string ones. Bug: 38425050 Test: make aapt2_tests Change-Id: Ib3e0f6f83d16ddd8b279c9fd44a07a37867b85e9
2017-06-01AAPT2: Allow any value type for <item> without format attrAdam Lesinski
TO bring AAPT2 behavior in-line with AAPT, <item> has a default format of "any", and only becomes restricted with an explicit format attribute. Bug: 62260121 Test: make aapt2_tests Change-Id: Ife416f520e6c2710bb30e3ba3f2d4463794bfa06
2017-05-26AAPT2: Fix <add-resource> tag for overlaysAdam Lesinski
Bug: 38355988 Test: make aapt2_tests Change-Id: Iea8887f55f8ceb2c15bd963405fd132916173c0c
2017-05-16AAPT2: Respect format attr in <array> resourceAdam Lesinski
Bug: 38152130 Test: make aapt2_tests Change-Id: I84f352afb1a8fd2f329354f789aaa36c5ef88e47
2017-03-31AAPT2: Fix pseudolocalization (again)Adam Lesinski
Pseudolocalization didn't properly handle spans in strings like "<small><small>Hello</small></small>". The spans would be identical and when doing range checks only one of them would be updated. Switched to a more robust way of extracting the relevant chunks of a styled string. This uses a stack, which is more in line with the real representation in XML. Bug: 34088357 Test: make aapt2_tests Change-Id: Ia4e4501713e688c96a89e26e4e2b1384f4cd3889
2017-03-02AAPT2: Fix Plural::Equals() methodAdam Lesinski
Test: make aapt2_tests Bug: 35902437 Change-Id: I8797f89af58876f891f0b0c5cce85fd7781c4e24
2017-02-08AAPT2: Fix pseudolocalization to respect <xliff:g>Adam Lesinski
The XLIFF 'g' tag specifies content that should NOT be translated. AAPT2's pseudolocalization process should respect it. Bug:34064599 Test: make libandroidfw_tests Change-Id: Ice437d7f0ff246730ee04896fd035e2d846148fb
2017-02-01AAPT2: Support CtsContentTestCases buildAdam Lesinski
- Add <feature-group> to ManifestFixer. - Support <meta-data> in <instrumentation> - Add support for <bag> and type="configVarying". Some CTS tests use this old notation, we need to support it (even though configVarying isn't anything supported by the framework convention). Change-Id: I6946fa633ce513ea8437c1496db883cf27dcf6de Test: make aapt2_tests
2017-01-17Move StringPiece to libandroidfwAdam Lesinski
libandroidfw needs to make use of StringPiece, so move it to libandroidfw and update all code referencing StringPiece in aapt2. Test: make libandroidfw_tests libaapt2_tests Change-Id: I68d7f0fc7c651b048d9d1f5e7971f10ef5349fa1
2016-10-26AAPT2: Rename to match new styleAdam Lesinski
Use Google3 naming style to match new projects' and open source google projects' style. Preferred to do this in a massive CL so as to avoid style inconsistencies that plague legacy code bases. This is a relatively NEW code base, may as well keep it up to date. Test: name/style refactor - existing tests pass Change-Id: Ie80ecb78d46ec53efdfca2336bb57d96cbb7fb87
2016-10-19Use Google3 style guide with .clang-formatAdam Lesinski
Test: style change only, builds ok Change-Id: I885180e24cb2e7b58cfb4967c3bcb40058ce4078
2016-09-07AAPT2: Fix issue with styled string indicesAdam Lesinski
Styled strings use spans to denote which part is styled (<b>, <i>, etc). Spans are simply a range of indices into the original string. In Java, we use String and its internal representation, meaning we must encode the indices using UTF16 lengths. When the internal AAPT2 representation of strings switched to UTF8, the indices also began to index into the UTF8 string. This change reverts the indices to use UTF16 lengths. Bug:31170115 Change-Id: I07b8b5b67d2542c7e0a855b601cdbd3ac4ebffb0
2016-07-25AAPT2: Change accepted notation for resource names in testsAdam Lesinski
Previously the way to name resources in tests was to use reference notation (@[package:][type/]name). Now we use name notation (no @). Change-Id: I68f0a36562d89cc78c582d128f370d9556c58707
2016-07-13AAPT2: Remove usage of u16stringAdam Lesinski
For legacy reasons, we kept around the use of UTF-16 internally in AAPT2. We don't need this and this CL removes all instances of std::u16string and StringPiece16. The only places still needed are when interacting with the ResTable APIs that only operate in UTF16. Change-Id: I492475b84bb9014fa13bf992cff447ee7a5fe588
2016-02-12AAPT2: Introduce notion of 'product' to ResourceTableAdam Lesinski
This allows us to preserve the various product definitions during the compile phase, and allows us to select the product in the link phase. This allows compiled files to remain product-independent, so that they do not need to be recompiled when switching targets. Bug:25958912 Change-Id: Iaa7eed25c834b67a39cdc9be43613e8b5ab6cdd7
2016-01-13AAPT2: Variety of small fixes to get the build workingAdam Lesinski
- Add option to rename package in AndroidManifest.xml - Support default versionName and versionCode - Accept True and False as valid booleans Change-Id: I400e350b9dcd0fd1c197d1929144299c7823617d