77 Commits

Author SHA1 Message Date
Ryan Mitchell
2ec8e1b71f Add <staging-public-group-final> to aapt2 (2/2)
Fixes BinaryResourceParser loading of alias chunk and makes changes
that did not get committed in 2fedba9a32d9e92344eaf6e9faf5b43e1bc2ae70.

Bug: 183411356
Test: aapt2_test
Change-Id: Ieff9166100019f38ddcfe900014709b15db24e43
2021-05-11 08:28:00 -07:00
Ryan Mitchell
2fedba9a32 Add <staging-public-group-final> to aapt2
To allow apps that compiled against a pre-release SDK to continue
working for a period of time after API finalization, a new tag,
<staging-public-group-final>, has been added to aapt2.

When finalizing the framework resource API, converting
<staging-public-group> tags to <staging-public-group-final> will
cause aapt2 to generate the resource table so that there is a resource
entry for the old non-finalized (staged) resource ID and another entry
for the finalized resource ID of newly finalized resources. This allows
an application that compiled against the pre-release SDK to continue
resolving resources using pre-release resource IDs.

All references to pre-release resource IDs will be rewritten to their
finalized resource IDs through the information stored in the new staged
alias chunk. This allows applications compiled against
<staging-public-group> resources to use the newly finalized
resource ID without re-compilation.

When an application is re-compiled against the SDK with
<staging-public-group-final> tags, the application will use the
finalized resource IDs.

This change limits the use of the alias chunk to the framework for S.

Bug: 183411356
Test: aapt2_test
Change-Id: Iba1c3033c3c2f32de8e4a19b58d3921c971092c4
2021-05-10 17:22:33 -07:00
Ryan Mitchell
326e35ffaf Add <macro> tag to aapt2
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-04-28 14:58:23 -07:00
Ryan Mitchell
31031a91f1 Merge "Aapt2 ValueTransformer" into sc-dev 2021-04-21 17:44:55 +00:00
Ryan Mitchell
efcdb95fa7 Aapt2 ValueTransformer
For future macro support, aapt2 must be able to convert Reference
values into other Value types. Currently a DescendingValueVisitor is
used to visit all of the References in a ResourceTable or a compiled
XML file to set their resource ids during the link phase. This was fine
since we were only mutating the resource id of the visited Reference.

A macro may reference a String, BinaryPrimitive, or any other Item
type. During the link phase, we will need to transform references to
macros into the values of the macros.

The only parameter in the methods of the ValueVisitor interface is a
raw pointer to the type being visited. The visitor interface does not
support reassigning the visited type to a different type.

ValueTransformer is a new interface for consuming a Value type and
transforming it into a compatible Value type. This change refactors
Value::Clone to use this interface.

Bug: 175616308
Test: aapt2_tests
Change-Id: Ic1b9d718b932c208764114cd9c74d880e189ccb0
2021-04-21 08:32:30 -07:00
Ryan Mitchell
ca3b4f7633 Use staging-public-group in framework SDK
To make S finalization easier, this changes the framework SDK so that
apps linking against it will be able to continue working as expected
after the first phase of SDK finalization.

During the first phase of SDK finalization, the resource ids of
resources that have not been removed are finalized.
staging-public-group tags are converted to staging-public-group-final
tags in order to encode into the framework what the staged resource id
of a finalized resource was. When an app recompiles, it will use the
finalized resource id. Then after all apps recompile, phase 2 of
finalization begins, in which the staging-public-group-final tags are
removed so apps can no longer use the staged resource ids.

Apps that link against the SDK (provided they are using a recent
version of aapt) will encode references to staged resources as
TYPE_DYNAMIC_REFERENCE and TYPE_DYNAMIC_ATTRIBUTE. The values of R
fields for staged resources are defined out-of-line to prevent them
from being inlined into apps linking agsint the SDK. This allows the
resource ids to change during phase 1 of API finalization.

Bug: 183413192
Test: `aapt2 diff` and resource ids stayed the same
Test: `aapt2 dump` of framework-res.apk and observe staged resources
Change-Id: Ie2275c608297a5f63dde8b1cf795415112cbcc24
2021-03-31 23:04:57 -07:00
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
Ryan Mitchell
9634efb6f4 Prepare aapt2 for multiple ids per type
For the SDK finalization changes, aapt2 must be able to handle
resources of the same type having different type ids. The
ResourceTable data structure currently stores package ids and type ids
on ResourceTablePackage and ResourceTableType respectively. This
prevents resource entries of the same type from having different type
ids without having to create another ResourceTableType structure.

JavaClassGenerator assumes each type only appears once in the
ResourceTable and it would need to dedupe the types to ensure one class
containing all the resource types ids is generated. TableFlattener on
the other hand needs a separate ResourceTableType for each type/id
combination so that the types are flattened into separate
ResTable_types.

This change simplifies aapt2's ResourceTable data structure:
- Resource ids are stored exclusively on ResourceEntry structures
  meaning multiple entries can have different type ids while being
  stored in the same ResourceTableType. Classes like JavaClassGenerator
  can simply iterate over a type to see all the resources of the type
  regardless of what their type id is.

- ResourceTable::GetPartitionedView() retrieves a list of resources
  sorted and partitioned by package id, type id, and entry id. Classes
  like TableFlattener can use this view to get separate
  ResourceTavleTypes for each different type id that a type has.

These changes will also make it easy to have a resource span multiple
type ids if it exhausts all of the entry ids in one type id.

The new NewResourcesBuilder replaces the numerous setter methods on
ResourceTable.

Bug: 183102797
Test: aapt2_tests
Change-Id: I60dbcb24143bb958333899cafa7d41faa226d203
2021-03-29 10:22:08 -07:00
Ryan Mitchell
5855de7ed6 Use R field directly for shared lib styleable attrs
If a shared library exposes an attribute and a client uses the
attribute in its own styleable, the value of the lib attribute
resource id in the client styleable must be fixed with the correct
package id at runtime. Since the client will not have an
onResourcesLoaded to call, the client should directly reference the
attribute resource field in its styleable.

Bug: 147674078
Test: aapt2_tests
Change-Id: I8e64bb2d3165a7072e2604fe1730b248545978f4
2021-02-24 15:57:34 -08:00
Ryan Mitchell
db21f09a8e Revert^2 "libandroidfw hardening for IncFs"
55ef6167a2c235bd88c7216238b2001b46795b79

Change-Id: I02d4890d181655dfd0a14c188468db512559d27b
2020-11-17 23:01:35 +00:00
Ryan Mitchell
55ef6167a2 Revert "libandroidfw hardening for IncFs"
Revert "Move map_ptr to incfs namspace"

Revert submission 12787270

Reason for revert: b/173250495
Reverted Changes:
I5cd1bc8a2:libandroidfw hardening for IncFs
Ice5dbcfb2:Move map_ptr to incfs namspace
I29ccdc8ed:Do not cache bag parent stack until requested
I1e9e9acaa:Cache resolved theme values

Change-Id: Ib90ef68339710086df41e9abe0833a542d03a74f
2020-11-13 23:55:20 +00:00
Ryan Mitchell
c75c2e0922 libandroidfw hardening for IncFs
Migrate libandroifw to using incfs::util::map_ptr to prevent processes
from crashing when parsing the resources.arsc, parsing compiled xml,
files, and retrieving resource values.

This change propagates incremental failures to the JNI level where they
are raised as ResourcesNotFoundException.

Performance of ResourcesPerfWorkloads without change (time in
nanoseconds):
[1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.883s)
    youtube_ns_median: 93812805
    youtube_ns_standardDeviation: 4387062
    youtube_ns_mean: 94455597
[2/3] com.android.resources.perf.PerfTest#maps: PASSED (11.265s)
    maps_ns_standardDeviation: 2997543
    maps_ns_mean: 83480371
    maps_ns_median: 82210941
[3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.963s)
    gmail_ns_median: 266141091
    gmail_ns_standardDeviation: 3492043
    gmail_ns_mean: 267472765

With change and verification forcibly enabled for all apks
(including the framework-res.apk):
[1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.646s)
    youtube_ns_median: 101999396
    youtube_ns_standardDeviation: 4625782
    youtube_ns_mean: 102631770
[2/3] com.android.resources.perf.PerfTest#maps: PASSED (11.286s)
    maps_ns_standardDeviation: 2692088
    maps_ns_mean: 91326538
    maps_ns_median: 90519884
[3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.694s)
    gmail_ns_median: 290284442
    gmail_ns_standardDeviation: 5764632
    gmail_ns_mean: 291660464

With change and verification disabled:
[1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.748s)
    youtube_ns_median: 95490747
    youtube_ns_standardDeviation: 7282249
    youtube_ns_mean: 98442515
[2/3] com.android.resources.perf.PerfTest#maps: PASSED (10.862s)
    maps_ns_standardDeviation: 4484213
    maps_ns_mean: 87912988
    maps_ns_median: 86325549
[3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.034s)
    gmail_ns_median: 282175838
    gmail_ns_standardDeviation: 6560876
    gmail_ns_mean: 282869146

These tests were done on a Pixel 3 and with cpu settings configured by
libs/hwui/tests/scripts/prep_generic.sh:

 Locked CPUs 4,5,6,7 to 1459200 / 2803200 KHz
 Disabled CPUs 0,1,2,3

Bug: 160635104
Bug: 169423204
Test: boot device && atest ResourcesPerfWorkloads

Change-Id: I5cd1bc8a2257bffaba6ca4a1c96f4e6640106866
2020-11-12 08:13:44 -08:00
Ryan Mitchell
19e1a5b4c8 Ignore resources from unknown types
When loading binary APKs into aapt2 for dumping purposes, aapt2 allows
the presence of custom resource types in the resources.arsc. Since
apapt2 may not be able to correctly interpret the data of custom types,
ignore resources from custom types completely when constructing the
ResourceTable data structure for the APK.

Bug: 168247188
Bug: 36051266
Test: run aapt2 dump bading/resources on APKs from both bugs
Change-Id: Ia3c0b4e07457eb8634b5a256ef77270e99b8bd72
2020-09-14 12:10:33 -07:00
Zoran Jovanovic
9336d9e13b OMS: Add config_signature policy handling
Alongside SIGNATURE and ACTOR_SIGNATURE policies, add CONFIG_SIGNATURE
policy to overlayable that overlay fulfills if it is signed with the
same certificate as the reference package whose package name is
declared in 'config-signature' tag of SystemConfig and is vetted by
OMS that it's a system pre-installed package.

BUG: 158726924
TEST: regular aapt2, idmap2, OMS tests

Change-Id: I645ee72271496008742886274be0d63a2985201b
2020-07-28 18:30:53 +00:00
Clark DuVall
8f51d6b876 Reorder styleable attributes in shared libraries
This is a similar fix to
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/10109386
but deals with styleable attributes instead of style items.

Bug: 147674078
Test: JavaClassGeneratorTest.SortsDynamicAttributesAfterFrameworkAttributes
Change-Id: Ida6572cf07e2b5987e9d8941cf169a37c43578c4
2020-04-22 13:19:28 -07:00
Donald Chai
ab7e0d5a51 Include the name of the resource in an error message.
Bug: 153393440
Tested: N/A
Change-Id: I6979c683978af2670b1823ff8380175673067630
2020-04-15 22:03:56 -07:00
Mohamed Heikal
e0388de6be Enable --collapse-resource-names on bundles
This cl enables aapt2 optimize and convert to handle collapsed resource
names optimization.

Test: make aapt2_test

Change-Id: I160d7e5bbd94580b52c00b648918e47beb4674f1
2020-03-31 14:58:01 -04: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
Clark DuVall
18b15bb3a6 Reorder style items in shared libraries
AssetManager2.cpp expects style attribute IDs to be in sorted order when
applying a style (see AssetManager2::GetBag). Shared libraries have a
package ID of 0x00, which will mean any attribute defined in a shared
library will be put before all other attributes. Once the attribute ID
is looked up in the dynamic ref table, the package ID is no longer 0x00,
which means this ID is no longer in sorted order. This messes up the
logic in AssetManager2::GetBag, and results in some style attributes
getting dropped from shared libraries.

This change modifies how aapt2 sorts the style entries, sorting entries
with dynamic IDs after entries with the android framework ID. This means
the entries will still be in sorted order when the IDs are looked up.

Bug: 147674078
Test: TableFlattenerTest.FlattenSharedLibraryWithStyle
Change-Id: Ic4f4004b6d9cecde9325dcdb37f71138857f8236
2020-01-16 12:37:36 -08:00
Clark DuVall
e9fedbe223 Fix serializing dynamic references to proto
The is_dynamic bit on references was getting lost when converting to
proto and back. This was preventing bundles from being used as shared
libraries, since layout inflation would fail when it hit a dynamic
reference.

Bug: 146491000
Test: Build a shared library with a layout that has a dynamic reference,
      and attempt to inflate that layout.

Change-Id: Ia0e615670d2ac52f9266e3eec8813af7687d3323
2020-01-13 09:55:53 -08:00
Donald Chai
b99e50922b Fix computation of 'entry_length' in AAPT2 container format
When the protobuf header (or data payload) size are a multiple of 4,
"entry_length" (called "aligned size" in the code) would have counted bytes that
are never actually written.

Bug: 139418052
Change-Id: Ia688a82a67f3807f7feb0be03670bf2827b1d6a1
2019-10-21 15:14:05 -07:00
Ryan Mitchell
8a891d86ab Allow for RRO internal referencing
This change allows RROs to reference their own internal resources as
expected.

Overlays are loaded as shared libraries so they can have their own
resource id space that does not conflict with the resource id space of
the target or other overlays.

References to overlay resources that override target resources now
appear as references to the target resources.

Overlay values that are inlined into the xml file specified using
android:overlayResources are now able to be used at runtime.

See go/rro-references for more information.

Bug: 135943783
Test: idmap2_tests
Test: libandroidfw_tests
Change-Id: Ie349c56d7fd3f7d94b7d595ed6d01dc6b59b6178
2019-10-17 13:09:33 -07:00
Brian Chang
dcef831e61 Improve how we exempt resources from getting their names collapsed.
Removed the --whitelist-path flag, which is poorly named and we can
already specify these resources with --resources-config-path.

Renamed TableFlattenerOptions.whitelisted_resources to keep_resources.
It holds ResourceName instead of std::string. This lets us include type
when specifying what gets exempted, for correctness.

Bug: 111115201
Test: make aapt2_tests
Change-Id: Ifa5df924b5e2265c32cdcf8ca7dfa4a3992a0468
2019-09-16 17:29:46 -07:00
Ryan Mitchell
ef9e688393 Add --exclude-sources to AAPT2 link
Information about where resources are defined can make having
reproducible builds more difficult, makes the generates resources.pb
large, and can exposes details about the machines that compiled the
resources.

The --exclude-sources flags can only be used when building a proto APK
and prevents source information from being included in the generated
resources protobuf.

Bug: 134929532
Test: checked debug string with and without the string
Change-Id: Ia345f067fe781ea82a4bcad37eb55576c72c44d7
2019-08-14 19:28:32 +00: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
Winson
5e7370d1d0 AAPT2: Fix --output-to-dir
Without a FinishEntry call, the file_ wasn't being released, which
prevents another StartEntry from succeeding.

Bug: 68033366

Test: manual aapt2 link --output-to-dir -o outputDir
Test: Archive_test.cpp

Change-Id: I3b66266327163307a2e4c7f891f6ee76baf7fc10
2019-05-02 10:30:04 -07:00
Ryan Mitchell
743266643a Merge "Add build number to aapt2 version" into qt-dev 2019-04-18 19:04:40 +00: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
Ryan Mitchell
34039b26f5 Add build number to aapt2 version
This changes adds the build id to the version printed by "aapt2
version". This change also adds a field to the ResourceTable proto that
specifies the fingerprints of tools used to build the table.

Bug: 123663089
Test: manual
Change-Id: Ifaf33c1e506b68e9f1d921fdbeddf36485e65790
2019-04-17 10:59:38 -07:00
TreeHugger Robot
b496d6150c Merge "Add --trace_folder to aapt2" 2019-03-07 16:40:03 +00: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
Fabien Sanglard
2d34e76dac Add --trace_folder to aapt2
Add a tracing API and instrument key functions in order to profile
aapt2 bottleneck. The API allows to generate systrace fragment files.

Impact on performance is neglibible with each Trace requiring less
than 1us and the final Flush operation at the end of a command
requiring around 40us.

Bug: None
Test: None
Change-Id: I51b564d3694e9384679f43b878b32295527dddf6
2019-03-05 15:09:27 -08:00
TreeHugger Robot
03f311cb75 Merge "Revert "Fix loaded apk string pool order"" 2019-02-16 00:46:04 +00:00
TreeHugger Robot
ed6c556145 Merge "Do not derive source from binary APK" 2019-02-15 22:57:17 +00:00
Ryan Mitchell
90b7a08aaf Revert "Fix loaded apk string pool order"
This reverts commit 4e9a922ede24f7f7bfe793321f7328623ee2a061.

Reason for revert: <b/122518436>

Change-Id: I3650b2c6c9bdfa69a3034f9ca49e95a9698c3cdd
2019-02-15 14:37:45 -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
b5b162bfe6 Do not derive source from binary APK
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-02-07 20:28:26 -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
cf9dd94323 Merge "Add encoding of name and actor overlayable fields" 2019-01-15 19:34:30 +00:00
Mohamed Heikal
149b0d29c6 Merge "Resource Path Obfuscation" 2019-01-15 15:34:06 +00:00
Ryan Mitchell
ef5673a4c4 Add encoding of name and actor overlayable fields
Encode the actor and name attributes of <overlayable> elements in the
overlayable chunks. Two chunks cannot have the same name.

Bug: 110869880
Bug: 119390855
Test: aapt2_tests and libandroidfw_tests
Change-Id: I0ed95efef640b3927046b6155d1840f0d96030dd
2019-01-11 14:45:09 -08:00
Mohamed Heikal
c769403631 Resource Path Obfuscation
This CL allows aapt2 to obfuscate resource paths within the output apk
and move resources to shorter obfuscated paths. This reduces apk size
when there is a large number of resources since the path metadata exists
in 4 places in the apk.

This CL adds two arguments to aapt2, one to enable resource path
obfuscation and one to point to a path to output the path map to (for
later debugging).

Test: make aapt2_tests
Bug: b/75965637

Change-Id: I9cacafe1d17800d673566b2d61b0b88f3fb8d60c
2018-12-20 18:19:25 -05: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
75e20dda2b Encoding of <overlayable> and <policy>
This change defines two new chunks for encoding overlayable information.
RES_TABLE_OVERLAYABLE_POLICY_TYPE contains flags that represent
restrictions enforced on overlays that try to overlay a specific set of
resource ids. The chunk header is followed by ResTable_ref for each id
that belongs to the policy type. A policy chunk will be created for
every unique combination of policies that are defined in overlayable
declarations.

RES_TABLE_OVERLAYABLE_TYPE holds policy blocks. Since <overlayable>
does not currently have any attributes, only one overlayable block is
encoded in an APK.

This change also removes the SPEC_OVERLAYABLE flag because the runtime
does not use the flag, and the overlayable chunk encoding renders it
obsolete.

Bug: 110869880
Bug: 117545186
Test: libandroidfw_tests and aapt2_tests
Change-Id: I45ae9bf4176699f14c85e2b7a2e8560185d8a0b8
2018-12-04 16:45:26 -08:00
Ryan Mitchell
19954a261c Merge "Do not serialize empty text in manifest proto" 2018-11-19 22:13:35 +00:00
Ryan Mitchell
467b689a4c Do not serialize empty text in manifest proto
When linking an APK in the proto format, the manifest is currently
serializes text nodes that only contain whitespace:

child: {
  text: "\n        "
  source: {
    line_number  : 0x0000000f
    column_number: 0x0000002f
  }
}

These whitespace bloat the proto size unnecessarily. Do not write these
text nodes for proto apks.

Bug: 118800653
Test: make aapt2_tests
Change-Id: Icfaaf88976f81450bbf51610a316b336deeae60c
2018-11-16 15:58:06 -08:00
Ryan Mitchell
4e9a922ede Fix loaded apk string pool order
Loading in an APk changed the ordering of strings in the string pool.
When loading an apk, assign the strings to the same index as they
are in the ResStringPool.

Bug: 118831219
Test: "aapt2 dump strings left.apk" prints in the correct order,
"aapt2 convert left.apk --output-format binary -o left_binary.apk" has
entries in the correct order, and aapt2_tests

Change-Id: I00014c02195f39c1152a110e90083d9b14e9216e
2018-11-15 11:37:01 -08:00