summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceParser.cpp
AgeCommit message (Collapse)Author
2020-03-09Merge "Suppress bugprone-use-after-move warnings" am: 100a6f64e5 am: a4f123ba5fAutomerger Merge Worker
Change-Id: Iabb0a0570f64d39844758d4313d009b380aba356
2020-03-06Suppress bugprone-use-after-move warningsChih-Hung Hsieh
Bug: 150783499 Test: WITH_TIDY=1 make Change-Id: Ifdd5d89d2207caba765e8f74e8a86f6b6b4ff609
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
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-05-28Empty attribute values in styles should be stringsRyan Mitchell
In aapt1, if you specified the value of an attribute in a style as an empty string (eg. <item name="my_attr"></item>), the encoded value would be an empty string. In aapt2 currently, @null is encoded instead. This change restores aapt1 behavior. Use @null explicitly if the desired value is to be @null. Bug: 133450400 Test: manual comparison of APK created by aapt1 and aapt2 <attr name="my_attr" format="string|reference" /> <style name="MyName"> <item name="my_attr"></item> </style> $ aapt p -M AndroidManifest.xml -F out1.apk -S res -f $ aapt2 compile --dir res-o compiled.flata $ aapt2 link --manifest AndroidManifest.xml -o out2.apk compiled.flata $ aapt2 dump out2.apk Change-Id: I8aa0ba30379dac0b1229da525abbc5482f40114b
2019-04-29Merge "Fix unknown resource type error message" into qt-devTreeHugger Robot
2019-04-26Fix unknown resource type error messageRyan Mitchell
Instead of printing the tag name, print the type name when the type was unable to be recognized. The type name is initialized to the tag name and changes when a type attribute is defined.. Bug: 37891551 Test: manual Change-Id: I9b0e6a6f2d96a8c5af71fbca8e83c947a8e308bf
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-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-19Merge "Fix seg faul when parsing invalid <plurals>"Ryan Mitchell
2019-02-15Fix seg faul when parsing invalid <plurals>Ryan Mitchell
If the inner element of a <plurals> tag fails to parse, aapt2 will seg fault. Don't do that. Bug: 123423125 Test: manual Change-Id: Iff39fa84073da62d85279683ac3d03b7309bc5e3
2019-02-15Merge "Do not derive source from binary APK"TreeHugger Robot
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-02-07Do not derive source from binary APKRyan Mitchell
When loading the binary APK, do not set the paths of Source structs to the path of the binary APK. This causes the merge_zips step of the build system to fail. Bug: 124082573 Test: vendor/google/build/build_mainline_modules.sh Change-Id: I84b8d43c5b6a5835e7ff6bd579c4eb744e02c20f
2019-01-18Merge "AAPT2: always say which file failed to compile"TreeHugger Robot
2019-01-17AAPT2: always say which file failed to compileIzabela Orlowska
Sometimes AAPT2 doesn't include the path of the file in the error message, or just outputs a warning where an error should be printed (but the overall build still fails without an error message). Let's always include the file path to make it easier for the users to find out the source of the failure. Fixes: 122856772 Test: manual Change-Id: Ibbbfd21b372792e5eaa40278186eb64cdfb0f60e
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-19Merge "Add actor and name parsing for overlayable"Ryan Mitchell
2018-12-17Merge "Fix performance-for-range-copy warnings" am: bc29242288 am: 7adb73f332Chih-Hung Hsieh
am: 2296036a40 Change-Id: Ia99ea6c9633986e68340bc88983d06baa7a1c597
2018-12-17Fix performance-for-range-copy warningsChih-Hung Hsieh
Bug: 30413223 Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,performance* Change-Id: Ie481e88025a7a1f3abde8ff63420d5ccd8577e52
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 Merged-In: I54210bbbd8dad5903cb7100807df977efa394ad5
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-02Merge "AAPT2: Fixed id parsing error" into pi-dev am: f4c089dd90Ryan Mitchell
am: 932c44d329 Change-Id: I661784fcabac19d4d9bae137904b9282d9765d79
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-19Merge "AAPT2: Support id reference chaining from AAPT" into pi-dev am: ↵Ryan Mitchell
247ecfa498 am: e9bbefa7dc Change-Id: Ic40b9e08352e561e21284d72592860b868f6edc1
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-03-27AAPT2: add flag for forcing visibility levelIzabela Orlowska
Test: manual Bug: 72735798 Change-Id: I29480e66384dd2da27e17ab454ac1fe8a033ee3e
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
2018-01-11AAPT2: Allow compatible duplicate AttributesAdam Lesinski
If a resource XML file defines two compatible Attributes, they should be merged without throwing an error. Ex: <declare-styleable> <attr name="conflict" format="string" /> </declare-styleable> <declare-styleable> <attr name="conflict" format="string|reference" /> </declare-styleable> In this case, string|reference and string are the same, so these should merge correctly. Bug: 65699599 Test: make aapt2_tests Test: make AaptBasicTest Change-Id: I7b0f956d2332f7f0b458acd59ca0a606b2cfdf95
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-09-07Merge "AAPT2: Add <overlayable> tag support"Adam Lesinski
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-29Merge "AAPT2: Fixup namespace implementation"Adam Lesinski
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-23AAPT2: Fixup namespace implementationAdam Lesinski
A few pieces were missing in the namespace mangling implementation. Namespace aware libraries now work, along with R class generation. Bug: 64706588 Test: make AaptTestNamespace_App Change-Id: I12f78d6aa909e782c0faf7ceaa36058f2e6c864a
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-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-02Merge "AAPT2: Allow any value type for <item> without format attr" into oc-devAdam Lesinski
am: 1ac325e4d5 Change-Id: I1b1180f2b33a077b2c46a8466c58d83ed618576e
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-30Merge "AAPT2: Fix <add-resource> tag for overlays" into oc-devAdam Lesinski
am: 8255ced3f5 Change-Id: Icc420eea48a8379723c0bc84a5f30c03ac2a2492
2017-05-26AAPT2: Fix <add-resource> tag for overlaysAdam Lesinski
Bug: 38355988 Test: make aapt2_tests Change-Id: Iea8887f55f8ceb2c15bd963405fd132916173c0c