67 Commits

Author SHA1 Message Date
Ryan Mitchell
2e9bec1154 Add staging-public-group to aapt2
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-29 16:33:16 -07:00
Ryan Mitchell
1d008d1d2a Refactor aapt2 tests ResourceTable changes
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
2021-03-29 10:22:10 -07:00
Winson
f56ade365a Actor signature overlayable policy
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-26 15:59:44 -08:00
Winson
62ac8b56a9 Refactor overlayable policy
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-02-26 15:59:43 -08:00
Donald Chai
94e4a01dec Add option to avoid clobbering visibility of <declare-styleable>
"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-07 12:55:52 -08:00
Ryan Mitchell
c1676807f4 Retain parsed attribute type
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-06-06 14:19:26 +00:00
Ryan Mitchell
acde95c3fc No new attributes in declare-styleables when format is not provided
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-23 08:32:30 -07:00
Ryan Mitchell
939df096be Add odm and oem policies
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-04-17 16:07:57 -07:00
Mihai Nita
d1a6521cc3 Fix aapt2 pseudo-translating donottranslate* files
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-29 17:15:18 -07:00
Ryan Mitchell
0f32675909 Do not convert whitespace chars above max char to regular space
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-11 11:00:25 -07:00
Ryan Mitchell
1d358ff5bb Fix aapt2 whitespace diffs from aapt(1)
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-03-06 15:06:49 -08:00
Winson
b2d7f5343d Signature policy for overlayable items
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-14 10:07:13 -08:00
Ryan Mitchell
02d9c1e931 Remove RRO policy product_services
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
2019-01-16 11:47:33 -08:00
Ryan Mitchell
54237ffed4 Add actor and name parsing for overlayable
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-13 16:05:10 -08:00
Ryan Mitchell
1bb1fe068a Refactor policy parsing
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-12-11 13:48:45 -08:00
Ryan Mitchell
e4e989ccba RRO: Added partition policies for overlays
<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-11-06 00:10:26 +00:00
Mårten Kongstad
24c9aa6541 libandroidfw: move ConfigDescription from aapt2 to libandroidfw
This is to allow idmap2 to access ConfigDescription.

Test: libandroidfw_tests
Test: aapt2_tests
Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08 06:50:22 -07:00
Ryan Mitchell
d6ace01c5a Merge "AAPT2: Fix unrecognized CDATA" 2018-06-25 16:10:59 +00:00
Ryan Mitchell
cb76d734fe AAPT2: Fix unrecognized CDATA
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-22 14:06:02 -07:00
Ryan Mitchell
633d796623 AAPT2: Fix raw string parsing
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-06-11 15:57:23 -07:00
Ryan Mitchell
eaf77e1d3a AAPT2: Fixed id parsing error
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-05-01 11:11:55 -07:00
y
9efbbef2e0 AAPT2: Support id reference chaining from AAPT
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-18 11:46:53 -07:00
Ryan Mitchell
9beaa9cfe3 Changed AAPT2 to abide by AAPT resource whitespace triming.
Bug: b/74331008
Test: Created tests in ResourceParser_test.cpp
Change-Id: Id7b387692b795774cd77452ca8cf06a8447bf3be
(cherry picked from commit a04880771254f5169a1fe460ff40b565d9dceb0d)
2018-04-04 15:54:05 +00:00
Adam Lesinski
2eed52ecc0 AAPT2: Fix styled string whitespace processing
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-02-27 11:39:10 -08:00
Adam Lesinski
71be70507d AAPT2: Propagate SPEC_OVERLAYABLE flag to final APK
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-12-18 14:16:02 -08:00
Adam Lesinski
0045116606 AAPT2: Define and Implement AAPT Container Format
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-10-19 12:50:53 -07:00
Adam Lesinski
46c4d72bf0 AAPT2: Add <overlayable> tag support
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-29 11:10:01 -07:00
Adam Lesinski
4ffea04064 AAPT2: Define intermediate compiled XML proto
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-23 11:54:38 -07:00
Adam Lesinski
efeb7af13b AAPT2: Fix windows unicode path issues
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-08-03 17:33:52 -07:00
Adam Lesinski
060b53d028 AAPT2: Ensure style strings are always first in StringPool
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-07-31 17:46:28 -07:00
Adam Lesinski
549e437e14 AAPT2: Iterate over UTF-8 string by codepoints
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-29 18:17:35 -07:00
Adam Lesinski
a45893a5c5 AAPT2: Clean up tests a bit
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-09 14:57:07 -07:00
Adam Lesinski
b9f0548341 AAPT2: Do not interpret %n as a format specifier in string resources
%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-06 20:02:38 +00:00
Adam Lesinski
bab4ef56d7 AAPT2: Allow undefined resources (placeholders)
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-02 16:48:38 -07:00
Adam Lesinski
e597d68d33 AAPT2: Allow any value type for <item> without format attr
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-06-01 17:16:44 -07:00
Adam Lesinski
4488f1c74a AAPT2: Fix <add-resource> tag for overlays
Bug: 38355988
Test: make aapt2_tests
Change-Id: Iea8887f55f8ceb2c15bd963405fd132916173c0c
2017-05-26 17:38:34 -07:00
Adam Lesinski
d5fd76a2ff AAPT2: Respect format attr in <array> resource
Bug: 38152130
Test: make aapt2_tests
Change-Id: I84f352afb1a8fd2f329354f789aaa36c5ef88e47
2017-05-16 12:18:53 -07:00
Adam Lesinski
8049f3da71 AAPT2: Fix pseudolocalization (again)
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-31 18:30:20 -07:00
Adam Lesinski
8f7c550e20 AAPT2: Fix Plural::Equals() method
Test: make aapt2_tests
Bug: 35902437
Change-Id: I8797f89af58876f891f0b0c5cce85fd7781c4e24
2017-03-02 17:45:51 -08:00
Adam Lesinski
7542162cb1 AAPT2: Fix pseudolocalization to respect <xliff:g>
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-08 06:23:45 -08:00
Adam Lesinski
86d67df8d5 AAPT2: Support CtsContentTestCases build
- 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-02-01 15:28:23 -08:00
Adam Lesinski
d5083f6f6b Move StringPiece to libandroidfw
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
2017-01-17 18:55:51 -08:00
Adam Lesinski
ce5e56e243 AAPT2: Rename to match new style
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-26 19:30:23 -07:00
Adam Lesinski
cacb28f2d6 Use Google3 style guide with .clang-format
Test: style change only, builds ok
Change-Id: I885180e24cb2e7b58cfb4967c3bcb40058ce4078
2016-10-19 12:18:14 -07:00
Adam Lesinski
8c3f31f022 AAPT2: Fix issue with styled string indices
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-09-07 13:45:13 -07:00
Adam Lesinski
58a20a6482 AAPT2: Change accepted notation for resource names in tests
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-25 17:56:58 -07:00
Adam Lesinski
d0f116b619 AAPT2: Remove usage of u16string
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-07-13 17:45:28 -07:00
Adam Lesinski
e4bb9eb5af AAPT2: Introduce notion of 'product' to ResourceTable
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-02-12 22:21:48 -08:00
Adam Lesinski
52364f7ae3 AAPT2: Variety of small fixes to get the build working
- Add option to rename package in AndroidManifest.xml
- Support default versionName and versionCode
- Accept True and False as valid booleans

Change-Id: I400e350b9dcd0fd1c197d1929144299c7823617d
2016-01-13 18:48:24 -08:00
Adam Lesinski
7751afc796 AAPT2: Fix product support
Previously the default product wasn't tried if 'default' wasn't specified on the command line.
Also adds support for multiple products.

Change-Id: I1e4872b34bb8d609b6444841a4e7e4dbb3bbb76b
2016-01-06 16:18:40 -08:00